multiple.js 7.1 KB

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