🐛 Statistic should support negetive numbers (#14695)

close #14692
This commit is contained in:
偏右 2019-02-02 21:55:46 +08:00 committed by zombieJ
parent 12f6d8ada4
commit 1daec4eacb
3 changed files with 43 additions and 3 deletions

View File

@ -17,14 +17,15 @@ const StatisticNumber: React.SFC<NumberProps> = props => {
} else {
// Internal formatter
const val: string = String(value);
const cells = val.match(/^(\d*)(\.(\d+))?$/);
const cells = val.match(/^(-?)(\d*)(\.(\d+))?$/);
// Process if illegal number
if (!cells) {
valueNode = val;
} else {
let int = cells[1] || '0';
let decimal = cells[3] || '';
const negative = cells[1];
let int = cells[2] || '0';
let decimal = cells[4] || '';
int = int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);
@ -38,6 +39,7 @@ const StatisticNumber: React.SFC<NumberProps> = props => {
valueNode = [
<span key="int" className={`${prefixCls}-content-value-int`}>
{negative}
{int}
</span>,
decimal && (

View File

@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Statistic support negetive number 1`] = `
<div
class="ant-statistic"
>
<div
class="ant-statistic-title"
>
Account Balance (CNY)
</div>
<div
class="ant-statistic-content"
>
<span
class="ant-statistic-content-value"
>
<span
class="ant-statistic-content-value-int"
>
-112,893
</span>
<span
class="ant-statistic-content-value-decimal"
>
.12
</span>
</span>
</div>
</div>
`;

View File

@ -32,6 +32,13 @@ describe('Statistic', () => {
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('bamboo');
});
it('support negetive number', () => {
const wrapper = mount(
<Statistic title="Account Balance (CNY)" value={-112893.12345} precision={2} />,
);
expect(wrapper.render()).toMatchSnapshot();
});
describe('Countdown', () => {
it('render correctly', () => {
const now = moment()