|
1 |
| -import '../../style/index.less'; |
2 |
| -import './index.less'; |
| 1 | +import type { CSSObject } from '../../_util/cssinjs'; |
| 2 | +import type { FullToken, GenerateStyle } from '../../theme/internal'; |
| 3 | +import { genComponentStyleHook, mergeToken } from '../../theme/internal'; |
| 4 | + |
| 5 | +export interface ComponentToken { |
| 6 | + imageWidth: number; |
| 7 | + imageHeight: number; |
| 8 | +} |
| 9 | + |
| 10 | +interface ResultToken extends FullToken<'Result'> { |
| 11 | + resultTitleFontSize: number; |
| 12 | + resultSubtitleFontSize: number; |
| 13 | + resultIconFontSize: number; |
| 14 | + |
| 15 | + resultExtraMargin: string; |
| 16 | + |
| 17 | + resultInfoIconColor: string; |
| 18 | + resultSuccessIconColor: string; |
| 19 | + resultWarningIconColor: string; |
| 20 | + resultErrorIconColor: string; |
| 21 | +} |
| 22 | + |
| 23 | +// ============================== Styles ============================== |
| 24 | +const genBaseStyle: GenerateStyle<ResultToken> = (token): CSSObject => { |
| 25 | + const { |
| 26 | + componentCls, |
| 27 | + lineHeightHeading3, |
| 28 | + iconCls, |
| 29 | + padding, |
| 30 | + paddingXL, |
| 31 | + paddingXS, |
| 32 | + paddingLG, |
| 33 | + marginXS, |
| 34 | + lineHeight, |
| 35 | + } = token; |
| 36 | + |
| 37 | + return { |
| 38 | + // Result |
| 39 | + [componentCls]: { |
| 40 | + padding: `${paddingLG * 2}px ${paddingXL}px`, |
| 41 | + |
| 42 | + // RTL |
| 43 | + '&-rtl': { |
| 44 | + direction: 'rtl', |
| 45 | + }, |
| 46 | + }, |
| 47 | + |
| 48 | + // Exception Status image |
| 49 | + [`${componentCls} ${componentCls}-image`]: { |
| 50 | + width: token.imageWidth, |
| 51 | + height: token.imageHeight, |
| 52 | + margin: 'auto', |
| 53 | + }, |
| 54 | + |
| 55 | + [`${componentCls} ${componentCls}-icon`]: { |
| 56 | + marginBottom: paddingLG, |
| 57 | + textAlign: 'center', |
| 58 | + |
| 59 | + [`& > ${iconCls}`]: { |
| 60 | + fontSize: token.resultIconFontSize, |
| 61 | + }, |
| 62 | + }, |
| 63 | + |
| 64 | + [`${componentCls} ${componentCls}-title`]: { |
| 65 | + color: token.colorTextHeading, |
| 66 | + fontSize: token.resultTitleFontSize, |
| 67 | + lineHeight: lineHeightHeading3, |
| 68 | + marginBlock: marginXS, |
| 69 | + textAlign: 'center', |
| 70 | + }, |
| 71 | + |
| 72 | + [`${componentCls} ${componentCls}-subtitle`]: { |
| 73 | + color: token.colorTextDescription, |
| 74 | + fontSize: token.resultSubtitleFontSize, |
| 75 | + lineHeight, |
| 76 | + textAlign: 'center', |
| 77 | + }, |
| 78 | + |
| 79 | + [`${componentCls} ${componentCls}-content`]: { |
| 80 | + marginTop: paddingLG, |
| 81 | + padding: `${paddingLG}px ${padding * 2.5}px`, |
| 82 | + backgroundColor: token.colorFillAlter, |
| 83 | + }, |
| 84 | + |
| 85 | + [`${componentCls} ${componentCls}-extra`]: { |
| 86 | + margin: token.resultExtraMargin, |
| 87 | + textAlign: 'center', |
| 88 | + |
| 89 | + '& > *': { |
| 90 | + marginInlineEnd: paddingXS, |
| 91 | + |
| 92 | + '&:last-child': { |
| 93 | + marginInlineEnd: 0, |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }; |
| 98 | +}; |
| 99 | + |
| 100 | +const genStatusIconStyle: GenerateStyle<ResultToken> = token => { |
| 101 | + const { componentCls, iconCls } = token; |
| 102 | + |
| 103 | + return { |
| 104 | + [`${componentCls}-success ${componentCls}-icon > ${iconCls}`]: { |
| 105 | + color: token.resultSuccessIconColor, |
| 106 | + }, |
| 107 | + [`${componentCls}-error ${componentCls}-icon > ${iconCls}`]: { |
| 108 | + color: token.resultErrorIconColor, |
| 109 | + }, |
| 110 | + [`${componentCls}-info ${componentCls}-icon > ${iconCls}`]: { |
| 111 | + color: token.resultInfoIconColor, |
| 112 | + }, |
| 113 | + [`${componentCls}-warning ${componentCls}-icon > ${iconCls}`]: { |
| 114 | + color: token.resultWarningIconColor, |
| 115 | + }, |
| 116 | + }; |
| 117 | +}; |
| 118 | + |
| 119 | +const genResultStyle: GenerateStyle<ResultToken> = token => [ |
| 120 | + genBaseStyle(token), |
| 121 | + genStatusIconStyle(token), |
| 122 | +]; |
| 123 | + |
| 124 | +// ============================== Export ============================== |
| 125 | +const getStyle: GenerateStyle<ResultToken> = token => genResultStyle(token); |
| 126 | + |
| 127 | +export default genComponentStyleHook( |
| 128 | + 'Result', |
| 129 | + token => { |
| 130 | + const { paddingLG, fontSizeHeading3 } = token; |
| 131 | + |
| 132 | + const resultSubtitleFontSize = token.fontSize; |
| 133 | + const resultExtraMargin = `${paddingLG}px 0 0 0`; |
| 134 | + |
| 135 | + const resultInfoIconColor = token.colorInfo; |
| 136 | + const resultErrorIconColor = token.colorError; |
| 137 | + const resultSuccessIconColor = token.colorSuccess; |
| 138 | + const resultWarningIconColor = token.colorWarning; |
| 139 | + |
| 140 | + const resultToken = mergeToken<ResultToken>(token, { |
| 141 | + resultTitleFontSize: fontSizeHeading3, |
| 142 | + resultSubtitleFontSize, |
| 143 | + resultIconFontSize: fontSizeHeading3 * 3, |
| 144 | + resultExtraMargin, |
| 145 | + resultInfoIconColor, |
| 146 | + resultErrorIconColor, |
| 147 | + resultSuccessIconColor, |
| 148 | + resultWarningIconColor, |
| 149 | + }); |
| 150 | + |
| 151 | + return [getStyle(resultToken)]; |
| 152 | + }, |
| 153 | + { |
| 154 | + imageWidth: 250, |
| 155 | + imageHeight: 295, |
| 156 | + }, |
| 157 | +); |
0 commit comments