index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _tinycolor = require("@ctrl/tinycolor");
  9. var _internal = require("../../theme/internal");
  10. var _style = require("../../style");
  11. // =============================== Base ===============================
  12. const genBaseStyle = token => {
  13. const {
  14. componentCls,
  15. controlSize,
  16. dotSize,
  17. marginFull,
  18. marginPart,
  19. colorFillContentHover
  20. } = token;
  21. return {
  22. [componentCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  23. position: 'relative',
  24. height: controlSize,
  25. margin: `${marginPart}px ${marginFull}px`,
  26. padding: 0,
  27. cursor: 'pointer',
  28. touchAction: 'none',
  29. [`&-vertical`]: {
  30. margin: `${marginFull}px ${marginPart}px`
  31. },
  32. [`${componentCls}-rail`]: {
  33. position: 'absolute',
  34. backgroundColor: token.colorFillTertiary,
  35. borderRadius: token.borderRadiusXS,
  36. transition: `background-color ${token.motionDurationMid}`
  37. },
  38. [`${componentCls}-track`]: {
  39. position: 'absolute',
  40. backgroundColor: token.colorPrimaryBorder,
  41. borderRadius: token.borderRadiusXS,
  42. transition: `background-color ${token.motionDurationMid}`
  43. },
  44. '&:hover': {
  45. [`${componentCls}-rail`]: {
  46. backgroundColor: token.colorFillSecondary
  47. },
  48. [`${componentCls}-track`]: {
  49. backgroundColor: token.colorPrimaryBorderHover
  50. },
  51. [`${componentCls}-dot`]: {
  52. borderColor: colorFillContentHover
  53. },
  54. [`${componentCls}-handle::after`]: {
  55. boxShadow: `0 0 0 ${token.handleLineWidth}px ${token.colorPrimaryBorderHover}`
  56. },
  57. [`${componentCls}-dot-active`]: {
  58. borderColor: token.colorPrimary
  59. }
  60. },
  61. [`${componentCls}-handle`]: {
  62. position: 'absolute',
  63. width: token.handleSize,
  64. height: token.handleSize,
  65. outline: 'none',
  66. [`${componentCls}-dragging`]: {
  67. zIndex: 1
  68. },
  69. // 扩大选区
  70. '&::before': {
  71. content: '""',
  72. position: 'absolute',
  73. insetInlineStart: -token.handleLineWidth,
  74. insetBlockStart: -token.handleLineWidth,
  75. width: token.handleSize + token.handleLineWidth * 2,
  76. height: token.handleSize + token.handleLineWidth * 2,
  77. backgroundColor: 'transparent'
  78. },
  79. '&::after': {
  80. content: '""',
  81. position: 'absolute',
  82. insetBlockStart: 0,
  83. insetInlineStart: 0,
  84. width: token.handleSize,
  85. height: token.handleSize,
  86. backgroundColor: token.colorBgElevated,
  87. boxShadow: `0 0 0 ${token.handleLineWidth}px ${token.colorPrimaryBorder}`,
  88. borderRadius: '50%',
  89. cursor: 'pointer',
  90. transition: `
  91. inset-inline-start ${token.motionDurationMid},
  92. inset-block-start ${token.motionDurationMid},
  93. width ${token.motionDurationMid},
  94. height ${token.motionDurationMid},
  95. box-shadow ${token.motionDurationMid}
  96. `
  97. },
  98. '&:hover, &:active, &:focus': {
  99. '&::before': {
  100. insetInlineStart: -((token.handleSizeHover - token.handleSize) / 2 + token.handleLineWidthHover),
  101. insetBlockStart: -((token.handleSizeHover - token.handleSize) / 2 + token.handleLineWidthHover),
  102. width: token.handleSizeHover + token.handleLineWidthHover * 2,
  103. height: token.handleSizeHover + token.handleLineWidthHover * 2
  104. },
  105. '&::after': {
  106. boxShadow: `0 0 0 ${token.handleLineWidthHover}px ${token.colorPrimary}`,
  107. width: token.handleSizeHover,
  108. height: token.handleSizeHover,
  109. insetInlineStart: (token.handleSize - token.handleSizeHover) / 2,
  110. insetBlockStart: (token.handleSize - token.handleSizeHover) / 2
  111. }
  112. }
  113. },
  114. [`${componentCls}-mark`]: {
  115. position: 'absolute',
  116. fontSize: token.fontSize
  117. },
  118. [`${componentCls}-mark-text`]: {
  119. position: 'absolute',
  120. display: 'inline-block',
  121. color: token.colorTextDescription,
  122. textAlign: 'center',
  123. wordBreak: 'keep-all',
  124. cursor: 'pointer',
  125. userSelect: 'none',
  126. '&-active': {
  127. color: token.colorText
  128. }
  129. },
  130. [`${componentCls}-step`]: {
  131. position: 'absolute',
  132. background: 'transparent',
  133. pointerEvents: 'none'
  134. },
  135. [`${componentCls}-dot`]: {
  136. position: 'absolute',
  137. width: dotSize,
  138. height: dotSize,
  139. backgroundColor: token.colorBgElevated,
  140. border: `${token.handleLineWidth}px solid ${token.colorBorderSecondary}`,
  141. borderRadius: '50%',
  142. cursor: 'pointer',
  143. transition: `border-color ${token.motionDurationSlow}`,
  144. '&-active': {
  145. borderColor: token.colorPrimaryBorder
  146. }
  147. },
  148. [`&${componentCls}-disabled`]: {
  149. cursor: 'not-allowed',
  150. [`${componentCls}-rail`]: {
  151. backgroundColor: `${token.colorFillSecondary} !important`
  152. },
  153. [`${componentCls}-track`]: {
  154. backgroundColor: `${token.colorTextDisabled} !important`
  155. },
  156. [`
  157. ${componentCls}-dot
  158. `]: {
  159. backgroundColor: token.colorBgElevated,
  160. borderColor: token.colorTextDisabled,
  161. boxShadow: 'none',
  162. cursor: 'not-allowed'
  163. },
  164. [`${componentCls}-handle::after`]: {
  165. backgroundColor: token.colorBgElevated,
  166. cursor: 'not-allowed',
  167. width: token.handleSize,
  168. height: token.handleSize,
  169. boxShadow: `0 0 0 ${token.handleLineWidth}px ${new _tinycolor.TinyColor(token.colorTextDisabled).onBackground(token.colorBgContainer).toHexString()}`,
  170. insetInlineStart: 0,
  171. insetBlockStart: 0
  172. },
  173. [`
  174. ${componentCls}-mark-text,
  175. ${componentCls}-dot
  176. `]: {
  177. cursor: `not-allowed !important`
  178. }
  179. }
  180. })
  181. };
  182. };
  183. // ============================ Horizontal ============================
  184. const genDirectionStyle = (token, horizontal) => {
  185. const {
  186. componentCls,
  187. railSize,
  188. handleSize,
  189. dotSize
  190. } = token;
  191. const railPadding = horizontal ? 'paddingBlock' : 'paddingInline';
  192. const full = horizontal ? 'width' : 'height';
  193. const part = horizontal ? 'height' : 'width';
  194. const handlePos = horizontal ? 'insetBlockStart' : 'insetInlineStart';
  195. const markInset = horizontal ? 'top' : 'insetInlineStart';
  196. return {
  197. [railPadding]: railSize,
  198. [part]: railSize * 3,
  199. [`${componentCls}-rail`]: {
  200. [full]: '100%',
  201. [part]: railSize
  202. },
  203. [`${componentCls}-track`]: {
  204. [part]: railSize
  205. },
  206. [`${componentCls}-handle`]: {
  207. [handlePos]: (railSize * 3 - handleSize) / 2
  208. },
  209. [`${componentCls}-mark`]: {
  210. // Reset all
  211. insetInlineStart: 0,
  212. top: 0,
  213. [markInset]: handleSize,
  214. [full]: '100%'
  215. },
  216. [`${componentCls}-step`]: {
  217. // Reset all
  218. insetInlineStart: 0,
  219. top: 0,
  220. [markInset]: railSize,
  221. [full]: '100%',
  222. [part]: railSize
  223. },
  224. [`${componentCls}-dot`]: {
  225. position: 'absolute',
  226. [handlePos]: (railSize - dotSize) / 2
  227. }
  228. };
  229. };
  230. // ============================ Horizontal ============================
  231. const genHorizontalStyle = token => {
  232. const {
  233. componentCls,
  234. marginPartWithMark
  235. } = token;
  236. return {
  237. [`${componentCls}-horizontal`]: (0, _extends2.default)((0, _extends2.default)({}, genDirectionStyle(token, true)), {
  238. [`&${componentCls}-with-marks`]: {
  239. marginBottom: marginPartWithMark
  240. }
  241. })
  242. };
  243. };
  244. // ============================= Vertical =============================
  245. const genVerticalStyle = token => {
  246. const {
  247. componentCls
  248. } = token;
  249. return {
  250. [`${componentCls}-vertical`]: (0, _extends2.default)((0, _extends2.default)({}, genDirectionStyle(token, false)), {
  251. height: '100%'
  252. })
  253. };
  254. };
  255. // ============================== Export ==============================
  256. var _default = exports.default = (0, _internal.genComponentStyleHook)('Slider', token => {
  257. const sliderToken = (0, _internal.mergeToken)(token, {
  258. marginPart: (token.controlHeight - token.controlSize) / 2,
  259. marginFull: token.controlSize / 2,
  260. marginPartWithMark: token.controlHeightLG - token.controlSize
  261. });
  262. return [genBaseStyle(sliderToken), genHorizontalStyle(sliderToken), genVerticalStyle(sliderToken)];
  263. }, token => {
  264. // Handle line width is always width-er 1px
  265. const increaseHandleWidth = 1;
  266. const controlSize = token.controlHeightLG / 4;
  267. const controlSizeHover = token.controlHeightSM / 2;
  268. const handleLineWidth = token.lineWidth + increaseHandleWidth;
  269. const handleLineWidthHover = token.lineWidth + increaseHandleWidth * 3;
  270. return {
  271. controlSize,
  272. railSize: 4,
  273. handleSize: controlSize,
  274. handleSizeHover: controlSizeHover,
  275. dotSize: 8,
  276. handleLineWidth,
  277. handleLineWidthHover
  278. };
  279. });