refactor: full token (#35834)

This commit is contained in:
二货机器人 2022-05-31 20:32:00 +08:00 committed by GitHub
parent 1c07387fda
commit 3b1539c711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 39 deletions

View File

@ -24,6 +24,7 @@ import type { ComponentToken as NotificationComponentToken } from '../../notific
import type { ComponentToken as PopconfirmComponentToken } from '../../popconfirm/style'; import type { ComponentToken as PopconfirmComponentToken } from '../../popconfirm/style';
import type { ComponentToken as PopoverComponentToken } from '../../popover/style'; import type { ComponentToken as PopoverComponentToken } from '../../popover/style';
import type { ComponentToken as ProgressComponentToken } from '../../progress/style'; import type { ComponentToken as ProgressComponentToken } from '../../progress/style';
import type { ComponentToken as ResultComponentToken } from '../../result/style';
import type { ComponentToken as SegmentedComponentToken } from '../../segmented/style'; import type { ComponentToken as SegmentedComponentToken } from '../../segmented/style';
import type { ComponentToken as SelectComponentToken } from '../../select/style'; import type { ComponentToken as SelectComponentToken } from '../../select/style';
import type { ComponentToken as SliderComponentToken } from '../../slider/style'; import type { ComponentToken as SliderComponentToken } from '../../slider/style';
@ -94,7 +95,7 @@ export interface OverrideToken {
Popover?: PopoverComponentToken; Popover?: PopoverComponentToken;
Popconfirm?: PopconfirmComponentToken; Popconfirm?: PopconfirmComponentToken;
Rate?: {}; Rate?: {};
Result?: {}; Result?: ResultComponentToken;
Segmented?: SegmentedComponentToken; Segmented?: SegmentedComponentToken;
Select?: SelectComponentToken; Select?: SelectComponentToken;
Skeleton?: {}; Skeleton?: {};

View File

@ -3,6 +3,11 @@ import type { CSSObject } from '@ant-design/cssinjs';
import type { GenerateStyle, FullToken } from '../../_util/theme'; import type { GenerateStyle, FullToken } from '../../_util/theme';
import { genComponentStyleHook, mergeToken } from '../../_util/theme'; import { genComponentStyleHook, mergeToken } from '../../_util/theme';
export interface ComponentToken {
imageWidth: number;
imageHeight: number;
}
interface ResultToken extends FullToken<'Result'> { interface ResultToken extends FullToken<'Result'> {
resultTitleFontSize: number; resultTitleFontSize: number;
resultSubtitleFontSize: number; resultSubtitleFontSize: number;
@ -18,12 +23,22 @@ interface ResultToken extends FullToken<'Result'> {
// ============================== Styles ============================== // ============================== Styles ==============================
const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => { const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => {
const { componentCls, iconCls } = token; const {
componentCls,
lineHeightHeading3,
iconCls,
padding,
paddingXL,
paddingXS,
paddingLG,
marginXS,
lineHeight,
} = token;
return { return {
// Result // Result
[componentCls]: { [componentCls]: {
padding: `${token.padding * 3}px ${token.padding * 2}px`, padding: `${paddingLG * 2}px ${paddingXL}px`,
// RTL // RTL
'&-rtl': { '&-rtl': {
@ -33,14 +48,13 @@ const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => {
// Exception Status image // Exception Status image
[`${componentCls} ${componentCls}-image`]: { [`${componentCls} ${componentCls}-image`]: {
// FIXME: hard code width: token.imageWidth,
width: 250, height: token.imageHeight,
height: 295,
margin: 'auto', margin: 'auto',
}, },
[`${componentCls} ${componentCls}-icon`]: { [`${componentCls} ${componentCls}-icon`]: {
marginBottom: token.padding * 1.5, marginBottom: paddingLG,
textAlign: 'center', textAlign: 'center',
[`& > ${iconCls}`]: { [`& > ${iconCls}`]: {
@ -51,22 +65,21 @@ const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => {
[`${componentCls} ${componentCls}-title`]: { [`${componentCls} ${componentCls}-title`]: {
color: token.colorTextHeading, color: token.colorTextHeading,
fontSize: token.resultTitleFontSize, fontSize: token.resultTitleFontSize,
// FIXME: hard code lineHeight: lineHeightHeading3,
lineHeight: 1.8, marginBlock: marginXS,
textAlign: 'center', textAlign: 'center',
}, },
[`${componentCls} ${componentCls}-subtitle`]: { [`${componentCls} ${componentCls}-subtitle`]: {
color: token.colorTextSecondary, color: token.colorTextSecondary,
fontSize: token.resultSubtitleFontSize, fontSize: token.resultSubtitleFontSize,
// FIXME: hard code lineHeight,
lineHeight: 1.6,
textAlign: 'center', textAlign: 'center',
}, },
[`${componentCls} ${componentCls}-content`]: { [`${componentCls} ${componentCls}-content`]: {
marginTop: token.padding * 1.5, marginTop: paddingLG,
padding: `${token.padding * 1.5}px ${token.padding * 2.5}px`, padding: `${paddingLG}px ${padding * 2.5}px`,
backgroundColor: token.colorBgComponentSecondary, backgroundColor: token.colorBgComponentSecondary,
}, },
@ -75,7 +88,7 @@ const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => {
textAlign: 'center', textAlign: 'center',
'& > *': { '& > *': {
marginInlineEnd: token.paddingXS, marginInlineEnd: paddingXS,
'&:last-child': { '&:last-child': {
marginInlineEnd: 0, marginInlineEnd: 0,
@ -112,31 +125,34 @@ const genResultStyle: GenerateStyle<ResultToken> = token => [
// ============================== Export ============================== // ============================== Export ==============================
const getStyle: GenerateStyle<ResultToken> = token => genResultStyle(token); const getStyle: GenerateStyle<ResultToken> = token => genResultStyle(token);
export default genComponentStyleHook('Result', token => { export default genComponentStyleHook(
// compact 20 'Result',
// FIXME: maybe we need a new token for fontSize 12px token => {
const resultTitleFontSize = 24; const { paddingLG, fontSizeHeading3 } = token;
const resultSubtitleFontSize = token.fontSize;
// compact 64
// FIXME: maybe we need a new token for fontSize 12px
const resultIconFontSize = 72;
const resultExtraMargin = `${token.padding * 1.5}px 0 0 0`;
const resultInfoIconColor = token.colorInfo; const resultSubtitleFontSize = token.fontSize;
const resultErrorIconColor = token.colorError; const resultExtraMargin = `${paddingLG}px 0 0 0`;
const resultSuccessIconColor = token.colorSuccess;
const resultWarningIconColor = token.colorWarning;
const resultToken = mergeToken<ResultToken>(token, { const resultInfoIconColor = token.colorInfo;
resultTitleFontSize, const resultErrorIconColor = token.colorError;
resultSubtitleFontSize, const resultSuccessIconColor = token.colorSuccess;
resultIconFontSize, const resultWarningIconColor = token.colorWarning;
resultExtraMargin,
resultInfoIconColor,
resultErrorIconColor,
resultSuccessIconColor,
resultWarningIconColor,
});
return [getStyle(resultToken)]; const resultToken = mergeToken<ResultToken>(token, {
}); resultTitleFontSize: fontSizeHeading3,
resultSubtitleFontSize,
resultIconFontSize: fontSizeHeading3 * 3,
resultExtraMargin,
resultInfoIconColor,
resultErrorIconColor,
resultSuccessIconColor,
resultWarningIconColor,
});
return [getStyle(resultToken)];
},
{
imageWidth: 250,
imageHeight: 295,
},
);