ant-design/components/button/style/token.ts

318 lines
9.4 KiB
TypeScript
Raw Normal View History

import type { CSSProperties } from 'react';
feat(Button): support variant and color (#50051) * feat(button): variant & color types * feat: type -> color/variant * feat: type -> color/variant * feat: add variant filled * test: snap * refactor(button): rename type -> variant * docs: add demo * feat: add danger ghost style * refactor: remove deprecated * refactor: eslint * docs: change color&variant * test: updated snap * docs: color-variant * docs: add debug color&variant * feat: global token * refactor: remove comment * docs: add color&variant docs * docs: remove default * docs: add space * docs: code * test: update snap * test: fix snap * test: btn querySelect * feat: change filled hoverStyle * test: fix * feat: support grey wave * refactor: enhance * docs: color/variant -> v 5.21 * test: snap * feat: add token * test: to do * test: fix test * ci: rebuild * style: remove * style: space * docs: add note & FQA * feat: add componentsToken * refactor: remove isNotGrey * test: add case * docs: tile button * test: snap * docs: site & snap * Update components/button/index.en-US.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * fix: token color & undef * docs: site * docs: responsive * docs: enhance FAQ * docs: gap middle * test: snap * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * refactor: rename * docs: prettier * chore: eslint * refactor: cls * test: add solidTextColor case * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * fix: rename * docs: text * fix: remove border * feat: add token colorErrorBgFilledHover * chore: add size-limit * refactor: rename --------- Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: MadCcc <1075746765@qq.com>
2024-09-03 17:39:02 +08:00
import { AggregationColor } from '../../color-picker/color';
import { isBright } from '../../color-picker/components/ColorPresets';
import type { FullToken, GenStyleFn, GetDefaultToken } from '../../theme/internal';
import { getLineHeight, mergeToken } from '../../theme/internal';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
/**
* @desc
* @descEN Font weight of text
*/
fontWeight: CSSProperties['fontWeight'];
/**
* @desc
* @descEN Shadow of default button
*/
defaultShadow: string;
/**
* @desc
* @descEN Shadow of primary button
*/
primaryShadow: string;
/**
* @desc
* @descEN Shadow of danger button
*/
dangerShadow: string;
/**
* @desc
* @descEN Text color of primary button
*/
primaryColor: string;
/**
* @desc
* @descEN Text color of default button
*/
defaultColor: string;
/**
* @desc
* @descEN Background color of default button
*/
defaultBg: string;
/**
* @desc
* @descEN Border color of default button
*/
defaultBorderColor: string;
/**
* @desc
* @descEN Text color of danger button
*/
dangerColor: string;
/**
* @desc
* @descEN Background color of default button when hover
*/
defaultHoverBg: string;
/**
* @desc
* @descEN Text color of default button when hover
*/
defaultHoverColor: string;
/**
* @desc
* @descEN Border color of default button
*/
defaultHoverBorderColor: string;
/**
* @desc
* @descEN Background color of default button when active
*/
defaultActiveBg: string;
/**
* @desc
* @descEN Text color of default button when active
*/
defaultActiveColor: string;
/**
* @desc
* @descEN Border color of default button when active
*/
defaultActiveBorderColor: string;
/**
* @desc
* @descEN Border color of disabled button
*/
borderColorDisabled: string;
/**
* @desc
* @descEN Text color of default ghost button
*/
defaultGhostColor: string;
/**
* @desc
* @descEN Background color of ghost button
*/
ghostBg: string;
/**
* @desc
* @descEN Border color of default ghost button
*/
defaultGhostBorderColor: string;
feat(Button): support variant and color (#50051) * feat(button): variant & color types * feat: type -> color/variant * feat: type -> color/variant * feat: add variant filled * test: snap * refactor(button): rename type -> variant * docs: add demo * feat: add danger ghost style * refactor: remove deprecated * refactor: eslint * docs: change color&variant * test: updated snap * docs: color-variant * docs: add debug color&variant * feat: global token * refactor: remove comment * docs: add color&variant docs * docs: remove default * docs: add space * docs: code * test: update snap * test: fix snap * test: btn querySelect * feat: change filled hoverStyle * test: fix * feat: support grey wave * refactor: enhance * docs: color/variant -> v 5.21 * test: snap * feat: add token * test: to do * test: fix test * ci: rebuild * style: remove * style: space * docs: add note & FQA * feat: add componentsToken * refactor: remove isNotGrey * test: add case * docs: tile button * test: snap * docs: site & snap * Update components/button/index.en-US.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * fix: token color & undef * docs: site * docs: responsive * docs: enhance FAQ * docs: gap middle * test: snap * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * refactor: rename * docs: prettier * chore: eslint * refactor: cls * test: add solidTextColor case * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * fix: rename * docs: text * fix: remove border * feat: add token colorErrorBgFilledHover * chore: add size-limit * refactor: rename --------- Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: MadCcc <1075746765@qq.com>
2024-09-03 17:39:02 +08:00
/**
* @desc
* @descEN Background color of primary filled button
*/
/**
* @desc
* @descEN Default text color for solid buttons.
*/
solidTextColor: string;
2024-09-18 23:26:56 +08:00
/**
* @desc
* @descEN Default text color for text buttons
*/
textTextColor: string;
/**
* @desc
* @descEN Default text color for text buttons on hover
*/
textTextHoverColor: string;
/**
* @desc
* @descEN Default text color for text buttons on active
*/
textTextActiveColor: string;
/**
* @desc
* @descEN Horizontal padding of button
*/
paddingInline: CSSProperties['paddingInline'];
/**
* @desc
* @descEN Horizontal padding of large button
*/
paddingInlineLG: CSSProperties['paddingInline'];
/**
* @desc
* @descEN Horizontal padding of small button
*/
paddingInlineSM: CSSProperties['paddingInline'];
/**
* @desc
* @descEN Vertical padding of button
*/
paddingBlock: CSSProperties['paddingBlock'];
/**
* @desc
* @descEN Vertical padding of large button
*/
paddingBlockLG: CSSProperties['paddingBlock'];
/**
* @desc
* @descEN Vertical padding of small button
*/
paddingBlockSM: CSSProperties['paddingBlock'];
/**
* @desc
* @descEN Icon size of button which only contains icon
*/
onlyIconSize: number;
/**
* @desc
* @descEN Icon size of large button which only contains icon
*/
onlyIconSizeLG: number;
/**
* @desc
* @descEN Icon size of small button which only contains icon
*/
onlyIconSizeSM: number;
/**
* @desc
* @descEN Border color of button group
*/
groupBorderColor: string;
/**
* @desc
* @descEN Background color of link button when hover
*/
linkHoverBg: string;
/**
* @desc
* @descEN Background color of text button when hover
*/
textHoverBg: string;
/**
* @desc
* @descEN Font size of button content
*/
contentFontSize: number;
/**
* @desc
* @descEN Font size of large button content
*/
contentFontSizeLG: number;
/**
* @desc
* @descEN Font size of small button content
*/
contentFontSizeSM: number;
/**
* @desc
* @descEN Line height of button content
*/
contentLineHeight: number;
/**
* @desc
* @descEN Line height of large button content
*/
contentLineHeightLG: number;
/**
* @desc
* @descEN Line height of small button content
*/
contentLineHeightSM: number;
}
export interface ButtonToken extends FullToken<'Button'> {
/**
* @desc
* @descEN Horizontal padding of button
*/
buttonPaddingHorizontal: CSSProperties['paddingInline'];
/**
* @desc
* @descEN Vertical padding of button
*/
buttonPaddingVertical: CSSProperties['paddingBlock'];
/**
* @desc
* @descEN Icon size of button which only contains icon
*/
buttonIconOnlyFontSize: number;
}
export const prepareToken: (token: Parameters<GenStyleFn<'Button'>>[0]) => ButtonToken = (
token,
) => {
const { paddingInline, onlyIconSize, paddingBlock } = token;
const buttonToken = mergeToken<ButtonToken>(token, {
buttonPaddingHorizontal: paddingInline,
buttonPaddingVertical: paddingBlock,
buttonIconOnlyFontSize: onlyIconSize,
});
return buttonToken;
};
export const prepareComponentToken: GetDefaultToken<'Button'> = (token) => {
const contentFontSize = token.contentFontSize ?? token.fontSize;
const contentFontSizeSM = token.contentFontSizeSM ?? token.fontSize;
const contentFontSizeLG = token.contentFontSizeLG ?? token.fontSizeLG;
const contentLineHeight = token.contentLineHeight ?? getLineHeight(contentFontSize);
const contentLineHeightSM = token.contentLineHeightSM ?? getLineHeight(contentFontSizeSM);
const contentLineHeightLG = token.contentLineHeightLG ?? getLineHeight(contentFontSizeLG);
feat(Button): support variant and color (#50051) * feat(button): variant & color types * feat: type -> color/variant * feat: type -> color/variant * feat: add variant filled * test: snap * refactor(button): rename type -> variant * docs: add demo * feat: add danger ghost style * refactor: remove deprecated * refactor: eslint * docs: change color&variant * test: updated snap * docs: color-variant * docs: add debug color&variant * feat: global token * refactor: remove comment * docs: add color&variant docs * docs: remove default * docs: add space * docs: code * test: update snap * test: fix snap * test: btn querySelect * feat: change filled hoverStyle * test: fix * feat: support grey wave * refactor: enhance * docs: color/variant -> v 5.21 * test: snap * feat: add token * test: to do * test: fix test * ci: rebuild * style: remove * style: space * docs: add note & FQA * feat: add componentsToken * refactor: remove isNotGrey * test: add case * docs: tile button * test: snap * docs: site & snap * Update components/button/index.en-US.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * fix: token color & undef * docs: site * docs: responsive * docs: enhance FAQ * docs: gap middle * test: snap * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * refactor: rename * docs: prettier * chore: eslint * refactor: cls * test: add solidTextColor case * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * fix: rename * docs: text * fix: remove border * feat: add token colorErrorBgFilledHover * chore: add size-limit * refactor: rename --------- Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: MadCcc <1075746765@qq.com>
2024-09-03 17:39:02 +08:00
const solidTextColor = isBright(new AggregationColor(token.colorBgSolid), '#fff')
? '#000'
: '#fff';
return {
fontWeight: 400,
defaultShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlTmpOutline}`,
primaryShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlOutline}`,
dangerShadow: `0 ${token.controlOutlineWidth}px 0 ${token.colorErrorOutline}`,
primaryColor: token.colorTextLightSolid,
dangerColor: token.colorTextLightSolid,
borderColorDisabled: token.colorBorder,
defaultGhostColor: token.colorBgContainer,
ghostBg: 'transparent',
defaultGhostBorderColor: token.colorBgContainer,
paddingInline: token.paddingContentHorizontal - token.lineWidth,
paddingInlineLG: token.paddingContentHorizontal - token.lineWidth,
paddingInlineSM: 8 - token.lineWidth,
onlyIconSize: token.fontSizeLG,
onlyIconSizeSM: token.fontSizeLG - 2,
onlyIconSizeLG: token.fontSizeLG + 2,
groupBorderColor: token.colorPrimaryHover,
linkHoverBg: 'transparent',
2024-09-18 23:26:56 +08:00
textTextColor: token.colorText,
textTextHoverColor: token.colorText,
textTextActiveColor: token.colorText,
textHoverBg: token.colorBgTextHover,
defaultColor: token.colorText,
defaultBg: token.colorBgContainer,
defaultBorderColor: token.colorBorder,
defaultBorderColorDisabled: token.colorBorder,
defaultHoverBg: token.colorBgContainer,
defaultHoverColor: token.colorPrimaryHover,
defaultHoverBorderColor: token.colorPrimaryHover,
defaultActiveBg: token.colorBgContainer,
defaultActiveColor: token.colorPrimaryActive,
defaultActiveBorderColor: token.colorPrimaryActive,
feat(Button): support variant and color (#50051) * feat(button): variant & color types * feat: type -> color/variant * feat: type -> color/variant * feat: add variant filled * test: snap * refactor(button): rename type -> variant * docs: add demo * feat: add danger ghost style * refactor: remove deprecated * refactor: eslint * docs: change color&variant * test: updated snap * docs: color-variant * docs: add debug color&variant * feat: global token * refactor: remove comment * docs: add color&variant docs * docs: remove default * docs: add space * docs: code * test: update snap * test: fix snap * test: btn querySelect * feat: change filled hoverStyle * test: fix * feat: support grey wave * refactor: enhance * docs: color/variant -> v 5.21 * test: snap * feat: add token * test: to do * test: fix test * ci: rebuild * style: remove * style: space * docs: add note & FQA * feat: add componentsToken * refactor: remove isNotGrey * test: add case * docs: tile button * test: snap * docs: site & snap * Update components/button/index.en-US.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * fix: token color & undef * docs: site * docs: responsive * docs: enhance FAQ * docs: gap middle * test: snap * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/theme/interface/maps/colors.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * Update components/button/style/token.ts Co-authored-by: MadCcc <1075746765@qq.com> Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> * refactor: rename * docs: prettier * chore: eslint * refactor: cls * test: add solidTextColor case * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * refactor: genVariantButtonStyle * fix: rename * docs: text * fix: remove border * feat: add token colorErrorBgFilledHover * chore: add size-limit * refactor: rename --------- Signed-off-by: ice <49827327+coding-ice@users.noreply.github.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: MadCcc <1075746765@qq.com>
2024-09-03 17:39:02 +08:00
solidTextColor,
contentFontSize,
contentFontSizeSM,
contentFontSizeLG,
contentLineHeight,
contentLineHeightSM,
contentLineHeightLG,
paddingBlock: Math.max(
(token.controlHeight - contentFontSize * contentLineHeight) / 2 - token.lineWidth,
0,
),
paddingBlockSM: Math.max(
(token.controlHeightSM - contentFontSizeSM * contentLineHeightSM) / 2 - token.lineWidth,
0,
),
paddingBlockLG: Math.max(
(token.controlHeightLG - contentFontSizeLG * contentLineHeightLG) / 2 - token.lineWidth,
0,
),
};
};