multiple.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getMultipleSelectorUnit = exports.genOverflowStyle = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. /**
  10. * Get multiple selector needed style. The calculation:
  11. *
  12. * ContainerPadding = BasePadding - ItemMargin
  13. *
  14. * Border: ╔═══════════════════════════╗ ┬
  15. * ContainerPadding: ║ ║ │
  16. * ╟───────────────────────────╢ ┬ │
  17. * Item Margin: ║ ║ │ │
  18. * ║ ┌──────────┐ ║ │ │
  19. * Item(multipleItemHeight): ║ BasePadding │ Item │ ║ Overflow Container(ControlHeight)
  20. * ║ └──────────┘ ║ │ │
  21. * Item Margin: ║ ║ │ │
  22. * ╟───────────────────────────╢ ┴ │
  23. * ContainerPadding: ║ ║ │
  24. * Border: ╚═══════════════════════════╝ ┴
  25. */
  26. const getMultipleSelectorUnit = token => {
  27. const {
  28. multipleSelectItemHeight,
  29. paddingXXS,
  30. lineWidth,
  31. INTERNAL_FIXED_ITEM_MARGIN
  32. } = token;
  33. const basePadding = token.max(token.calc(paddingXXS).sub(lineWidth).equal(), 0);
  34. const containerPadding = token.max(token.calc(basePadding).sub(INTERNAL_FIXED_ITEM_MARGIN).equal(), 0);
  35. return {
  36. basePadding,
  37. containerPadding,
  38. itemHeight: (0, _cssinjs.unit)(multipleSelectItemHeight),
  39. itemLineHeight: (0, _cssinjs.unit)(token.calc(multipleSelectItemHeight).sub(token.calc(token.lineWidth).mul(2)).equal())
  40. };
  41. };
  42. exports.getMultipleSelectorUnit = getMultipleSelectorUnit;
  43. const getSelectItemStyle = token => {
  44. const {
  45. multipleSelectItemHeight,
  46. selectHeight,
  47. lineWidth
  48. } = token;
  49. const selectItemDist = token.calc(selectHeight).sub(multipleSelectItemHeight).div(2).sub(lineWidth).equal();
  50. return selectItemDist;
  51. };
  52. /**
  53. * Get the `rc-overflow` needed style.
  54. * It's a share style which means not affected by `size`.
  55. */
  56. const genOverflowStyle = token => {
  57. const {
  58. componentCls,
  59. iconCls,
  60. borderRadiusSM,
  61. motionDurationSlow,
  62. paddingXS,
  63. multipleItemColorDisabled,
  64. multipleItemBorderColorDisabled,
  65. colorIcon,
  66. colorIconHover,
  67. INTERNAL_FIXED_ITEM_MARGIN
  68. } = token;
  69. const selectOverflowPrefixCls = `${componentCls}-selection-overflow`;
  70. return {
  71. /**
  72. * Do not merge `height` & `line-height` under style with `selection` & `search`, since chrome
  73. * may update to redesign with its align logic.
  74. */
  75. // =========================== Overflow ===========================
  76. [selectOverflowPrefixCls]: {
  77. position: 'relative',
  78. display: 'flex',
  79. flex: 'auto',
  80. flexWrap: 'wrap',
  81. maxWidth: '100%',
  82. '&-item': {
  83. flex: 'none',
  84. alignSelf: 'center',
  85. // https://github.com/ant-design/ant-design/issues/54179
  86. maxWidth: 'calc(100% - 4px)',
  87. display: 'inline-flex'
  88. },
  89. // ======================== Selections ==========================
  90. [`${componentCls}-selection-item`]: {
  91. display: 'flex',
  92. alignSelf: 'center',
  93. flex: 'none',
  94. boxSizing: 'border-box',
  95. maxWidth: '100%',
  96. marginBlock: INTERNAL_FIXED_ITEM_MARGIN,
  97. borderRadius: borderRadiusSM,
  98. cursor: 'default',
  99. transition: `font-size ${motionDurationSlow}, line-height ${motionDurationSlow}, height ${motionDurationSlow}`,
  100. marginInlineEnd: token.calc(INTERNAL_FIXED_ITEM_MARGIN).mul(2).equal(),
  101. paddingInlineStart: paddingXS,
  102. paddingInlineEnd: token.calc(paddingXS).div(2).equal(),
  103. [`${componentCls}-disabled&`]: {
  104. color: multipleItemColorDisabled,
  105. borderColor: multipleItemBorderColorDisabled,
  106. cursor: 'not-allowed'
  107. },
  108. // It's ok not to do this, but 24px makes bottom narrow in view should adjust
  109. '&-content': {
  110. display: 'inline-block',
  111. marginInlineEnd: token.calc(paddingXS).div(2).equal(),
  112. overflow: 'hidden',
  113. whiteSpace: 'pre',
  114. // fix whitespace wrapping. custom tags display all whitespace within.
  115. textOverflow: 'ellipsis'
  116. },
  117. '&-remove': Object.assign(Object.assign({}, (0, _style.resetIcon)()), {
  118. display: 'inline-flex',
  119. alignItems: 'center',
  120. color: colorIcon,
  121. fontWeight: 'bold',
  122. fontSize: 10,
  123. lineHeight: 'inherit',
  124. cursor: 'pointer',
  125. [`> ${iconCls}`]: {
  126. verticalAlign: '-0.2em'
  127. },
  128. '&:hover': {
  129. color: colorIconHover
  130. }
  131. })
  132. }
  133. }
  134. };
  135. };
  136. exports.genOverflowStyle = genOverflowStyle;
  137. const genSelectionStyle = (token, suffix) => {
  138. const {
  139. componentCls,
  140. INTERNAL_FIXED_ITEM_MARGIN
  141. } = token;
  142. const selectOverflowPrefixCls = `${componentCls}-selection-overflow`;
  143. const selectItemHeight = token.multipleSelectItemHeight;
  144. const selectItemDist = getSelectItemStyle(token);
  145. const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
  146. const multipleSelectorUnit = getMultipleSelectorUnit(token);
  147. return {
  148. [`${componentCls}-multiple${suffixCls}`]: Object.assign(Object.assign({}, genOverflowStyle(token)), {
  149. // ========================= Selector =========================
  150. [`${componentCls}-selector`]: {
  151. display: 'flex',
  152. alignItems: 'center',
  153. width: '100%',
  154. height: '100%',
  155. // Multiple is little different that horizontal is follow the vertical
  156. paddingInline: multipleSelectorUnit.basePadding,
  157. paddingBlock: multipleSelectorUnit.containerPadding,
  158. borderRadius: token.borderRadius,
  159. [`${componentCls}-disabled&`]: {
  160. background: token.multipleSelectorBgDisabled,
  161. cursor: 'not-allowed'
  162. },
  163. '&:after': {
  164. display: 'inline-block',
  165. width: 0,
  166. margin: `${(0, _cssinjs.unit)(INTERNAL_FIXED_ITEM_MARGIN)} 0`,
  167. lineHeight: (0, _cssinjs.unit)(selectItemHeight),
  168. visibility: 'hidden',
  169. content: '"\\a0"'
  170. }
  171. },
  172. // ======================== Selections ========================
  173. [`${componentCls}-selection-item`]: {
  174. height: multipleSelectorUnit.itemHeight,
  175. lineHeight: (0, _cssinjs.unit)(multipleSelectorUnit.itemLineHeight)
  176. },
  177. // ========================== Wrap ===========================
  178. [`${componentCls}-selection-wrap`]: {
  179. alignSelf: 'flex-start',
  180. '&:after': {
  181. lineHeight: (0, _cssinjs.unit)(selectItemHeight),
  182. marginBlock: INTERNAL_FIXED_ITEM_MARGIN
  183. }
  184. },
  185. // ========================== Input ==========================
  186. [`${componentCls}-prefix`]: {
  187. marginInlineStart: token.calc(token.inputPaddingHorizontalBase).sub(multipleSelectorUnit.basePadding).equal()
  188. },
  189. [`${selectOverflowPrefixCls}-item + ${selectOverflowPrefixCls}-item,
  190. ${componentCls}-prefix + ${componentCls}-selection-wrap
  191. `]: {
  192. [`${componentCls}-selection-search`]: {
  193. marginInlineStart: 0
  194. },
  195. [`${componentCls}-selection-placeholder`]: {
  196. insetInlineStart: 0
  197. }
  198. },
  199. // https://github.com/ant-design/ant-design/issues/44754
  200. // Same as `wrap:after`
  201. [`${selectOverflowPrefixCls}-item-suffix`]: {
  202. minHeight: multipleSelectorUnit.itemHeight,
  203. marginBlock: INTERNAL_FIXED_ITEM_MARGIN
  204. },
  205. [`${componentCls}-selection-search`]: {
  206. display: 'inline-flex',
  207. position: 'relative',
  208. maxWidth: '100%',
  209. marginInlineStart: token.calc(token.inputPaddingHorizontalBase).sub(selectItemDist).equal(),
  210. [`
  211. &-input,
  212. &-mirror
  213. `]: {
  214. height: selectItemHeight,
  215. fontFamily: token.fontFamily,
  216. lineHeight: (0, _cssinjs.unit)(selectItemHeight),
  217. transition: `all ${token.motionDurationSlow}`
  218. },
  219. '&-input': {
  220. width: '100%',
  221. minWidth: 4.1 // fix search cursor missing
  222. },
  223. '&-mirror': {
  224. position: 'absolute',
  225. top: 0,
  226. insetInlineStart: 0,
  227. insetInlineEnd: 'auto',
  228. zIndex: 999,
  229. whiteSpace: 'pre',
  230. // fix whitespace wrapping caused width calculation bug
  231. visibility: 'hidden'
  232. }
  233. },
  234. // ======================= Placeholder =======================
  235. [`${componentCls}-selection-placeholder`]: {
  236. position: 'absolute',
  237. top: '50%',
  238. insetInlineStart: token.calc(token.inputPaddingHorizontalBase).sub(multipleSelectorUnit.basePadding).equal(),
  239. insetInlineEnd: token.inputPaddingHorizontalBase,
  240. transform: 'translateY(-50%)',
  241. transition: `all ${token.motionDurationSlow}`
  242. }
  243. })
  244. };
  245. };
  246. function genSizeStyle(token, suffix) {
  247. const {
  248. componentCls
  249. } = token;
  250. const suffixCls = suffix ? `${componentCls}-${suffix}` : '';
  251. const rawStyle = {
  252. [`${componentCls}-multiple${suffixCls}`]: {
  253. fontSize: token.fontSize,
  254. // ========================= Selector =========================
  255. [`${componentCls}-selector`]: {
  256. [`${componentCls}-show-search&`]: {
  257. cursor: 'text'
  258. }
  259. },
  260. [`
  261. &${componentCls}-show-arrow ${componentCls}-selector,
  262. &${componentCls}-allow-clear ${componentCls}-selector
  263. `]: {
  264. paddingInlineEnd: token.calc(token.fontSizeIcon).add(token.controlPaddingHorizontal).equal()
  265. }
  266. }
  267. };
  268. return [genSelectionStyle(token, suffix), rawStyle];
  269. }
  270. const genMultipleStyle = token => {
  271. const {
  272. componentCls
  273. } = token;
  274. const smallToken = (0, _internal.mergeToken)(token, {
  275. selectHeight: token.controlHeightSM,
  276. multipleSelectItemHeight: token.multipleItemHeightSM,
  277. borderRadius: token.borderRadiusSM,
  278. borderRadiusSM: token.borderRadiusXS
  279. });
  280. const largeToken = (0, _internal.mergeToken)(token, {
  281. fontSize: token.fontSizeLG,
  282. selectHeight: token.controlHeightLG,
  283. multipleSelectItemHeight: token.multipleItemHeightLG,
  284. borderRadius: token.borderRadiusLG,
  285. borderRadiusSM: token.borderRadius
  286. });
  287. return [genSizeStyle(token),
  288. // ======================== Small ========================
  289. genSizeStyle(smallToken, 'sm'),
  290. // Padding
  291. {
  292. [`${componentCls}-multiple${componentCls}-sm`]: {
  293. [`${componentCls}-selection-placeholder`]: {
  294. insetInline: token.calc(token.controlPaddingHorizontalSM).sub(token.lineWidth).equal()
  295. },
  296. // https://github.com/ant-design/ant-design/issues/29559
  297. [`${componentCls}-selection-search`]: {
  298. marginInlineStart: 2 // Magic Number
  299. }
  300. }
  301. },
  302. // ======================== Large ========================
  303. genSizeStyle(largeToken, 'lg')];
  304. };
  305. var _default = exports.default = genMultipleStyle;