mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
parent
12f6d8ada4
commit
1daec4eacb
@ -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 && (
|
||||
|
@ -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>
|
||||
`;
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user