token.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { unit } from '@ant-design/cssinjs';
  2. import { AggregationColor } from '../../color-picker/color';
  3. import { isBright } from '../../color-picker/components/ColorPresets';
  4. import { getLineHeight, mergeToken } from '../../theme/internal';
  5. import { PresetColors } from '../../theme/interface';
  6. import getAlphaColor from '../../theme/util/getAlphaColor';
  7. export const prepareToken = token => {
  8. const {
  9. paddingInline,
  10. onlyIconSize
  11. } = token;
  12. const buttonToken = mergeToken(token, {
  13. buttonPaddingHorizontal: paddingInline,
  14. buttonPaddingVertical: 0,
  15. buttonIconOnlyFontSize: onlyIconSize
  16. });
  17. return buttonToken;
  18. };
  19. export const prepareComponentToken = token => {
  20. var _a, _b, _c, _d, _e, _f;
  21. const contentFontSize = (_a = token.contentFontSize) !== null && _a !== void 0 ? _a : token.fontSize;
  22. const contentFontSizeSM = (_b = token.contentFontSizeSM) !== null && _b !== void 0 ? _b : token.fontSize;
  23. const contentFontSizeLG = (_c = token.contentFontSizeLG) !== null && _c !== void 0 ? _c : token.fontSizeLG;
  24. const contentLineHeight = (_d = token.contentLineHeight) !== null && _d !== void 0 ? _d : getLineHeight(contentFontSize);
  25. const contentLineHeightSM = (_e = token.contentLineHeightSM) !== null && _e !== void 0 ? _e : getLineHeight(contentFontSizeSM);
  26. const contentLineHeightLG = (_f = token.contentLineHeightLG) !== null && _f !== void 0 ? _f : getLineHeight(contentFontSizeLG);
  27. const solidTextColor = isBright(new AggregationColor(token.colorBgSolid), '#fff') ? '#000' : '#fff';
  28. const shadowColorTokens = PresetColors.reduce((prev, colorKey) => Object.assign(Object.assign({}, prev), {
  29. [`${colorKey}ShadowColor`]: `0 ${unit(token.controlOutlineWidth)} 0 ${getAlphaColor(token[`${colorKey}1`], token.colorBgContainer)}`
  30. }), {});
  31. return Object.assign(Object.assign({}, shadowColorTokens), {
  32. fontWeight: 400,
  33. iconGap: token.marginXS,
  34. defaultShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlTmpOutline}`,
  35. primaryShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlOutline}`,
  36. dangerShadow: `0 ${token.controlOutlineWidth}px 0 ${token.colorErrorOutline}`,
  37. primaryColor: token.colorTextLightSolid,
  38. dangerColor: token.colorTextLightSolid,
  39. borderColorDisabled: token.colorBorder,
  40. defaultGhostColor: token.colorBgContainer,
  41. ghostBg: 'transparent',
  42. defaultGhostBorderColor: token.colorBgContainer,
  43. paddingInline: token.paddingContentHorizontal - token.lineWidth,
  44. paddingInlineLG: token.paddingContentHorizontal - token.lineWidth,
  45. paddingInlineSM: 8 - token.lineWidth,
  46. onlyIconSize: 'inherit',
  47. onlyIconSizeSM: 'inherit',
  48. onlyIconSizeLG: 'inherit',
  49. groupBorderColor: token.colorPrimaryHover,
  50. linkHoverBg: 'transparent',
  51. textTextColor: token.colorText,
  52. textTextHoverColor: token.colorText,
  53. textTextActiveColor: token.colorText,
  54. textHoverBg: token.colorFillTertiary,
  55. defaultColor: token.colorText,
  56. defaultBg: token.colorBgContainer,
  57. defaultBorderColor: token.colorBorder,
  58. defaultBorderColorDisabled: token.colorBorder,
  59. defaultHoverBg: token.colorBgContainer,
  60. defaultHoverColor: token.colorPrimaryHover,
  61. defaultHoverBorderColor: token.colorPrimaryHover,
  62. defaultActiveBg: token.colorBgContainer,
  63. defaultActiveColor: token.colorPrimaryActive,
  64. defaultActiveBorderColor: token.colorPrimaryActive,
  65. solidTextColor,
  66. contentFontSize,
  67. contentFontSizeSM,
  68. contentFontSizeLG,
  69. contentLineHeight,
  70. contentLineHeightSM,
  71. contentLineHeightLG,
  72. paddingBlock: Math.max((token.controlHeight - contentFontSize * contentLineHeight) / 2 - token.lineWidth, 0),
  73. paddingBlockSM: Math.max((token.controlHeightSM - contentFontSizeSM * contentLineHeightSM) / 2 - token.lineWidth, 0),
  74. paddingBlockLG: Math.max((token.controlHeightLG - contentFontSizeLG * contentLineHeightLG) / 2 - token.lineWidth, 0)
  75. });
  76. };