index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genPlaceholderStyle, initInputToken } from '../../input/style';
  3. import { resetComponent, textEllipsis } from '../../style';
  4. import { genCompactItemStyle } from '../../style/compact-item';
  5. import { initMoveMotion, initSlideMotion, slideDownIn, slideDownOut, slideUpIn, slideUpOut } from '../../style/motion';
  6. import { genRoundedArrow } from '../../style/roundedArrow';
  7. import { genStyleHooks, mergeToken } from '../../theme/internal';
  8. import genPickerMultipleStyle from './multiple';
  9. import genPickerPanelStyle, { genPanelStyle } from './panel';
  10. import { initPanelComponentToken, initPickerPanelToken, prepareComponentToken } from './token';
  11. import genVariantsStyle from './variants';
  12. export { initPickerPanelToken, initPanelComponentToken, genPanelStyle };
  13. const genPickerPadding = (paddingBlock, paddingInline) => {
  14. return {
  15. padding: `${unit(paddingBlock)} ${unit(paddingInline)}`
  16. };
  17. };
  18. const genPickerStatusStyle = token => {
  19. const {
  20. componentCls,
  21. colorError,
  22. colorWarning
  23. } = token;
  24. return {
  25. [`${componentCls}:not(${componentCls}-disabled):not([disabled])`]: {
  26. [`&${componentCls}-status-error`]: {
  27. [`${componentCls}-active-bar`]: {
  28. background: colorError
  29. }
  30. },
  31. [`&${componentCls}-status-warning`]: {
  32. [`${componentCls}-active-bar`]: {
  33. background: colorWarning
  34. }
  35. }
  36. }
  37. };
  38. };
  39. const genPickerStyle = token => {
  40. var _a;
  41. const {
  42. componentCls,
  43. antCls,
  44. paddingInline,
  45. lineWidth,
  46. lineType,
  47. colorBorder,
  48. borderRadius,
  49. motionDurationMid,
  50. colorTextDisabled,
  51. colorTextPlaceholder,
  52. fontSizeLG,
  53. inputFontSizeLG,
  54. fontSizeSM,
  55. inputFontSizeSM,
  56. controlHeightSM,
  57. paddingInlineSM,
  58. paddingXS,
  59. marginXS,
  60. colorIcon,
  61. lineWidthBold,
  62. colorPrimary,
  63. motionDurationSlow,
  64. zIndexPopup,
  65. paddingXXS,
  66. sizePopupArrow,
  67. colorBgElevated,
  68. borderRadiusLG,
  69. boxShadowSecondary,
  70. borderRadiusSM,
  71. colorSplit,
  72. cellHoverBg,
  73. presetsWidth,
  74. presetsMaxWidth,
  75. boxShadowPopoverArrow,
  76. fontHeight,
  77. lineHeightLG
  78. } = token;
  79. return [{
  80. [componentCls]: Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genPickerPadding(token.paddingBlock, token.paddingInline)), {
  81. position: 'relative',
  82. display: 'inline-flex',
  83. alignItems: 'center',
  84. lineHeight: 1,
  85. borderRadius,
  86. transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}, background ${motionDurationMid}`,
  87. [`${componentCls}-prefix`]: {
  88. flex: '0 0 auto',
  89. marginInlineEnd: token.inputAffixPadding
  90. },
  91. // ======================== Input =========================
  92. [`${componentCls}-input`]: {
  93. position: 'relative',
  94. display: 'inline-flex',
  95. alignItems: 'center',
  96. width: '100%',
  97. '> input': Object.assign(Object.assign({
  98. position: 'relative',
  99. display: 'inline-block',
  100. width: '100%',
  101. color: 'inherit',
  102. fontSize: (_a = token.inputFontSize) !== null && _a !== void 0 ? _a : token.fontSize,
  103. lineHeight: token.lineHeight,
  104. transition: `all ${motionDurationMid}`
  105. }, genPlaceholderStyle(colorTextPlaceholder)), {
  106. flex: 'auto',
  107. // Fix Firefox flex not correct:
  108. // https://github.com/ant-design/ant-design/pull/20023#issuecomment-564389553
  109. minWidth: 1,
  110. height: 'auto',
  111. padding: 0,
  112. background: 'transparent',
  113. border: 0,
  114. fontFamily: 'inherit',
  115. '&:focus': {
  116. boxShadow: 'none',
  117. outline: 0
  118. },
  119. '&[disabled]': {
  120. background: 'transparent',
  121. color: colorTextDisabled,
  122. cursor: 'not-allowed'
  123. }
  124. }),
  125. '&-placeholder': {
  126. '> input': {
  127. color: colorTextPlaceholder
  128. }
  129. }
  130. },
  131. // Size
  132. '&-large': Object.assign(Object.assign({}, genPickerPadding(token.paddingBlockLG, token.paddingInlineLG)), {
  133. [`${componentCls}-input > input`]: {
  134. fontSize: inputFontSizeLG !== null && inputFontSizeLG !== void 0 ? inputFontSizeLG : fontSizeLG,
  135. lineHeight: lineHeightLG
  136. }
  137. }),
  138. '&-small': Object.assign(Object.assign({}, genPickerPadding(token.paddingBlockSM, token.paddingInlineSM)), {
  139. [`${componentCls}-input > input`]: {
  140. fontSize: inputFontSizeSM !== null && inputFontSizeSM !== void 0 ? inputFontSizeSM : fontSizeSM
  141. }
  142. }),
  143. [`${componentCls}-suffix`]: {
  144. display: 'flex',
  145. flex: 'none',
  146. alignSelf: 'center',
  147. marginInlineStart: token.calc(paddingXS).div(2).equal(),
  148. color: colorTextDisabled,
  149. lineHeight: 1,
  150. pointerEvents: 'none',
  151. transition: `opacity ${motionDurationMid}, color ${motionDurationMid}`,
  152. '> *': {
  153. verticalAlign: 'top',
  154. '&:not(:last-child)': {
  155. marginInlineEnd: marginXS
  156. }
  157. }
  158. },
  159. [`${componentCls}-clear`]: {
  160. position: 'absolute',
  161. top: '50%',
  162. insetInlineEnd: 0,
  163. color: colorTextDisabled,
  164. lineHeight: 1,
  165. transform: 'translateY(-50%)',
  166. cursor: 'pointer',
  167. opacity: 0,
  168. transition: `opacity ${motionDurationMid}, color ${motionDurationMid}`,
  169. '> *': {
  170. verticalAlign: 'top'
  171. },
  172. '&:hover': {
  173. color: colorIcon
  174. }
  175. },
  176. '&:hover': {
  177. [`${componentCls}-clear`]: {
  178. opacity: 1
  179. },
  180. // Should use the following selector, but since `:has` has poor compatibility,
  181. // we use `:not(:last-child)` instead, which may cause some problems in some cases.
  182. // [`${componentCls}-suffix:has(+ ${componentCls}-clear)`]: {
  183. [`${componentCls}-suffix:not(:last-child)`]: {
  184. opacity: 0
  185. }
  186. },
  187. [`${componentCls}-separator`]: {
  188. position: 'relative',
  189. display: 'inline-block',
  190. width: '1em',
  191. height: fontSizeLG,
  192. color: colorTextDisabled,
  193. fontSize: fontSizeLG,
  194. verticalAlign: 'top',
  195. cursor: 'default',
  196. [`${componentCls}-focused &`]: {
  197. color: colorIcon
  198. },
  199. [`${componentCls}-range-separator &`]: {
  200. [`${componentCls}-disabled &`]: {
  201. cursor: 'not-allowed'
  202. }
  203. }
  204. },
  205. // ======================== Range =========================
  206. '&-range': {
  207. position: 'relative',
  208. display: 'inline-flex',
  209. // Active bar
  210. [`${componentCls}-active-bar`]: {
  211. bottom: token.calc(lineWidth).mul(-1).equal(),
  212. height: lineWidthBold,
  213. background: colorPrimary,
  214. opacity: 0,
  215. transition: `all ${motionDurationSlow} ease-out`,
  216. pointerEvents: 'none'
  217. },
  218. [`&${componentCls}-focused`]: {
  219. [`${componentCls}-active-bar`]: {
  220. opacity: 1
  221. }
  222. },
  223. [`${componentCls}-range-separator`]: {
  224. alignItems: 'center',
  225. padding: `0 ${unit(paddingXS)}`,
  226. lineHeight: 1
  227. }
  228. },
  229. // ======================== Clear =========================
  230. '&-range, &-multiple': {
  231. // Clear
  232. [`${componentCls}-clear`]: {
  233. insetInlineEnd: paddingInline
  234. },
  235. [`&${componentCls}-small`]: {
  236. [`${componentCls}-clear`]: {
  237. insetInlineEnd: paddingInlineSM
  238. }
  239. }
  240. },
  241. // ======================= Dropdown =======================
  242. '&-dropdown': Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genPanelStyle(token)), {
  243. pointerEvents: 'none',
  244. position: 'absolute',
  245. // Fix incorrect position of picker popup
  246. // https://github.com/ant-design/ant-design/issues/35590
  247. top: -9999,
  248. left: {
  249. _skip_check_: true,
  250. value: -9999
  251. },
  252. zIndex: zIndexPopup,
  253. [`&${componentCls}-dropdown-hidden`]: {
  254. display: 'none'
  255. },
  256. '&-rtl': {
  257. direction: 'rtl'
  258. },
  259. [`&${componentCls}-dropdown-placement-bottomLeft,
  260. &${componentCls}-dropdown-placement-bottomRight`]: {
  261. [`${componentCls}-range-arrow`]: {
  262. top: 0,
  263. display: 'block',
  264. transform: 'translateY(-100%)'
  265. }
  266. },
  267. [`&${componentCls}-dropdown-placement-topLeft,
  268. &${componentCls}-dropdown-placement-topRight`]: {
  269. [`${componentCls}-range-arrow`]: {
  270. bottom: 0,
  271. display: 'block',
  272. transform: 'translateY(100%) rotate(180deg)'
  273. }
  274. },
  275. [`&${antCls}-slide-up-appear, &${antCls}-slide-up-enter`]: {
  276. [`${componentCls}-range-arrow${componentCls}-range-arrow`]: {
  277. transition: 'none'
  278. }
  279. },
  280. [`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-topLeft,
  281. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-topRight,
  282. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-topLeft,
  283. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-topRight`]: {
  284. animationName: slideDownIn
  285. },
  286. [`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-bottomLeft,
  287. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-bottomRight,
  288. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-bottomLeft,
  289. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-bottomRight`]: {
  290. animationName: slideUpIn
  291. },
  292. // https://github.com/ant-design/ant-design/issues/48727
  293. [`&${antCls}-slide-up-leave ${componentCls}-panel-container`]: {
  294. pointerEvents: 'none'
  295. },
  296. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-topLeft,
  297. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-topRight`]: {
  298. animationName: slideDownOut
  299. },
  300. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-bottomLeft,
  301. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-bottomRight`]: {
  302. animationName: slideUpOut
  303. },
  304. // Time picker with additional style
  305. [`${componentCls}-panel > ${componentCls}-time-panel`]: {
  306. paddingTop: paddingXXS
  307. },
  308. // ======================== Ranges ========================
  309. [`${componentCls}-range-wrapper`]: {
  310. display: 'flex',
  311. position: 'relative'
  312. },
  313. [`${componentCls}-range-arrow`]: Object.assign(Object.assign({
  314. position: 'absolute',
  315. zIndex: 1,
  316. display: 'none',
  317. paddingInline: token.calc(paddingInline).mul(1.5).equal(),
  318. boxSizing: 'content-box',
  319. transition: `all ${motionDurationSlow} ease-out`
  320. }, genRoundedArrow(token, colorBgElevated, boxShadowPopoverArrow)), {
  321. '&:before': {
  322. insetInlineStart: token.calc(paddingInline).mul(1.5).equal()
  323. }
  324. }),
  325. [`${componentCls}-panel-container`]: {
  326. overflow: 'hidden',
  327. verticalAlign: 'top',
  328. background: colorBgElevated,
  329. borderRadius: borderRadiusLG,
  330. boxShadow: boxShadowSecondary,
  331. transition: `margin ${motionDurationSlow}`,
  332. display: 'inline-block',
  333. pointerEvents: 'auto',
  334. // ======================== Layout ========================
  335. [`${componentCls}-panel-layout`]: {
  336. display: 'flex',
  337. flexWrap: 'nowrap',
  338. alignItems: 'stretch'
  339. },
  340. // ======================== Preset ========================
  341. [`${componentCls}-presets`]: {
  342. display: 'flex',
  343. flexDirection: 'column',
  344. minWidth: presetsWidth,
  345. maxWidth: presetsMaxWidth,
  346. ul: {
  347. height: 0,
  348. flex: 'auto',
  349. listStyle: 'none',
  350. overflow: 'auto',
  351. margin: 0,
  352. padding: paddingXS,
  353. borderInlineEnd: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
  354. li: Object.assign(Object.assign({}, textEllipsis), {
  355. borderRadius: borderRadiusSM,
  356. paddingInline: paddingXS,
  357. paddingBlock: token.calc(controlHeightSM).sub(fontHeight).div(2).equal(),
  358. cursor: 'pointer',
  359. transition: `all ${motionDurationSlow}`,
  360. '+ li': {
  361. marginTop: marginXS
  362. },
  363. '&:hover': {
  364. background: cellHoverBg
  365. }
  366. })
  367. }
  368. },
  369. // ======================== Panels ========================
  370. [`${componentCls}-panels`]: {
  371. display: 'inline-flex',
  372. flexWrap: 'nowrap',
  373. // [`${componentCls}-panel`]: {
  374. // borderWidth: `0 0 ${unit(lineWidth)}`,
  375. // },
  376. '&:last-child': {
  377. [`${componentCls}-panel`]: {
  378. borderWidth: 0
  379. }
  380. }
  381. },
  382. [`${componentCls}-panel`]: {
  383. verticalAlign: 'top',
  384. background: 'transparent',
  385. borderRadius: 0,
  386. borderWidth: 0,
  387. [`${componentCls}-content, table`]: {
  388. textAlign: 'center'
  389. },
  390. '&-focused': {
  391. borderColor: colorBorder
  392. }
  393. }
  394. }
  395. }),
  396. '&-dropdown-range': {
  397. padding: `${unit(token.calc(sizePopupArrow).mul(2).div(3).equal())} 0`,
  398. '&-hidden': {
  399. display: 'none'
  400. }
  401. },
  402. '&-rtl': {
  403. direction: 'rtl',
  404. [`${componentCls}-separator`]: {
  405. transform: 'scale(-1, 1)'
  406. },
  407. [`${componentCls}-footer`]: {
  408. '&-extra': {
  409. direction: 'rtl'
  410. }
  411. }
  412. }
  413. })
  414. },
  415. // Follow code may reuse in other components
  416. initSlideMotion(token, 'slide-up'), initSlideMotion(token, 'slide-down'), initMoveMotion(token, 'move-up'), initMoveMotion(token, 'move-down')];
  417. };
  418. // ============================== Export ==============================
  419. export default genStyleHooks('DatePicker', token => {
  420. const pickerToken = mergeToken(initInputToken(token), initPickerPanelToken(token), {
  421. inputPaddingHorizontalBase: token.calc(token.paddingSM).sub(1).equal(),
  422. multipleSelectItemHeight: token.multipleItemHeight,
  423. selectHeight: token.controlHeight
  424. });
  425. return [genPickerPanelStyle(pickerToken), genPickerStyle(pickerToken), genVariantsStyle(pickerToken), genPickerStatusStyle(pickerToken), genPickerMultipleStyle(pickerToken),
  426. // =====================================================
  427. // == Space Compact ==
  428. // =====================================================
  429. genCompactItemStyle(token, {
  430. focusElCls: `${token.componentCls}-focused`
  431. })];
  432. }, prepareComponentToken);