multiple.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genOverflowStyle, getMultipleSelectorUnit } from '../../select/style/multiple';
  3. import { mergeToken } from '../../theme/internal';
  4. const genSize = (token, suffix) => {
  5. const {
  6. componentCls,
  7. controlHeight
  8. } = token;
  9. const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
  10. const multipleSelectorUnit = getMultipleSelectorUnit(token);
  11. return [
  12. // genSelectionStyle(token, suffix),
  13. {
  14. [`${componentCls}-multiple${suffixCls}`]: {
  15. paddingBlock: multipleSelectorUnit.containerPadding,
  16. paddingInlineStart: multipleSelectorUnit.basePadding,
  17. minHeight: controlHeight,
  18. // ======================== Selections ========================
  19. [`${componentCls}-selection-item`]: {
  20. height: multipleSelectorUnit.itemHeight,
  21. lineHeight: unit(multipleSelectorUnit.itemLineHeight)
  22. }
  23. }
  24. }];
  25. };
  26. const genPickerMultipleStyle = token => {
  27. const {
  28. componentCls,
  29. calc,
  30. lineWidth
  31. } = token;
  32. const smallToken = mergeToken(token, {
  33. fontHeight: token.fontSize,
  34. selectHeight: token.controlHeightSM,
  35. multipleSelectItemHeight: token.multipleItemHeightSM,
  36. borderRadius: token.borderRadiusSM,
  37. borderRadiusSM: token.borderRadiusXS,
  38. controlHeight: token.controlHeightSM
  39. });
  40. const largeToken = mergeToken(token, {
  41. fontHeight: calc(token.multipleItemHeightLG).sub(calc(lineWidth).mul(2).equal()).equal(),
  42. fontSize: token.fontSizeLG,
  43. selectHeight: token.controlHeightLG,
  44. multipleSelectItemHeight: token.multipleItemHeightLG,
  45. borderRadius: token.borderRadiusLG,
  46. borderRadiusSM: token.borderRadius,
  47. controlHeight: token.controlHeightLG
  48. });
  49. return [
  50. // ======================== Size ========================
  51. genSize(smallToken, 'small'), genSize(token), genSize(largeToken, 'large'),
  52. // ====================== Selection ======================
  53. {
  54. [`${componentCls}${componentCls}-multiple`]: Object.assign(Object.assign({
  55. width: '100%',
  56. cursor: 'text',
  57. // ==================== Selector =====================
  58. [`${componentCls}-selector`]: {
  59. flex: 'auto',
  60. padding: 0,
  61. position: 'relative',
  62. '&:after': {
  63. margin: 0
  64. },
  65. // ================== placeholder ==================
  66. [`${componentCls}-selection-placeholder`]: {
  67. position: 'absolute',
  68. top: '50%',
  69. insetInlineStart: token.inputPaddingHorizontalBase,
  70. insetInlineEnd: 0,
  71. transform: 'translateY(-50%)',
  72. transition: `all ${token.motionDurationSlow}`,
  73. overflow: 'hidden',
  74. whiteSpace: 'nowrap',
  75. textOverflow: 'ellipsis',
  76. flex: 1,
  77. color: token.colorTextPlaceholder,
  78. pointerEvents: 'none'
  79. }
  80. }
  81. }, genOverflowStyle(token)), {
  82. // ====================== Input ======================
  83. // Input is `readonly`, which is used for a11y only
  84. [`${componentCls}-multiple-input`]: {
  85. width: 0,
  86. height: 0,
  87. border: 0,
  88. visibility: 'hidden',
  89. position: 'absolute',
  90. zIndex: -1
  91. }
  92. })
  93. }];
  94. };
  95. export default genPickerMultipleStyle;