File tree Expand file tree Collapse file tree 3 files changed +14
-15
lines changed Expand file tree Collapse file tree 3 files changed +14
-15
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,7 @@ export type CurrencyInputOnChangeValues = {
32
32
33
33
export type IntlConfig = {
34
34
locale : string ;
35
- currency ?: string ;
36
- } ;
35
+ } & Intl . NumberFormatOptions ;
37
36
38
37
export type CurrencyInputProps = Overwrite <
39
38
React . ComponentPropsWithRef < 'input' > ,
@@ -189,6 +188,6 @@ export type CurrencyInputProps = Overwrite<
189
188
* specifically on blur events. If disabled or set to false, the onValueChange will not trigger on blur.
190
189
* Default = true
191
190
*/
192
- formatValueOnBlur ?: boolean ;
191
+ formatValueOnBlur ?: boolean ;
193
192
}
194
193
> ;
Original file line number Diff line number Diff line change @@ -88,22 +88,19 @@ export const formatValue = (options: FormatValueOptions): string => {
88
88
value = '0' + value ;
89
89
}
90
90
91
+ const { locale, currency, ...formatOptions } = intlConfig || { } ;
92
+
91
93
const defaultNumberFormatOptions = {
94
+ ...formatOptions ,
92
95
minimumFractionDigits : decimalScale || 0 ,
93
96
maximumFractionDigits : 20 ,
94
97
} ;
95
98
96
99
const numberFormatter = intlConfig
97
- ? new Intl . NumberFormat (
98
- intlConfig . locale ,
99
- intlConfig . currency
100
- ? {
101
- ...defaultNumberFormatOptions ,
102
- style : 'currency' ,
103
- currency : intlConfig . currency ,
104
- }
105
- : defaultNumberFormatOptions
106
- )
100
+ ? new Intl . NumberFormat ( locale , {
101
+ ...defaultNumberFormatOptions ,
102
+ ...( currency && { style : 'currency' , currency } ) ,
103
+ } )
107
104
: new Intl . NumberFormat ( undefined , defaultNumberFormatOptions ) ;
108
105
109
106
const parts = numberFormatter . formatToParts ( Number ( value ) ) ;
Original file line number Diff line number Diff line change @@ -20,9 +20,12 @@ const defaultConfig: LocaleConfig = {
20
20
* Get locale config from input or default
21
21
*/
22
22
export const getLocaleConfig = ( intlConfig ?: IntlConfig ) : LocaleConfig => {
23
- const { locale, currency } = intlConfig || { } ;
23
+ const { locale, currency, ... formatOptions } = intlConfig || { } ;
24
24
const numberFormatter = locale
25
- ? new Intl . NumberFormat ( locale , currency ? { currency, style : 'currency' } : undefined )
25
+ ? new Intl . NumberFormat ( locale , {
26
+ ...formatOptions ,
27
+ ...( currency && { currency, style : 'currency' } ) ,
28
+ } )
26
29
: new Intl . NumberFormat ( ) ;
27
30
28
31
return numberFormatter . formatToParts ( 1000.1 ) . reduce ( ( prev , curr , i ) : LocaleConfig => {
You can’t perform that action at this time.
0 commit comments