Просмотр исходного кода

fix: Putting unstable properties on the to-do list

remove: rule=currency
Signed-off-by: uiuing <[email protected]>
uiuing 3 лет назад
Родитель
Сommit
dcc200e5ef

+ 1 - 1
packages/semi-foundation/typography/constants.ts

@@ -9,7 +9,7 @@ const strings = {
     SIZE: ['normal', 'small'],
     SPACING: ['normal', 'extended'],
     HEADING: [1, 2, 3, 4, 5, 6],
-    RULE: ['text', 'numbers', 'bytes-decimal', 'bytes-binary', 'percentages', 'currency', 'exponential'],
+    RULE: ['text', 'numbers', 'bytes-decimal', 'bytes-binary', 'percentages', 'exponential'],
     TRUNCATE: ['ceil', 'floor', 'round'],
 } as const;
 

+ 2 - 7
packages/semi-foundation/typography/formatNumeral.ts

@@ -1,6 +1,7 @@
 import { strings } from './constants';
 
-// rule types: 'text' | 'numbers' | 'bytes-decimal' | 'bytes-binary' | 'percentages' | 'currency' | 'exponential'
+// rule types: 'text' | 'numbers' | 'bytes-decimal' | 'bytes-binary' | 'percentages' | 'exponential'
+// TODO: Refining the 'currency' type
 type Rule = typeof strings.RULE[number];
 type Truncate = typeof strings.TRUNCATE[number];
 type Parser = (value: string) => string;
@@ -47,12 +48,6 @@ export default class FormatNumeral {
             }
             return `${this.truncatePrecision(value)}%`;
         },
-        currency: (value: number) => {
-            const cArr = this.truncatePrecision(value).split('.');
-            const cInt = cArr[0].replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
-            const cFloat = cArr[1] ? `.${cArr[1]}` : '';
-            return `${cInt}${cFloat}`;
-        },
         exponential: (value: number) => {
             const vExponential = value.toExponential(this.precision + 2);
             const vArr = vExponential.split('e');

+ 7 - 9
packages/semi-ui/typography/__test__/typography.test.js

@@ -94,19 +94,17 @@ describe(`Typography`, () => {
         );
         expect(numeral.find('.price').text()).toEqual('1.56-1.00,0.56');
         numeral = mount(
-            <Typography.Numeral rule={'currency'} truncate={'round'} precision={1}>
+            <Typography.Numeral rule={'exponential'} truncate={'floor'} precision={2}>
                 <div className="price">
                     Total revenue: <b>$ 1992.15</b>
                 </div>
             </Typography.Numeral>
-        );
-        expect(numeral.find('.price').text()).toEqual('Total revenue: $ 1,992.2');
-        numeral.setProps({ rule: 'exponential', truncate: 'floor', precision: 2 });
-        expect(numeral.find('.price').text()).toEqual('Total revenue: $ 1.99e+3');
+        )
+        expect(numeral.find('.price').text()).toEqual('Total revenue: $ 1.99e+3')
         // test: parser
         numeral.setProps({
-            parser: oldVal => oldVal.replace(/[^\d.]/g, ''),
-        });
-        expect(numeral.find('.price').text()).toEqual('1992.15');
-    });
+            parser: oldVal => oldVal.replace(/[^\d.]/g, '')
+        })
+        expect(numeral.find('.price').text()).toEqual('1992.15')
+    })
 });