token.js 4.3 KB

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