multiple.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { mergeToken } from '../../theme/internal';
  3. import { resetIcon } from '../../style';
  4. const FIXED_ITEM_MARGIN = 2;
  5. function getSelectItemStyle(_ref) {
  6. let {
  7. controlHeightSM,
  8. controlHeight,
  9. lineWidth: borderWidth
  10. } = _ref;
  11. const selectItemDist = (controlHeight - controlHeightSM) / 2 - borderWidth;
  12. const selectItemMargin = Math.ceil(selectItemDist / 2);
  13. return [selectItemDist, selectItemMargin];
  14. }
  15. function genSizeStyle(token, suffix) {
  16. const {
  17. componentCls,
  18. iconCls
  19. } = token;
  20. const selectOverflowPrefixCls = `${componentCls}-selection-overflow`;
  21. const selectItemHeight = token.controlHeightSM;
  22. const [selectItemDist] = getSelectItemStyle(token);
  23. const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
  24. return {
  25. [`${componentCls}-multiple${suffixCls}`]: {
  26. fontSize: token.fontSize,
  27. /**
  28. * Do not merge `height` & `line-height` under style with `selection` & `search`, since chrome
  29. * may update to redesign with its align logic.
  30. */
  31. // =========================== Overflow ===========================
  32. [selectOverflowPrefixCls]: {
  33. position: 'relative',
  34. display: 'flex',
  35. flex: 'auto',
  36. flexWrap: 'wrap',
  37. maxWidth: '100%',
  38. '&-item': {
  39. flex: 'none',
  40. alignSelf: 'center',
  41. maxWidth: '100%',
  42. display: 'inline-flex'
  43. }
  44. },
  45. // ========================= Selector =========================
  46. [`${componentCls}-selector`]: {
  47. display: 'flex',
  48. flexWrap: 'wrap',
  49. alignItems: 'center',
  50. // Multiple is little different that horizontal is follow the vertical
  51. padding: `${selectItemDist - FIXED_ITEM_MARGIN}px ${FIXED_ITEM_MARGIN * 2}px`,
  52. borderRadius: token.borderRadius,
  53. [`${componentCls}-show-search&`]: {
  54. cursor: 'text'
  55. },
  56. [`${componentCls}-disabled&`]: {
  57. background: token.colorBgContainerDisabled,
  58. cursor: 'not-allowed'
  59. },
  60. '&:after': {
  61. display: 'inline-block',
  62. width: 0,
  63. margin: `${FIXED_ITEM_MARGIN}px 0`,
  64. lineHeight: `${selectItemHeight}px`,
  65. content: '"\\a0"'
  66. }
  67. },
  68. [`
  69. &${componentCls}-show-arrow ${componentCls}-selector,
  70. &${componentCls}-allow-clear ${componentCls}-selector
  71. `]: {
  72. paddingInlineEnd: token.fontSizeIcon + token.controlPaddingHorizontal
  73. },
  74. // ======================== Selections ========================
  75. [`${componentCls}-selection-item`]: {
  76. position: 'relative',
  77. display: 'flex',
  78. flex: 'none',
  79. boxSizing: 'border-box',
  80. maxWidth: '100%',
  81. height: selectItemHeight,
  82. marginTop: FIXED_ITEM_MARGIN,
  83. marginBottom: FIXED_ITEM_MARGIN,
  84. lineHeight: `${selectItemHeight - token.lineWidth * 2}px`,
  85. background: token.colorFillSecondary,
  86. border: `${token.lineWidth}px solid ${token.colorSplit}`,
  87. borderRadius: token.borderRadiusSM,
  88. cursor: 'default',
  89. transition: `font-size ${token.motionDurationSlow}, line-height ${token.motionDurationSlow}, height ${token.motionDurationSlow}`,
  90. userSelect: 'none',
  91. marginInlineEnd: FIXED_ITEM_MARGIN * 2,
  92. paddingInlineStart: token.paddingXS,
  93. paddingInlineEnd: token.paddingXS / 2,
  94. [`${componentCls}-disabled&`]: {
  95. color: token.colorTextDisabled,
  96. borderColor: token.colorBorder,
  97. cursor: 'not-allowed'
  98. },
  99. // It's ok not to do this, but 24px makes bottom narrow in view should adjust
  100. '&-content': {
  101. display: 'inline-block',
  102. marginInlineEnd: token.paddingXS / 2,
  103. overflow: 'hidden',
  104. whiteSpace: 'pre',
  105. textOverflow: 'ellipsis'
  106. },
  107. '&-remove': _extends(_extends({}, resetIcon()), {
  108. display: 'inline-block',
  109. color: token.colorIcon,
  110. fontWeight: 'bold',
  111. fontSize: 10,
  112. lineHeight: 'inherit',
  113. cursor: 'pointer',
  114. [`> ${iconCls}`]: {
  115. verticalAlign: '-0.2em'
  116. },
  117. '&:hover': {
  118. color: token.colorIconHover
  119. }
  120. })
  121. },
  122. // ========================== Input ==========================
  123. [`${selectOverflowPrefixCls}-item + ${selectOverflowPrefixCls}-item`]: {
  124. [`${componentCls}-selection-search`]: {
  125. marginInlineStart: 0
  126. }
  127. },
  128. [`${componentCls}-selection-search`]: {
  129. display: 'inline-flex',
  130. position: 'relative',
  131. maxWidth: '100%',
  132. marginInlineStart: token.inputPaddingHorizontalBase - selectItemDist,
  133. [`
  134. &-input,
  135. &-mirror
  136. `]: {
  137. height: selectItemHeight,
  138. fontFamily: token.fontFamily,
  139. lineHeight: `${selectItemHeight}px`,
  140. transition: `all ${token.motionDurationSlow}`
  141. },
  142. '&-input': {
  143. width: '100%',
  144. minWidth: 4.1 // fix search cursor missing
  145. },
  146. '&-mirror': {
  147. position: 'absolute',
  148. top: 0,
  149. insetInlineStart: 0,
  150. insetInlineEnd: 'auto',
  151. zIndex: 999,
  152. whiteSpace: 'pre',
  153. visibility: 'hidden'
  154. }
  155. },
  156. // ======================= Placeholder =======================
  157. [`${componentCls}-selection-placeholder `]: {
  158. position: 'absolute',
  159. top: '50%',
  160. insetInlineStart: token.inputPaddingHorizontalBase,
  161. insetInlineEnd: token.inputPaddingHorizontalBase,
  162. transform: 'translateY(-50%)',
  163. transition: `all ${token.motionDurationSlow}`
  164. }
  165. }
  166. };
  167. }
  168. export default function genMultipleStyle(token) {
  169. const {
  170. componentCls
  171. } = token;
  172. const smallToken = mergeToken(token, {
  173. controlHeight: token.controlHeightSM,
  174. controlHeightSM: token.controlHeightXS,
  175. borderRadius: token.borderRadiusSM,
  176. borderRadiusSM: token.borderRadiusXS
  177. });
  178. const [, smSelectItemMargin] = getSelectItemStyle(token);
  179. return [genSizeStyle(token),
  180. // ======================== Small ========================
  181. // Shared
  182. genSizeStyle(smallToken, 'sm'),
  183. // Padding
  184. {
  185. [`${componentCls}-multiple${componentCls}-sm`]: {
  186. [`${componentCls}-selection-placeholder`]: {
  187. insetInlineStart: token.controlPaddingHorizontalSM - token.lineWidth,
  188. insetInlineEnd: 'auto'
  189. },
  190. // https://github.com/ant-design/ant-design/issues/29559
  191. [`${componentCls}-selection-search`]: {
  192. marginInlineStart: smSelectItemMargin
  193. }
  194. }
  195. },
  196. // ======================== Large ========================
  197. // Shared
  198. genSizeStyle(mergeToken(token, {
  199. fontSize: token.fontSizeLG,
  200. controlHeight: token.controlHeightLG,
  201. controlHeightSM: token.controlHeight,
  202. borderRadius: token.borderRadiusLG,
  203. borderRadiusSM: token.borderRadius
  204. }), 'lg')];
  205. }