index.js 16 KB

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