@@ -16,150 +16,6 @@ import {NumberFieldProps} from '@react-types/numberfield';
16
16
import { NumberFormatter , NumberParser } from '@internationalized/number' ;
17
17
import { useCallback , useMemo , useState } from 'react' ;
18
18
19
-
20
- let supportedLocales = new Map < string , { groupSeparator : string , decimalSeparator : string } > ( [
21
- [
22
- 'ar-AE' , // Arabic (United Arab Emirates)
23
- { groupSeparator : ',' , decimalSeparator : '.' }
24
- ] ,
25
- [
26
- 'bg-BG' , // Bulgarian (Bulgaria)
27
- { groupSeparator : '' , decimalSeparator : ',' }
28
- ] ,
29
- [
30
- 'zh-CN' , // Chinese (Simplified)
31
- { groupSeparator : ',' , decimalSeparator : '.' }
32
- ] ,
33
- [
34
- 'zh-TW' , // Chinese (Traditional)
35
- { groupSeparator : ',' , decimalSeparator : '.' }
36
- ] ,
37
- [
38
- 'hr-HR' , // Croatian (Croatia)
39
- { groupSeparator : '.' , decimalSeparator : ',' }
40
- ] ,
41
- [
42
- 'cs-CZ' , // Czech (Czech Republic)
43
- { groupSeparator : ' ' , decimalSeparator : ',' }
44
- ] ,
45
- [
46
- 'da-DK' , // Danish (Denmark)
47
- { groupSeparator : '.' , decimalSeparator : ',' }
48
- ] ,
49
- [
50
- 'nl-NL' , // Dutch (Netherlands)
51
- { groupSeparator : '.' , decimalSeparator : ',' }
52
- ] ,
53
- [
54
- 'en-GB' , // English (Great Britain)
55
- { groupSeparator : ',' , decimalSeparator : '.' }
56
- ] ,
57
- [
58
- 'en-US' , // English (United States)
59
- { groupSeparator : ',' , decimalSeparator : '.' }
60
- ] ,
61
- [
62
- 'et-EE' , // Estonian (Estonia)
63
- { groupSeparator : '' , decimalSeparator : ',' }
64
- ] ,
65
- [
66
- 'fi-FI' , // Finnish (Finland)
67
- { groupSeparator : ' ' , decimalSeparator : ',' }
68
- ] ,
69
- [
70
- 'fr-CA' , // French (Canada)
71
- { groupSeparator : ' ' , decimalSeparator : ',' }
72
- ] ,
73
- [
74
- 'fr-FR' , // French (France)
75
- { groupSeparator : ' ' , decimalSeparator : ',' }
76
- ] ,
77
- [
78
- 'de-DE' , // German (Germany)
79
- { groupSeparator : '.' , decimalSeparator : ',' }
80
- ] ,
81
- [
82
- 'el-GR' , // Greek (Greece)
83
- { groupSeparator : '.' , decimalSeparator : ',' }
84
- ] ,
85
- [
86
- 'he-IL' , // Hebrew (Israel)
87
- { groupSeparator : ',' , decimalSeparator : '.' }
88
- ] ,
89
- [
90
- 'hu-HU' , // Hungarian (Hungary)
91
- { groupSeparator : ' ' , decimalSeparator : ',' }
92
- ] ,
93
- [
94
- 'it-IT' , // Italian (Italy)
95
- { groupSeparator : '.' , decimalSeparator : ',' }
96
- ] ,
97
- [
98
- 'ja-JP' , // Japanese (Japan)
99
- { groupSeparator : ',' , decimalSeparator : '.' }
100
- ] ,
101
- [
102
- 'ko-KR' , // Korean (Korea)
103
- { groupSeparator : ',' , decimalSeparator : '.' }
104
- ] ,
105
- [
106
- 'lv-LV' , // Latvian (Latvia)
107
- { groupSeparator : '' , decimalSeparator : ',' }
108
- ] ,
109
- [
110
- 'lt-LT' , // Lithuanian (Lithuania)
111
- { groupSeparator : ' ' , decimalSeparator : ',' }
112
- ] ,
113
- [
114
- 'no-NO' , // Norwegian (Norway)
115
- { groupSeparator : ' ' , decimalSeparator : ',' }
116
- ] ,
117
- [
118
- 'pl-PL' , // Polish (Poland)
119
- { groupSeparator : '' , decimalSeparator : ',' }
120
- ] ,
121
- [
122
- 'pt-BR' , // Portuguese (Brazil)
123
- { groupSeparator : '.' , decimalSeparator : ',' }
124
- ] ,
125
- [
126
- 'ro-RO' , // Romanian (Romania)
127
- { groupSeparator : '.' , decimalSeparator : ',' }
128
- ] ,
129
- [
130
- 'ru-RU' , // Russian (Russia)
131
- { groupSeparator : ' ' , decimalSeparator : ',' }
132
- ] ,
133
- [
134
- 'sr-RS' , // Serbian (Serbia)
135
- { groupSeparator : '.' , decimalSeparator : ',' }
136
- ] ,
137
- [
138
- 'sk-SK' , // Slovakian (Slovakia)
139
- { groupSeparator : ' ' , decimalSeparator : ',' }
140
- ] ,
141
- [
142
- 'sl-SI' , // Slovenian (Slovenia)
143
- { groupSeparator : '.' , decimalSeparator : ',' }
144
- ] ,
145
- [
146
- 'es-ES' , // Spanish (Spain)
147
- { groupSeparator : '' , decimalSeparator : ',' }
148
- ] ,
149
- [
150
- 'sv-SE' , // Swedish (Sweden)
151
- { groupSeparator : ' ' , decimalSeparator : ',' }
152
- ] ,
153
- [
154
- 'tr-TR' , // Turkish (Turkey)
155
- { groupSeparator : '.' , decimalSeparator : ',' }
156
- ] ,
157
- [
158
- 'uk-UA' , // Ukrainian (Ukraine)
159
- { groupSeparator : ' ' , decimalSeparator : ',' }
160
- ]
161
- ] ) ;
162
-
163
19
export interface NumberFieldState extends FormValidationState {
164
20
/**
165
21
* The current text value of the input. Updated as the user types,
@@ -410,41 +266,7 @@ export function useNumberFieldState(
410
266
411
267
let validate = ( value : string ) => numberParser . isValidPartialNumber ( value , minValue , maxValue ) ;
412
268
413
- let parseValueInAnySupportedLocale = ( value : string ) => {
414
- let currentLocaleCode = [ ...supportedLocales ] . find ( ( [ localeCode ] ) => localeCode === locale ) || [ 'en-US' , { groupSeparator : ',' , decimalSeparator : '.' } ] ;
415
- let localesWithDifferentSeparators = [ ...supportedLocales ] . filter ( ( [ , separators ] ) => separators . groupSeparator !== currentLocaleCode ?. [ 1 ] . groupSeparator && separators . decimalSeparator !== currentLocaleCode ?. [ 1 ] . decimalSeparator ) ;
416
- let locales = new Map (
417
- [
418
- currentLocaleCode ,
419
- ...localesWithDifferentSeparators
420
- ]
421
- ) ;
422
-
423
- let _parsedValue = NaN ;
424
- for ( let [ localeCode , separators ] of locales ) {
425
- let _numberParser = new NumberParser ( localeCode , formatOptions ) ;
426
- if (
427
- (
428
- value . includes ( separators . groupSeparator ) ||
429
- value . includes ( separators . decimalSeparator )
430
- ) &&
431
- value . lastIndexOf ( separators . groupSeparator ) > value . lastIndexOf ( separators . decimalSeparator )
432
- ) {
433
- if ( value . lastIndexOf ( separators . decimalSeparator ) === - 1 ) {
434
- let pv = _numberParser . parse ( value . replaceAll ( separators . groupSeparator , '' ) ) ;
435
- if ( ! isNaN ( pv ) && parseFloat ( value . replaceAll ( separators . groupSeparator , '' ) ) === pv ) {
436
- return pv ;
437
- }
438
- }
439
- continue ;
440
- }
441
- _parsedValue = _numberParser . parse ( value . replaceAll ( separators . groupSeparator , '' ) ) ;
442
- if ( ! isNaN ( _parsedValue ) ) {
443
- return _parsedValue ;
444
- }
445
- }
446
- return _parsedValue ;
447
- } ;
269
+ let parseValueInAnySupportedLocale = ( value : string ) => numberParser . parse ( value ) ;
448
270
449
271
return {
450
272
...validation ,
0 commit comments