Skip to content

Commit 31c6fe1

Browse files
Implement support for localized querying (GH-20)
2 parents 07d5dd9 + 554781b commit 31c6fe1

9 files changed

+41
-8
lines changed

babel.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/preset-env",
5+
{
6+
targets: {
7+
node: "current",
8+
},
9+
},
10+
],
11+
],
12+
};

jestconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"transform": {
3-
"^.+\\.tsx?$": "ts-jest"
3+
"^.+\\.tsx?$": "ts-jest",
4+
"^.+\\.jsx?$": "babel-jest"
45
},
56
"testRegex": "/tests/.*\\.test\\.(tsx?)$",
7+
"transformIgnorePatterns": [
8+
"/node_modules/(?!(react-phone-hooks)/)"
9+
],
610
"modulePathIgnorePatterns": [
711
"<rootDir>/examples"
812
],

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.3",
2+
"version": "0.1.4",
33
"name": "mui-phone-input",
44
"description": "Advanced, highly customizable phone input component for Material UI.",
55
"keywords": [
@@ -39,7 +39,7 @@
3939
"rename": "bash -c 'for file in *.js; do mv $file \"${file%.js}.$0.js\"; done'",
4040
"build": "tsc --module commonjs && npm run rename -- cjs && tsc --declaration",
4141
"prebuild": "rm -r joy base core resources index* locale* types* styles* || true",
42-
"postpack": "tsx scripts/prepare-package.ts",
42+
"postpack": "tsx scripts/prepare-package.ts && mv babel.config.cjs.js babel.config.js",
4343
"test": "jest --config jestconfig.json",
4444
"postbuild": "cp -r src/resources ."
4545
},
@@ -48,10 +48,13 @@
4848
"react": "^16.8.6 || ^17.0.0 || ^18.0.0"
4949
},
5050
"dependencies": {
51-
"react-phone-hooks": "^0.1.6"
51+
"react-phone-hooks": "^0.1.12"
5252
},
5353
"devDependencies": {
54-
"@emotion/styled": "^11.11.0",
54+
"@babel/core": "^7.26.0",
55+
"@babel/preset-env": "^7.26.0",
56+
"@emotion/styled": "^11.13.0",
57+
"@emotion/react": "^11.13.3",
5558
"@material-ui/core": "^4.0.0",
5659
"@mui/base": "^5.0.0-beta.29",
5760
"@mui/joy": "^5.0.0-beta.18",
@@ -60,8 +63,11 @@
6063
"@testing-library/user-event": "^14.5.1",
6164
"@types/jest": "^29.5.11",
6265
"@types/react": "^17.0.71",
66+
"babel-jest": "^29.7.0",
6367
"jest": "^29.7.0",
6468
"jest-environment-jsdom": "^29.7.0",
69+
"react": "^17.0.0",
70+
"react-dom": "^17.0.0",
6571
"react-hook-form": "^7.49.2",
6672
"ts-jest": "^29.1.1",
6773
"tslib": "^2.6.2",

src/core/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const PhoneInput = forwardRef(({
5454
const [countryCode, setCountryCode] = useState<string>(country);
5555

5656
const {
57+
locale,
5758
searchNotFound = defaultSearchNotFound,
5859
searchPlaceholder = defaultSearchPlaceholder,
5960
countries = new Proxy({}, ({get: (_: any, prop: any) => prop})),
@@ -67,6 +68,7 @@ const PhoneInput = forwardRef(({
6768
countriesList,
6869
} = usePhone({
6970
query,
71+
locale,
7072
country,
7173
countryCode,
7274
initialValue,

src/core/locale.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ type Locale = keyof typeof locale;
66
export default (lang: Locale) => ({
77
props: {
88
...locale[lang].props,
9-
MuiPhoneInput: (phoneLocale as any)[lang],
9+
MuiPhoneInput: {
10+
...(phoneLocale as any)[lang],
11+
locale: lang,
12+
},
1013
}
1114
})

src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const PhoneInput = forwardRef(({
5353
const [countryCode, setCountryCode] = useState<string>(country);
5454

5555
const {
56+
locale,
5657
searchNotFound = defaultSearchNotFound,
5758
searchPlaceholder = defaultSearchPlaceholder,
5859
countries = new Proxy({}, ({get: (_: any, prop: any) => prop})),
@@ -66,6 +67,7 @@ const PhoneInput = forwardRef(({
6667
countriesList,
6768
} = usePhone({
6869
query,
70+
locale,
6971
country,
7072
countryCode,
7173
initialValue,

src/joy/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const PhoneInput = forwardRef(({
5353
const [countryCode, setCountryCode] = useState<string>(country);
5454

5555
const {
56+
locale,
5657
searchNotFound = defaultSearchNotFound,
5758
searchPlaceholder = defaultSearchPlaceholder,
5859
countries = new Proxy({}, ({get: (_: any, prop: any) => prop})),
@@ -66,6 +67,7 @@ const PhoneInput = forwardRef(({
6667
countriesList,
6768
} = usePhone({
6869
query,
70+
locale,
6971
country,
7072
countryCode,
7173
initialValue,

src/locale.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export default (lang: Locale) => ({
77
components: {
88
...locale[lang].components,
99
MuiPhoneInput: {
10-
defaultProps: (phoneLocale as any)[lang],
10+
defaultProps: {
11+
...(phoneLocale as any)[lang],
12+
locale: lang,
13+
},
1114
}
1215
}
1316
})

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"noImplicitAny": true,
44
"noUnusedLocals": true,
55
"noUnusedParameters": true,
6-
"noImplicitUseStrict": true,
76
"strictNullChecks": true,
87
"module": "esnext",
98
"moduleResolution": "node",

0 commit comments

Comments
 (0)