Skip to content

Commit 050aeb2

Browse files
committed
feat: implement callingCodeEditable prop
1 parent 338fbf4 commit 050aeb2

6 files changed

Lines changed: 10 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
- 🌍 International phone number input with country picker
1212
- 📱 Automatic phone number formatting based on country
13+
- 🔍 Dynamic country and mask adaptation based on typed country code
1314
- ✨ Highly customizable appearance and styling
1415
- 🎯 Phone number validation using Google's libphonenumber
15-
- 📦 Easy integration with React Native projects
16-
- 🔍 Country search functionality
1716
- 🎨 Dark theme support
1817
- ♿ Accessibility support
1918
- 💪 Written in TypeScript
2019

2120
## TODO
2221

23-
- [ ] Add unit tests
22+
- [ ] Fix defaultProp issue with picker library
23+
- [ ] Make similar UI with OTP lib
2424
- [ ] Add Error state
2525
- [ ] Make fully customizable
2626

example/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function App() {
77
<PhoneInput
88
onChangeCountry={(country) => console.log('country changed:', country)}
99
onChangeText={(text) => console.log('text changed:', text)}
10+
callingCodeEditable={false}
1011
theme={{
1112
withShadow: true,
1213
}}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"scripts": {
4040
"example": "yarn workspace react-native-phone-entry-example",
4141
"test": "jest",
42+
"test:watch": "jest --watch",
4243
"test:coverage": "jest --collectCoverage --coverageDirectory=\"./coverage\"",
4344
"typecheck": "tsc",
4445
"lint": "eslint \"**/*.{js,ts,tsx}\"",

src/PhoneInput/PhoneInput.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type PhoneInputProps = {
2626
maskInputProps?: MaskInputProps;
2727
countryPickerProps?: Parameters<typeof CountryPicker>[0];
2828
flagProps?: Parameters<typeof Flag>[0];
29+
callingCodeEditable?: boolean;
2930
};
3031
interface Theme {
3132
containerStyle?: StyleProp<ViewStyle>;

src/PhoneInput/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const styles = StyleSheet.create({
1919
height: hp(7),
2020
minHeight: 56,
2121
borderWidth: 1,
22-
borderColor: '#E5E7EB',
22+
borderColor: '#DFDFDE',
2323
},
2424
flagButtonView: {
2525
width: '25%',

src/PhoneInput/usePhoneInput.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const usePhoneInput = ({
1515
value,
1616
onChangeCountry,
1717
onChangeText,
18+
callingCodeEditable = true,
1819
}: PhoneInputProps) => {
1920
const inputRef = useRef<TextInput | null>();
2021
const [callingCode, setCallingCode] = useState<CallingCode>(
@@ -58,11 +59,12 @@ export const usePhoneInput = ({
5859
const handleChangeText = useCallback(
5960
(_masked: string, unmasked: string, _obfuscated: string) => {
6061
const text = ensurePlusPrefix(unmasked);
62+
if (!callingCodeEditable && text.length < callingCode.length) return;
6163
updateCountryOnType(text);
6264
setPhoneNumber(text);
6365
onChangeText?.(text);
6466
},
65-
[updateCountryOnType, onChangeText]
67+
[callingCodeEditable, callingCode.length, updateCountryOnType, onChangeText]
6668
);
6769

6870
return {

0 commit comments

Comments
 (0)