Skip to content

Commit 26f98b7

Browse files
authored
refactor:statistic (#6240)
* refactor:statistic * fix inheritAttrs: false & attrs.class
1 parent a9fbf98 commit 26f98b7

File tree

5 files changed

+85
-68
lines changed

5 files changed

+85
-68
lines changed

components/statistic/Statistic.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import type { valueType } from './utils';
77
import Skeleton from '../skeleton/Skeleton';
88
import useConfigInject from '../config-provider/hooks/useConfigInject';
99

10+
// CSSINJS
11+
import useStyle from './style';
12+
1013
export const statisticProps = () => ({
1114
prefixCls: String,
1215
decimalSeparator: String,
@@ -30,14 +33,19 @@ export type StatisticProps = Partial<ExtractPropTypes<ReturnType<typeof statisti
3033
export default defineComponent({
3134
compatConfig: { MODE: 3 },
3235
name: 'AStatistic',
36+
inheritAttrs: false,
3337
props: initDefaultProps(statisticProps(), {
3438
decimalSeparator: '.',
3539
groupSeparator: ',',
3640
loading: false,
3741
}),
3842
slots: ['title', 'prefix', 'suffix', 'formatter'],
39-
setup(props, { slots }) {
43+
setup(props, { slots, attrs }) {
4044
const { prefixCls, direction } = useConfigInject('statistic', props);
45+
46+
// Style
47+
const [wrapSSR, hashId] = useStyle(prefixCls);
48+
4149
return () => {
4250
const { value = 0, valueStyle, valueRender } = props;
4351
const pre = prefixCls.value;
@@ -56,8 +64,11 @@ export default defineComponent({
5664
if (valueRender) {
5765
valueNode = valueRender(valueNode);
5866
}
59-
return (
60-
<div class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }]}>
67+
return wrapSSR(
68+
<div
69+
{...attrs}
70+
class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }, attrs.class, hashId.value]}
71+
>
6172
{title && <div class={`${pre}-title`}>{title}</div>}
6273
<Skeleton paragraph={false} loading={props.loading}>
6374
<div style={valueStyle} class={`${pre}-content`}>
@@ -66,7 +77,7 @@ export default defineComponent({
6677
{suffix && <span class={`${pre}-content-suffix`}>{suffix}</span>}
6778
</div>
6879
</Skeleton>
69-
</div>
80+
</div>,
7081
);
7182
};
7283
},

components/statistic/style/index.less

-40
This file was deleted.

components/statistic/style/index.tsx

+69-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
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+
import { resetComponent } from '../../_style';
5+
6+
interface StatisticToken extends FullToken<'Statistic'> {
7+
statisticTitleFontSize: number;
8+
statisticContentFontSize: number;
9+
statisticFontFamily: string;
10+
}
11+
12+
const genStatisticStyle: GenerateStyle<StatisticToken> = (token: StatisticToken): CSSObject => {
13+
const {
14+
componentCls,
15+
marginXXS,
16+
padding,
17+
colorTextDescription,
18+
statisticTitleFontSize,
19+
colorTextHeading,
20+
statisticContentFontSize,
21+
statisticFontFamily,
22+
} = token;
23+
24+
return {
25+
[`${componentCls}`]: {
26+
...resetComponent(token),
27+
[`${componentCls}-title`]: {
28+
marginBottom: marginXXS,
29+
color: colorTextDescription,
30+
fontSize: statisticTitleFontSize,
31+
},
32+
33+
[`${componentCls}-skeleton`]: {
34+
paddingTop: padding,
35+
},
36+
37+
[`${componentCls}-content`]: {
38+
color: colorTextHeading,
39+
fontSize: statisticContentFontSize,
40+
fontFamily: statisticFontFamily,
41+
[`${componentCls}-content-value`]: {
42+
display: 'inline-block',
43+
direction: 'ltr',
44+
},
45+
[`${componentCls}-content-prefix, ${componentCls}-content-suffix`]: {
46+
display: 'inline-block',
47+
},
48+
[`${componentCls}-content-prefix`]: {
49+
marginInlineEnd: marginXXS,
50+
},
51+
[`${componentCls}-content-suffix`]: {
52+
marginInlineStart: marginXXS,
53+
},
54+
},
55+
},
56+
};
57+
};
58+
59+
// ============================== Export ==============================
60+
export default genComponentStyleHook('Statistic', token => {
61+
const { fontSizeHeading3, fontSize, fontFamily } = token;
62+
63+
const statisticToken = mergeToken<StatisticToken>(token, {
64+
statisticTitleFontSize: fontSize,
65+
statisticContentFontSize: fontSizeHeading3,
66+
statisticFontFamily: fontFamily,
67+
});
68+
return [genStatisticStyle(statisticToken)];
69+
});

components/statistic/style/rtl.less

-21
This file was deleted.

components/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import './drawer/style';
5353
// import './comment/style';
5454
// import './config-provider/style';
5555
import './empty/style';
56-
import './statistic/style';
56+
// import './statistic/style';
5757
import './result/style';
5858
// import './descriptions/style';
5959
// import './page-header/style';

0 commit comments

Comments
 (0)