add groupSeparator prop (#14251)

pull/14258/head
zombieJ 6 years ago committed by GitHub
parent 4e54aa8a46
commit 8ef4d72633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,7 +7,7 @@ interface NumberProps extends FormatConfig {
}
const StatisticNumber: React.SFC<NumberProps> = props => {
const { value, formatter, precision, decimalSeparator, prefixCls } = props;
const { value, formatter, precision, decimalSeparator, groupSeparator = '', prefixCls } = props;
let valueNode: React.ReactNode;
@ -26,7 +26,7 @@ const StatisticNumber: React.SFC<NumberProps> = props => {
let int = cells[1] || '0';
let decimal = cells[3] || '';
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
if (typeof precision === 'number') {
decimal = padEnd(decimal, precision, '0').slice(0, precision);

@ -55,6 +55,7 @@ const Statistic: React.SFC<StatisticProps & ConfigConsumerProps> = props => {
Statistic.defaultProps = {
decimalSeparator: '.',
groupSeparator: ',',
};
const WrapperStatistic = withConfigConsumer<StatisticProps>({

@ -22,6 +22,11 @@ describe('Statistic', () => {
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('93');
});
it('groupSeparator', () => {
const wrapper = mount(<Statistic value={1128} groupSeparator="__TEST__" />);
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('1__TEST__128');
});
it('not a number', () => {
const wrapper = mount(<Statistic value="bamboo" />);
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('bamboo');

@ -17,8 +17,9 @@ Display statistic number.
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| decimalSeparator | decimal separator | string | - |
| decimalSeparator | decimal separator | string | . |
| formatter | customize value display logic | (value) => ReactNode | - |
| groupSeparator | group separator | string | , |
| precision | precision of input value | number | - |
| prefix | prefix node of value | string \| ReactNode | - |
| suffix | suffix node of value | string \| ReactNode | - |

@ -18,8 +18,9 @@ title: Statistic
| 参数 | 说明 | 类型 | 默认值 |
| -------- | ----------- | ---- | ------- |
| decimalSeparator | 设置小数点 | string | - |
| decimalSeparator | 设置小数点 | string | . |
| formatter | 自定义数值展示 | (value) => ReactNode | - |
| groupSeparator | 设置千分位标识符 | string | , |
| precision | 数值精度 | number | - |
| prefix | 设置数值的前缀 | string \| ReactNode | - |
| suffix | 设置数值的后缀 | string \| ReactNode | - |

@ -15,6 +15,7 @@ export type Formatter =
export interface FormatConfig {
formatter?: Formatter;
decimalSeparator?: string;
groupSeparator?: string;
precision?: number;
prefixCls?: string;
}

Loading…
Cancel
Save