Skip to content

Commit

Permalink
refactor:statistic (#6240)
Browse files Browse the repository at this point in the history
* refactor:statistic

* fix inheritAttrs: false & attrs.class
  • Loading branch information
shifeng1993 authored Feb 8, 2023
1 parent a9fbf98 commit 26f98b7
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 68 deletions.
19 changes: 15 additions & 4 deletions components/statistic/Statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import type { valueType } from './utils';
import Skeleton from '../skeleton/Skeleton';
import useConfigInject from '../config-provider/hooks/useConfigInject';

// CSSINJS
import useStyle from './style';

export const statisticProps = () => ({
prefixCls: String,
decimalSeparator: String,
Expand All @@ -30,14 +33,19 @@ export type StatisticProps = Partial<ExtractPropTypes<ReturnType<typeof statisti
export default defineComponent({
compatConfig: { MODE: 3 },
name: 'AStatistic',
inheritAttrs: false,
props: initDefaultProps(statisticProps(), {
decimalSeparator: '.',
groupSeparator: ',',
loading: false,
}),
slots: ['title', 'prefix', 'suffix', 'formatter'],
setup(props, { slots }) {
setup(props, { slots, attrs }) {
const { prefixCls, direction } = useConfigInject('statistic', props);

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

return () => {
const { value = 0, valueStyle, valueRender } = props;
const pre = prefixCls.value;
Expand All @@ -56,8 +64,11 @@ export default defineComponent({
if (valueRender) {
valueNode = valueRender(valueNode);
}
return (
<div class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }]}>
return wrapSSR(
<div
{...attrs}
class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }, attrs.class, hashId.value]}
>
{title && <div class={`${pre}-title`}>{title}</div>}
<Skeleton paragraph={false} loading={props.loading}>
<div style={valueStyle} class={`${pre}-content`}>
Expand All @@ -66,7 +77,7 @@ export default defineComponent({
{suffix && <span class={`${pre}-content-suffix`}>{suffix}</span>}
</div>
</Skeleton>
</div>
</div>,
);
};
},
Expand Down
40 changes: 0 additions & 40 deletions components/statistic/style/index.less

This file was deleted.

71 changes: 69 additions & 2 deletions components/statistic/style/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,69 @@
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';
import { resetComponent } from '../../_style';

interface StatisticToken extends FullToken<'Statistic'> {
statisticTitleFontSize: number;
statisticContentFontSize: number;
statisticFontFamily: string;
}

const genStatisticStyle: GenerateStyle<StatisticToken> = (token: StatisticToken): CSSObject => {
const {
componentCls,
marginXXS,
padding,
colorTextDescription,
statisticTitleFontSize,
colorTextHeading,
statisticContentFontSize,
statisticFontFamily,
} = token;

return {
[`${componentCls}`]: {
...resetComponent(token),
[`${componentCls}-title`]: {
marginBottom: marginXXS,
color: colorTextDescription,
fontSize: statisticTitleFontSize,
},

[`${componentCls}-skeleton`]: {
paddingTop: padding,
},

[`${componentCls}-content`]: {
color: colorTextHeading,
fontSize: statisticContentFontSize,
fontFamily: statisticFontFamily,
[`${componentCls}-content-value`]: {
display: 'inline-block',
direction: 'ltr',
},
[`${componentCls}-content-prefix, ${componentCls}-content-suffix`]: {
display: 'inline-block',
},
[`${componentCls}-content-prefix`]: {
marginInlineEnd: marginXXS,
},
[`${componentCls}-content-suffix`]: {
marginInlineStart: marginXXS,
},
},
},
};
};

// ============================== Export ==============================
export default genComponentStyleHook('Statistic', token => {
const { fontSizeHeading3, fontSize, fontFamily } = token;

const statisticToken = mergeToken<StatisticToken>(token, {
statisticTitleFontSize: fontSize,
statisticContentFontSize: fontSizeHeading3,
statisticFontFamily: fontFamily,
});
return [genStatisticStyle(statisticToken)];
});
21 changes: 0 additions & 21 deletions components/statistic/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 @@ -53,7 +53,7 @@ import './drawer/style';
// import './comment/style';
// import './config-provider/style';
import './empty/style';
import './statistic/style';
// import './statistic/style';
import './result/style';
// import './descriptions/style';
// import './page-header/style';
Expand Down

0 comments on commit 26f98b7

Please sign in to comment.