index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _fastColor = require("@ant-design/fast-color");
  8. var _style = require("../../style");
  9. var _internal = require("../../theme/internal");
  10. // =============================== Base ===============================
  11. const genBaseStyle = token => {
  12. const {
  13. componentCls,
  14. antCls,
  15. controlSize,
  16. dotSize,
  17. marginFull,
  18. marginPart,
  19. colorFillContentHover,
  20. handleColorDisabled,
  21. calc,
  22. handleSize,
  23. handleSizeHover,
  24. handleActiveColor,
  25. handleActiveOutlineColor,
  26. handleLineWidth,
  27. handleLineWidthHover,
  28. motionDurationMid
  29. } = token;
  30. return {
  31. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  32. position: 'relative',
  33. height: controlSize,
  34. margin: `${(0, _cssinjs.unit)(marginPart)} ${(0, _cssinjs.unit)(marginFull)}`,
  35. padding: 0,
  36. cursor: 'pointer',
  37. touchAction: 'none',
  38. '&-vertical': {
  39. margin: `${(0, _cssinjs.unit)(marginFull)} ${(0, _cssinjs.unit)(marginPart)}`
  40. },
  41. [`${componentCls}-rail`]: {
  42. position: 'absolute',
  43. backgroundColor: token.railBg,
  44. borderRadius: token.borderRadiusXS,
  45. transition: `background-color ${motionDurationMid}`
  46. },
  47. [`${componentCls}-track,${componentCls}-tracks`]: {
  48. position: 'absolute',
  49. transition: `background-color ${motionDurationMid}`
  50. },
  51. [`${componentCls}-track`]: {
  52. backgroundColor: token.trackBg,
  53. borderRadius: token.borderRadiusXS
  54. },
  55. [`${componentCls}-track-draggable`]: {
  56. boxSizing: 'content-box',
  57. backgroundClip: 'content-box',
  58. border: 'solid rgba(0,0,0,0)'
  59. },
  60. '&:hover': {
  61. [`${componentCls}-rail`]: {
  62. backgroundColor: token.railHoverBg
  63. },
  64. [`${componentCls}-track`]: {
  65. backgroundColor: token.trackHoverBg
  66. },
  67. [`${componentCls}-dot`]: {
  68. borderColor: colorFillContentHover
  69. },
  70. [`${componentCls}-handle::after`]: {
  71. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(handleLineWidth)} ${token.colorPrimaryBorderHover}`
  72. },
  73. [`${componentCls}-dot-active`]: {
  74. borderColor: token.dotActiveBorderColor
  75. }
  76. },
  77. [`${componentCls}-handle`]: {
  78. position: 'absolute',
  79. width: handleSize,
  80. height: handleSize,
  81. outline: 'none',
  82. userSelect: 'none',
  83. // Dragging status
  84. '&-dragging-delete': {
  85. opacity: 0
  86. },
  87. // 扩大选区
  88. '&::before': {
  89. content: '""',
  90. position: 'absolute',
  91. insetInlineStart: calc(handleLineWidth).mul(-1).equal(),
  92. insetBlockStart: calc(handleLineWidth).mul(-1).equal(),
  93. width: calc(handleSize).add(calc(handleLineWidth).mul(2)).equal(),
  94. height: calc(handleSize).add(calc(handleLineWidth).mul(2)).equal(),
  95. backgroundColor: 'transparent'
  96. },
  97. '&::after': {
  98. content: '""',
  99. position: 'absolute',
  100. insetBlockStart: 0,
  101. insetInlineStart: 0,
  102. width: handleSize,
  103. height: handleSize,
  104. backgroundColor: token.colorBgElevated,
  105. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(handleLineWidth)} ${token.handleColor}`,
  106. outline: `0px solid transparent`,
  107. borderRadius: '50%',
  108. cursor: 'pointer',
  109. transition: `
  110. inset-inline-start ${motionDurationMid},
  111. inset-block-start ${motionDurationMid},
  112. width ${motionDurationMid},
  113. height ${motionDurationMid},
  114. box-shadow ${motionDurationMid},
  115. outline ${motionDurationMid}
  116. `
  117. },
  118. '&:hover, &:active, &:focus': {
  119. '&::before': {
  120. insetInlineStart: calc(handleSizeHover).sub(handleSize).div(2).add(handleLineWidthHover).mul(-1).equal(),
  121. insetBlockStart: calc(handleSizeHover).sub(handleSize).div(2).add(handleLineWidthHover).mul(-1).equal(),
  122. width: calc(handleSizeHover).add(calc(handleLineWidthHover).mul(2)).equal(),
  123. height: calc(handleSizeHover).add(calc(handleLineWidthHover).mul(2)).equal()
  124. },
  125. '&::after': {
  126. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(handleLineWidthHover)} ${handleActiveColor}`,
  127. outline: `6px solid ${handleActiveOutlineColor}`,
  128. width: handleSizeHover,
  129. height: handleSizeHover,
  130. insetInlineStart: token.calc(handleSize).sub(handleSizeHover).div(2).equal(),
  131. insetBlockStart: token.calc(handleSize).sub(handleSizeHover).div(2).equal()
  132. }
  133. }
  134. },
  135. [`&-lock ${componentCls}-handle`]: {
  136. '&::before, &::after': {
  137. transition: 'none'
  138. }
  139. },
  140. [`${componentCls}-mark`]: {
  141. position: 'absolute',
  142. fontSize: token.fontSize
  143. },
  144. [`${componentCls}-mark-text`]: {
  145. position: 'absolute',
  146. display: 'inline-block',
  147. color: token.colorTextDescription,
  148. textAlign: 'center',
  149. wordBreak: 'keep-all',
  150. cursor: 'pointer',
  151. userSelect: 'none',
  152. '&-active': {
  153. color: token.colorText
  154. }
  155. },
  156. [`${componentCls}-step`]: {
  157. position: 'absolute',
  158. background: 'transparent',
  159. pointerEvents: 'none'
  160. },
  161. [`${componentCls}-dot`]: {
  162. position: 'absolute',
  163. width: dotSize,
  164. height: dotSize,
  165. backgroundColor: token.colorBgElevated,
  166. border: `${(0, _cssinjs.unit)(handleLineWidth)} solid ${token.dotBorderColor}`,
  167. borderRadius: '50%',
  168. cursor: 'pointer',
  169. transition: `border-color ${token.motionDurationSlow}`,
  170. pointerEvents: 'auto',
  171. '&-active': {
  172. borderColor: token.dotActiveBorderColor
  173. }
  174. },
  175. [`&${componentCls}-disabled`]: {
  176. cursor: 'not-allowed',
  177. [`${componentCls}-rail`]: {
  178. backgroundColor: `${token.railBg} !important`
  179. },
  180. [`${componentCls}-track`]: {
  181. backgroundColor: `${token.trackBgDisabled} !important`
  182. },
  183. [`
  184. ${componentCls}-dot
  185. `]: {
  186. backgroundColor: token.colorBgElevated,
  187. borderColor: token.trackBgDisabled,
  188. boxShadow: 'none',
  189. cursor: 'not-allowed'
  190. },
  191. [`${componentCls}-handle::after`]: {
  192. backgroundColor: token.colorBgElevated,
  193. cursor: 'not-allowed',
  194. width: handleSize,
  195. height: handleSize,
  196. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(handleLineWidth)} ${handleColorDisabled}`,
  197. insetInlineStart: 0,
  198. insetBlockStart: 0
  199. },
  200. [`
  201. ${componentCls}-mark-text,
  202. ${componentCls}-dot
  203. `]: {
  204. cursor: `not-allowed !important`
  205. }
  206. },
  207. [`&-tooltip ${antCls}-tooltip-inner`]: {
  208. minWidth: 'unset'
  209. }
  210. })
  211. };
  212. };
  213. // ============================ Horizontal ============================
  214. const genDirectionStyle = (token, horizontal) => {
  215. const {
  216. componentCls,
  217. railSize,
  218. handleSize,
  219. dotSize,
  220. marginFull,
  221. calc
  222. } = token;
  223. const railPadding = horizontal ? 'paddingBlock' : 'paddingInline';
  224. const full = horizontal ? 'width' : 'height';
  225. const part = horizontal ? 'height' : 'width';
  226. const handlePos = horizontal ? 'insetBlockStart' : 'insetInlineStart';
  227. const markInset = horizontal ? 'top' : 'insetInlineStart';
  228. const handlePosSize = calc(railSize).mul(3).sub(handleSize).div(2).equal();
  229. const draggableBorderSize = calc(handleSize).sub(railSize).div(2).equal();
  230. const draggableBorder = horizontal ? {
  231. borderWidth: `${(0, _cssinjs.unit)(draggableBorderSize)} 0`,
  232. transform: `translateY(${(0, _cssinjs.unit)(calc(draggableBorderSize).mul(-1).equal())})`
  233. } : {
  234. borderWidth: `0 ${(0, _cssinjs.unit)(draggableBorderSize)}`,
  235. transform: `translateX(${(0, _cssinjs.unit)(token.calc(draggableBorderSize).mul(-1).equal())})`
  236. };
  237. return {
  238. [railPadding]: railSize,
  239. [part]: calc(railSize).mul(3).equal(),
  240. [`${componentCls}-rail`]: {
  241. [full]: '100%',
  242. [part]: railSize
  243. },
  244. [`${componentCls}-track,${componentCls}-tracks`]: {
  245. [part]: railSize
  246. },
  247. [`${componentCls}-track-draggable`]: Object.assign({}, draggableBorder),
  248. [`${componentCls}-handle`]: {
  249. [handlePos]: handlePosSize
  250. },
  251. [`${componentCls}-mark`]: {
  252. // Reset all
  253. insetInlineStart: 0,
  254. top: 0,
  255. // https://github.com/ant-design/ant-design/issues/43731
  256. [markInset]: calc(railSize).mul(3).add(horizontal ? 0 : marginFull).equal(),
  257. [full]: '100%'
  258. },
  259. [`${componentCls}-step`]: {
  260. // Reset all
  261. insetInlineStart: 0,
  262. top: 0,
  263. [markInset]: railSize,
  264. [full]: '100%',
  265. [part]: railSize
  266. },
  267. [`${componentCls}-dot`]: {
  268. position: 'absolute',
  269. [handlePos]: calc(railSize).sub(dotSize).div(2).equal()
  270. }
  271. };
  272. };
  273. // ============================ Horizontal ============================
  274. const genHorizontalStyle = token => {
  275. const {
  276. componentCls,
  277. marginPartWithMark
  278. } = token;
  279. return {
  280. [`${componentCls}-horizontal`]: Object.assign(Object.assign({}, genDirectionStyle(token, true)), {
  281. [`&${componentCls}-with-marks`]: {
  282. marginBottom: marginPartWithMark
  283. }
  284. })
  285. };
  286. };
  287. // ============================= Vertical =============================
  288. const genVerticalStyle = token => {
  289. const {
  290. componentCls
  291. } = token;
  292. return {
  293. [`${componentCls}-vertical`]: Object.assign(Object.assign({}, genDirectionStyle(token, false)), {
  294. height: '100%'
  295. })
  296. };
  297. };
  298. // ============================== Export ==============================
  299. const prepareComponentToken = token => {
  300. // Handle line width is always width-er 1px
  301. const increaseHandleWidth = 1;
  302. const controlSize = token.controlHeightLG / 4;
  303. const controlSizeHover = token.controlHeightSM / 2;
  304. const handleLineWidth = token.lineWidth + increaseHandleWidth;
  305. const handleLineWidthHover = token.lineWidth + increaseHandleWidth * 1.5;
  306. const handleActiveColor = token.colorPrimary;
  307. const handleActiveOutlineColor = new _fastColor.FastColor(handleActiveColor).setA(0.2).toRgbString();
  308. return {
  309. controlSize,
  310. railSize: 4,
  311. handleSize: controlSize,
  312. handleSizeHover: controlSizeHover,
  313. dotSize: 8,
  314. handleLineWidth,
  315. handleLineWidthHover,
  316. railBg: token.colorFillTertiary,
  317. railHoverBg: token.colorFillSecondary,
  318. trackBg: token.colorPrimaryBorder,
  319. trackHoverBg: token.colorPrimaryBorderHover,
  320. handleColor: token.colorPrimaryBorder,
  321. handleActiveColor,
  322. handleActiveOutlineColor,
  323. handleColorDisabled: new _fastColor.FastColor(token.colorTextDisabled).onBackground(token.colorBgContainer).toHexString(),
  324. dotBorderColor: token.colorBorderSecondary,
  325. dotActiveBorderColor: token.colorPrimaryBorder,
  326. trackBgDisabled: token.colorBgContainerDisabled
  327. };
  328. };
  329. exports.prepareComponentToken = prepareComponentToken;
  330. var _default = exports.default = (0, _internal.genStyleHooks)('Slider', token => {
  331. const sliderToken = (0, _internal.mergeToken)(token, {
  332. marginPart: token.calc(token.controlHeight).sub(token.controlSize).div(2).equal(),
  333. marginFull: token.calc(token.controlSize).div(2).equal(),
  334. marginPartWithMark: token.calc(token.controlHeightLG).sub(token.controlSize).equal()
  335. });
  336. return [genBaseStyle(sliderToken), genHorizontalStyle(sliderToken), genVerticalStyle(sliderToken)];
  337. }, prepareComponentToken);