1
1
"use client" ;
2
2
3
3
import { ChangeEvent , forwardRef , KeyboardEvent , useCallback , useEffect , useMemo , useRef , useState } from "react" ;
4
- import { Input , Option , Select } from "@mui/joy" ;
4
+ import { Input , Option , Select , useThemeProps } from "@mui/joy" ;
5
5
6
6
import {
7
7
checkValidity ,
@@ -16,6 +16,7 @@ import {
16
16
usePhone ,
17
17
} from "../../phone-hooks" ;
18
18
19
+ import locale from "../locale" ;
19
20
import { injectMergedStyles } from "./styles" ;
20
21
import { PhoneInputProps , PhoneNumber } from "./types" ;
21
22
@@ -27,14 +28,15 @@ const PhoneInput = forwardRef(({
27
28
searchVariant = undefined ,
28
29
country = getDefaultISO2Code ( ) ,
29
30
disabled = false ,
31
+ enableArrow = false ,
30
32
enableSearch = false ,
31
33
disableDropdown = false ,
32
34
disableParentheses = false ,
33
35
onlyCountries = [ ] ,
34
36
excludeCountries = [ ] ,
35
37
preferredCountries = [ ] ,
36
- searchNotFound = "No country found" ,
37
- searchPlaceholder = "Search country" ,
38
+ searchNotFound : defaultSearchNotFound = "No country found" ,
39
+ searchPlaceholder : defaultSearchPlaceholder = "Search country" ,
38
40
onMount : handleMount = ( ) => null ,
39
41
onInput : handleInput = ( ) => null ,
40
42
onChange : handleChange = ( ) => null ,
@@ -50,6 +52,12 @@ const PhoneInput = forwardRef(({
50
52
const [ maxWidth , setMaxWidth ] = useState < number > ( 0 ) ;
51
53
const [ countryCode , setCountryCode ] = useState < string > ( country ) ;
52
54
55
+ const {
56
+ searchNotFound = defaultSearchNotFound ,
57
+ searchPlaceholder = defaultSearchPlaceholder ,
58
+ countries = new Proxy ( { } , ( { get : ( _ : any , prop : any ) => prop } ) ) ,
59
+ } = useThemeProps ( { props : { } , name : "MuiPhoneInput" } ) as any ;
60
+
53
61
const {
54
62
value,
55
63
pattern,
@@ -168,7 +176,7 @@ const PhoneInput = forwardRef(({
168
176
children = { < div className = "mui-phone-input-select-item" >
169
177
< div className = { `flag ${ iso } ` } />
170
178
< div className = "label" >
171
- { name } { displayFormat ( mask ) }
179
+ { countries [ name ] } { displayFormat ( mask ) }
172
180
</ div >
173
181
</ div > }
174
182
/>
@@ -189,10 +197,21 @@ const PhoneInput = forwardRef(({
189
197
onKeyDown = { onKeyDown }
190
198
startDecorator = { (
191
199
< span
192
- style = { { cursor : "pointer" } }
200
+ style = { {
201
+ display : "flex" ,
202
+ cursor : "pointer" ,
203
+ alignItems : "center" ,
204
+ justifyContent : "center" ,
205
+ } }
193
206
onClick = { ( ) => setOpen ( ! open ) }
194
207
>
195
208
< div className = { `flag ${ countryCode } ` } />
209
+ { enableArrow && (
210
+ < svg viewBox = "0 0 24 24" focusable = "false" fill = "currentColor"
211
+ style = { { paddingLeft : 4 } } width = "22" height = "20" >
212
+ < path d = "M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z" />
213
+ </ svg >
214
+ ) }
196
215
</ span >
197
216
) }
198
217
{ ...( muiInputProps as any ) }
@@ -202,3 +221,4 @@ const PhoneInput = forwardRef(({
202
221
} )
203
222
204
223
export default PhoneInput ;
224
+ export type { PhoneInputProps , PhoneNumber , locale } ;
0 commit comments