token.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export const prepareComponentToken = token => {
  2. const {
  3. fontSize,
  4. lineHeight,
  5. lineWidth,
  6. controlHeight,
  7. controlHeightSM,
  8. controlHeightLG,
  9. paddingXXS,
  10. controlPaddingHorizontal,
  11. zIndexPopupBase,
  12. colorText,
  13. fontWeightStrong,
  14. controlItemBgActive,
  15. controlItemBgHover,
  16. colorBgContainer,
  17. colorFillSecondary,
  18. colorBgContainerDisabled,
  19. colorTextDisabled,
  20. colorPrimaryHover,
  21. colorPrimary,
  22. controlOutline
  23. } = token;
  24. // Item height default use `controlHeight - 2 * paddingXXS`,
  25. // but some case `paddingXXS=0`.
  26. // Let's fallback it.
  27. const dblPaddingXXS = paddingXXS * 2;
  28. const dblLineWidth = lineWidth * 2;
  29. const multipleItemHeight = Math.min(controlHeight - dblPaddingXXS, controlHeight - dblLineWidth);
  30. const multipleItemHeightSM = Math.min(controlHeightSM - dblPaddingXXS, controlHeightSM - dblLineWidth);
  31. const multipleItemHeightLG = Math.min(controlHeightLG - dblPaddingXXS, controlHeightLG - dblLineWidth);
  32. // FIXED_ITEM_MARGIN is a hardcode calculation since calc not support rounding
  33. const INTERNAL_FIXED_ITEM_MARGIN = Math.floor(paddingXXS / 2);
  34. return {
  35. INTERNAL_FIXED_ITEM_MARGIN,
  36. zIndexPopup: zIndexPopupBase + 50,
  37. optionSelectedColor: colorText,
  38. optionSelectedFontWeight: fontWeightStrong,
  39. optionSelectedBg: controlItemBgActive,
  40. optionActiveBg: controlItemBgHover,
  41. optionPadding: `${(controlHeight - fontSize * lineHeight) / 2}px ${controlPaddingHorizontal}px`,
  42. optionFontSize: fontSize,
  43. optionLineHeight: lineHeight,
  44. optionHeight: controlHeight,
  45. selectorBg: colorBgContainer,
  46. clearBg: colorBgContainer,
  47. singleItemHeightLG: controlHeightLG,
  48. multipleItemBg: colorFillSecondary,
  49. multipleItemBorderColor: 'transparent',
  50. multipleItemHeight,
  51. multipleItemHeightSM,
  52. multipleItemHeightLG,
  53. multipleSelectorBgDisabled: colorBgContainerDisabled,
  54. multipleItemColorDisabled: colorTextDisabled,
  55. multipleItemBorderColorDisabled: 'transparent',
  56. showArrowPaddingInlineEnd: Math.ceil(token.fontSize * 1.25),
  57. hoverBorderColor: colorPrimaryHover,
  58. activeBorderColor: colorPrimary,
  59. activeOutlineColor: controlOutline,
  60. selectAffixPadding: paddingXXS
  61. };
  62. };