Skip to content

refactor(result): less to cssinjs #6246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions components/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import unauthorized from './unauthorized';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import classNames from '../_util/classNames';

import useStyle from './style';

export const IconMap = {
success: CheckCircleFilled,
error: CloseCircleFilled,
Expand Down Expand Up @@ -61,12 +63,16 @@ const renderExtra = (prefixCls: string, extra: VNodeTypes) =>
const Result = defineComponent({
compatConfig: { MODE: 3 },
name: 'AResult',
inheritAttrs: false,
props: resultProps(),
slots: ['title', 'subTitle', 'icon', 'extra'],
setup(props, { slots }) {
setup(props, { slots, attrs }) {
const { prefixCls, direction } = useConfigInject('result', props);

const [wrapSSR, hashId] = useStyle(prefixCls);

const className = computed(() =>
classNames(prefixCls.value, `${prefixCls.value}-${props.status}`, {
classNames(prefixCls.value, hashId.value, `${prefixCls.value}-${props.status}`, {
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
}),
);
Expand All @@ -76,14 +82,14 @@ const Result = defineComponent({
const icon = props.icon ?? slots.icon?.();
const extra = props.extra ?? slots.extra?.();
const pre = prefixCls.value;
return (
<div class={className.value}>
return wrapSSR(
<div {...attrs} class={className.value}>
{renderIcon(pre, { status: props.status, icon })}
<div class={`${pre}-title`}>{title}</div>
{subTitle && <div class={`${pre}-subtitle`}>{subTitle}</div>}
{renderExtra(pre, extra)}
{slots.default && <div class={`${pre}-content`}>{slots.default()}</div>}
</div>
</div>,
);
};
},
Expand Down
75 changes: 0 additions & 75 deletions components/result/style/index.less

This file was deleted.

159 changes: 157 additions & 2 deletions components/result/style/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,157 @@
import '../../style/index.less';
import './index.less';
import type { CSSObject } from '../../_util/cssinjs';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';

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 => {
const {
componentCls,
lineHeightHeading3,
iconCls,
padding,
paddingXL,
paddingXS,
paddingLG,
marginXS,
lineHeight,
} = token;

return {
// Result
[componentCls]: {
padding: `${paddingLG * 2}px ${paddingXL}px`,

// RTL
'&-rtl': {
direction: 'rtl',
},
},

// Exception Status image
[`${componentCls} ${componentCls}-image`]: {
width: token.imageWidth,
height: token.imageHeight,
margin: 'auto',
},

[`${componentCls} ${componentCls}-icon`]: {
marginBottom: paddingLG,
textAlign: 'center',

[`& > ${iconCls}`]: {
fontSize: token.resultIconFontSize,
},
},

[`${componentCls} ${componentCls}-title`]: {
color: token.colorTextHeading,
fontSize: token.resultTitleFontSize,
lineHeight: lineHeightHeading3,
marginBlock: marginXS,
textAlign: 'center',
},

[`${componentCls} ${componentCls}-subtitle`]: {
color: token.colorTextDescription,
fontSize: token.resultSubtitleFontSize,
lineHeight,
textAlign: 'center',
},

[`${componentCls} ${componentCls}-content`]: {
marginTop: paddingLG,
padding: `${paddingLG}px ${padding * 2.5}px`,
backgroundColor: token.colorFillAlter,
},

[`${componentCls} ${componentCls}-extra`]: {
margin: token.resultExtraMargin,
textAlign: 'center',

'& > *': {
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);

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,
},
);
25 changes: 0 additions & 25 deletions components/result/style/rtl.less

This file was deleted.

2 changes: 1 addition & 1 deletion components/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import './drawer/style';
// import './config-provider/style';
import './empty/style';
// import './statistic/style';
import './result/style';
// import './result/style';
// import './descriptions/style';
// import './page-header/style';
import './form/style';
Expand Down
4 changes: 2 additions & 2 deletions components/theme/interface/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { ComponentToken as PopoverComponentToken } from '../../popover/styl
import type { ComponentToken as ProgressComponentToken } from '../../progress/style';
// import type { ComponentToken as RadioComponentToken } from '../../radio/style';
// import type { ComponentToken as RateComponentToken } from '../../rate/style';
// import type { ComponentToken as ResultComponentToken } from '../../result/style';
import type { ComponentToken as ResultComponentToken } from '../../result/style';
// import type { ComponentToken as SegmentedComponentToken } from '../../segmented/style';
// import type { ComponentToken as SelectComponentToken } from '../../select/style';
import type { ComponentToken as SkeletonComponentToken } from '../../skeleton/style';
Expand Down Expand Up @@ -87,7 +87,7 @@ export interface ComponentTokenMap {
Popconfirm?: PopconfirmComponentToken;
// Rate?: RateComponentToken;
// Radio?: RadioComponentToken;
// Result?: ResultComponentToken;
Result?: ResultComponentToken;
// Segmented?: SegmentedComponentToken;
// Select?: SelectComponentToken;
Skeleton?: SkeletonComponentToken;
Expand Down