Skip to content

Implement a distinct option for the countries list #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Apart from the phone-specific properties described below, all [Input](https://mu
|--------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| value | An object containing a parsed phone number or the raw number. | [object](#value) / string |
| country | Country code to be selected by default. By default, it will show the flag of the user's country. | string |
| distinct | Show the distinct list of country codes not listing all area codes. | boolean |
| enableArrow | Shows an arrow next to the country flag. Default value is `false`. | boolean |
| enableSearch | Enables search in the country selection dropdown menu. Default value is `false`. | boolean |
| searchVariant | Accepts an Input variant, and values depend on the chosen Material distribution. | TextFieldVariants |
Expand Down
2 changes: 1 addition & 1 deletion examples/material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"copy-to-clipboard": "^3.3.3",
"mui-phone-input": "^0.1.3",
"mui-phone-input": "^0.1.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.4",
Expand Down
42 changes: 28 additions & 14 deletions examples/material/src/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Demo = () => {
const [copied, setCopied] = useState<boolean>(false);
const [preview, setPreview] = useState<boolean>(false);
const [dropdown, setDropdown] = useState<boolean>(true);
const [distinct, setDistinct] = useState<boolean>(false);
const [disabled, setDisabled] = useState<boolean>(false);
const [parentheses, setParentheses] = useState(true);

Expand All @@ -50,6 +51,7 @@ const Demo = () => {

const code = useMemo(() => {
let code = "<PhoneInput\n";
if (distinct) code += " distinct\n";
if (disabled) code += " disabled\n";
if (arrow) code += " enableArrow\n";
if (search && dropdown) code += " enableSearch\n";
Expand All @@ -58,7 +60,7 @@ const Demo = () => {
if (code === "<PhoneInput\n") code = "<PhoneInput />";
else code += "/>";
return code;
}, [disabled, arrow, search, dropdown, parentheses])
}, [distinct, disabled, arrow, search, dropdown, parentheses])

return (
<ThemeProvider theme={theme}>
Expand All @@ -85,53 +87,64 @@ const Demo = () => {
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={changeTheme}
onChange={() => setDropdown(!dropdown)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Theme"
label="Dropdown"
/>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={() => setStrict(!strict)}
onChange={() => setParentheses(!parentheses)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Validation"
defaultChecked
label="Parentheses"
/>
</div>
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
<FormControlLabel
control={<Switch
color="primary"
onChange={() => setDisabled(!disabled)}
onChange={changeTheme}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Disabled"
label="Theme"
/>
<FormControlLabel
control={<Switch
color="primary"
onChange={() => setStrict(!strict)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Validation"
defaultChecked
/>
</div>
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={() => setDropdown(!dropdown)}
onChange={() => setDisabled(!disabled)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Dropdown"
label="Disabled"
/>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={() => setParentheses(!parentheses)}
onChange={() => setDistinct(!distinct)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Parentheses"
label="Distinct"
/>
</div>
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
Expand Down Expand Up @@ -183,6 +196,7 @@ const Demo = () => {
<PhoneInput
{...phoneProps}
error={error}
distinct={distinct}
disabled={disabled}
onChange={onChange}
enableArrow={arrow}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.4",
"version": "0.1.5",
"name": "mui-phone-input",
"description": "Advanced, highly customizable phone input component for Material UI.",
"keywords": [
Expand Down Expand Up @@ -48,7 +48,7 @@
"react": "^16.8.6 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"react-phone-hooks": "^0.1.12"
"react-phone-hooks": "^0.1.14"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const PhoneInput = forwardRef(({
variant = undefined,
searchVariant = undefined,
country = getDefaultISO2Code(),
distinct = false,
disabled = false,
enableArrow = false,
enableSearch = false,
Expand Down Expand Up @@ -70,6 +71,7 @@ const PhoneInput = forwardRef(({
query,
locale,
country,
distinct,
countryCode,
initialValue,
onlyCountries,
Expand Down
2 changes: 2 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface PhoneInputProps extends Omit<TextFieldProps, "onChange"> {

country?: string;

distinct?: boolean;

enableArrow?: boolean;

enableSearch?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const PhoneInput = forwardRef(({
variant = undefined,
searchVariant = undefined,
country = getDefaultISO2Code(),
distinct = false,
disabled = false,
enableArrow = false,
enableSearch = false,
Expand Down Expand Up @@ -69,6 +70,7 @@ const PhoneInput = forwardRef(({
query,
locale,
country,
distinct,
countryCode,
initialValue,
onlyCountries,
Expand Down
2 changes: 2 additions & 0 deletions src/joy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const PhoneInput = forwardRef(({
variant = undefined,
searchVariant = undefined,
country = getDefaultISO2Code(),
distinct = false,
disabled = false,
enableArrow = false,
enableSearch = false,
Expand Down Expand Up @@ -69,6 +70,7 @@ const PhoneInput = forwardRef(({
query,
locale,
country,
distinct,
countryCode,
initialValue,
onlyCountries,
Expand Down
2 changes: 2 additions & 0 deletions src/joy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface PhoneInputProps extends Omit<InputProps, "value" | "onChange">

country?: string;

distinct?: boolean;

enableArrow?: boolean;

enableSearch?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface PhoneInputProps extends Omit<TextFieldProps, "onChange"> {

country?: string;

distinct?: boolean;

enableArrow?: boolean;

enableSearch?: boolean;
Expand Down