ant-design/components/result/style/index.tsx

158 lines
3.9 KiB
TypeScript
Raw Normal View History

2022-05-09 22:20:07 +08:00
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../theme';
import { genComponentStyleHook, mergeToken } from '../../theme';
2022-05-31 20:32:00 +08:00
export interface ComponentToken {
imageWidth: number;
imageHeight: number;
}
interface ResultToken extends FullToken<'Result'> {
resultTitleFontSize: number;
resultSubtitleFontSize: number;
resultIconFontSize: number;
resultExtraMargin: string;
resultInfoIconColor: string;
resultSuccessIconColor: string;
resultWarningIconColor: string;
resultErrorIconColor: string;
}
// ============================== Styles ==============================
const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => {
2022-05-31 20:32:00 +08:00
const {
componentCls,
lineHeightHeading3,
iconCls,
padding,
paddingXL,
paddingXS,
paddingLG,
marginXS,
lineHeight,
} = token;
return {
// Result
[componentCls]: {
2022-05-31 20:32:00 +08:00
padding: `${paddingLG * 2}px ${paddingXL}px`,
// RTL
'&-rtl': {
direction: 'rtl',
},
},
// Exception Status image
[`${componentCls} ${componentCls}-image`]: {
2022-05-31 20:32:00 +08:00
width: token.imageWidth,
height: token.imageHeight,
margin: 'auto',
},
[`${componentCls} ${componentCls}-icon`]: {
2022-05-31 20:32:00 +08:00
marginBottom: paddingLG,
textAlign: 'center',
[`& > ${iconCls}`]: {
fontSize: token.resultIconFontSize,
},
},
[`${componentCls} ${componentCls}-title`]: {
color: token.colorTextHeading,
fontSize: token.resultTitleFontSize,
2022-05-31 20:32:00 +08:00
lineHeight: lineHeightHeading3,
marginBlock: marginXS,
textAlign: 'center',
},
[`${componentCls} ${componentCls}-subtitle`]: {
color: token.colorTextSecondary,
fontSize: token.resultSubtitleFontSize,
2022-05-31 20:32:00 +08:00
lineHeight,
textAlign: 'center',
},
[`${componentCls} ${componentCls}-content`]: {
2022-05-31 20:32:00 +08:00
marginTop: paddingLG,
padding: `${paddingLG}px ${padding * 2.5}px`,
backgroundColor: token.colorBgContainerSecondary,
},
[`${componentCls} ${componentCls}-extra`]: {
margin: token.resultExtraMargin,
textAlign: 'center',
'& > *': {
2022-05-31 20:32:00 +08:00
marginInlineEnd: paddingXS,
'&:last-child': {
marginInlineEnd: 0,
},
},
},
};
};
const genStatusIconStyle: GenerateStyle<ResultToken> = token => {
const { componentCls, iconCls } = token;
return {
[`${componentCls}-success ${componentCls}-icon > ${iconCls}`]: {
color: token.resultSuccessIconColor,
},
[`${componentCls}-error ${componentCls}-icon > ${iconCls}`]: {
color: token.resultErrorIconColor,
},
[`${componentCls}-info ${componentCls}-icon > ${iconCls}`]: {
color: token.resultInfoIconColor,
},
[`${componentCls}-warning ${componentCls}-icon > ${iconCls}`]: {
color: token.resultWarningIconColor,
},
};
};
const genResultStyle: GenerateStyle<ResultToken> = token => [
genBaseStyle(token),
genStatusIconStyle(token),
];
// ============================== Export ==============================
const getStyle: GenerateStyle<ResultToken> = token => genResultStyle(token);
2022-05-31 20:32:00 +08:00
export default genComponentStyleHook(
'Result',
token => {
const { paddingLG, fontSizeHeading3 } = token;
const resultSubtitleFontSize = token.fontSize;
const resultExtraMargin = `${paddingLG}px 0 0 0`;
const resultInfoIconColor = token.colorInfo;
const resultErrorIconColor = token.colorError;
const resultSuccessIconColor = token.colorSuccess;
const resultWarningIconColor = token.colorWarning;
const resultToken = mergeToken<ResultToken>(token, {
resultTitleFontSize: fontSizeHeading3,
resultSubtitleFontSize,
resultIconFontSize: fontSizeHeading3 * 3,
resultExtraMargin,
resultInfoIconColor,
resultErrorIconColor,
resultSuccessIconColor,
resultWarningIconColor,
});
return [getStyle(resultToken)];
},
{
imageWidth: 250,
imageHeight: 295,
},
);