refactor:statistic (#6240)
* refactor:statistic * fix inheritAttrs: false & attrs.classpull/6245/head
parent
a9fbf98f0e
commit
26f98b7b10
|
@ -7,6 +7,9 @@ import type { valueType } from './utils';
|
||||||
import Skeleton from '../skeleton/Skeleton';
|
import Skeleton from '../skeleton/Skeleton';
|
||||||
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
||||||
|
|
||||||
|
// CSSINJS
|
||||||
|
import useStyle from './style';
|
||||||
|
|
||||||
export const statisticProps = () => ({
|
export const statisticProps = () => ({
|
||||||
prefixCls: String,
|
prefixCls: String,
|
||||||
decimalSeparator: String,
|
decimalSeparator: String,
|
||||||
|
@ -30,14 +33,19 @@ export type StatisticProps = Partial<ExtractPropTypes<ReturnType<typeof statisti
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
compatConfig: { MODE: 3 },
|
compatConfig: { MODE: 3 },
|
||||||
name: 'AStatistic',
|
name: 'AStatistic',
|
||||||
|
inheritAttrs: false,
|
||||||
props: initDefaultProps(statisticProps(), {
|
props: initDefaultProps(statisticProps(), {
|
||||||
decimalSeparator: '.',
|
decimalSeparator: '.',
|
||||||
groupSeparator: ',',
|
groupSeparator: ',',
|
||||||
loading: false,
|
loading: false,
|
||||||
}),
|
}),
|
||||||
slots: ['title', 'prefix', 'suffix', 'formatter'],
|
slots: ['title', 'prefix', 'suffix', 'formatter'],
|
||||||
setup(props, { slots }) {
|
setup(props, { slots, attrs }) {
|
||||||
const { prefixCls, direction } = useConfigInject('statistic', props);
|
const { prefixCls, direction } = useConfigInject('statistic', props);
|
||||||
|
|
||||||
|
// Style
|
||||||
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const { value = 0, valueStyle, valueRender } = props;
|
const { value = 0, valueStyle, valueRender } = props;
|
||||||
const pre = prefixCls.value;
|
const pre = prefixCls.value;
|
||||||
|
@ -56,8 +64,11 @@ export default defineComponent({
|
||||||
if (valueRender) {
|
if (valueRender) {
|
||||||
valueNode = valueRender(valueNode);
|
valueNode = valueRender(valueNode);
|
||||||
}
|
}
|
||||||
return (
|
return wrapSSR(
|
||||||
<div class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }]}>
|
<div
|
||||||
|
{...attrs}
|
||||||
|
class={[pre, { [`${pre}-rtl`]: direction.value === 'rtl' }, attrs.class, hashId.value]}
|
||||||
|
>
|
||||||
{title && <div class={`${pre}-title`}>{title}</div>}
|
{title && <div class={`${pre}-title`}>{title}</div>}
|
||||||
<Skeleton paragraph={false} loading={props.loading}>
|
<Skeleton paragraph={false} loading={props.loading}>
|
||||||
<div style={valueStyle} class={`${pre}-content`}>
|
<div style={valueStyle} class={`${pre}-content`}>
|
||||||
|
@ -66,7 +77,7 @@ export default defineComponent({
|
||||||
{suffix && <span class={`${pre}-content-suffix`}>{suffix}</span>}
|
{suffix && <span class={`${pre}-content-suffix`}>{suffix}</span>}
|
||||||
</div>
|
</div>
|
||||||
</Skeleton>
|
</Skeleton>
|
||||||
</div>
|
</div>,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
@import '../../style/themes/index';
|
|
||||||
@import '../../style/mixins/index';
|
|
||||||
|
|
||||||
@statistic-prefix-cls: ~'@{ant-prefix}-statistic';
|
|
||||||
|
|
||||||
.@{statistic-prefix-cls} {
|
|
||||||
.reset-component();
|
|
||||||
|
|
||||||
&-title {
|
|
||||||
margin-bottom: @margin-xss;
|
|
||||||
color: @text-color-secondary;
|
|
||||||
font-size: @statistic-title-font-size;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-content {
|
|
||||||
color: @heading-color;
|
|
||||||
font-size: @statistic-content-font-size;
|
|
||||||
font-family: @statistic-font-family;
|
|
||||||
|
|
||||||
&-value {
|
|
||||||
display: inline-block;
|
|
||||||
direction: ltr;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-prefix,
|
|
||||||
&-suffix {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-prefix {
|
|
||||||
margin-right: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-suffix {
|
|
||||||
margin-left: 4px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@import './rtl';
|
|
|
@ -1,2 +1,69 @@
|
||||||
import '../../style/index.less';
|
import type { CSSObject } from '../../_util/cssinjs';
|
||||||
import './index.less';
|
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)];
|
||||||
|
});
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
.@{statistic-prefix-cls} {
|
|
||||||
&-rtl {
|
|
||||||
direction: rtl;
|
|
||||||
}
|
|
||||||
|
|
||||||
&-content {
|
|
||||||
&-prefix {
|
|
||||||
.@{statistic-prefix-cls}-rtl & {
|
|
||||||
margin-right: 0;
|
|
||||||
margin-left: 4px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&-suffix {
|
|
||||||
.@{statistic-prefix-cls}-rtl & {
|
|
||||||
margin-right: 4px;
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -53,7 +53,7 @@ import './drawer/style';
|
||||||
// import './comment/style';
|
// import './comment/style';
|
||||||
// import './config-provider/style';
|
// import './config-provider/style';
|
||||||
import './empty/style';
|
import './empty/style';
|
||||||
import './statistic/style';
|
// import './statistic/style';
|
||||||
import './result/style';
|
import './result/style';
|
||||||
// import './descriptions/style';
|
// import './descriptions/style';
|
||||||
// import './page-header/style';
|
// import './page-header/style';
|
||||||
|
|
Loading…
Reference in New Issue