Skip to content
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

Implement an enableArrow option #19

Merged
merged 3 commits into from
Jul 2, 2024
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 |
| 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 |
| searchNotFound | The value is shown if `enableSearch` is `true` and the query does not match any country. Default value is `No country found`. | string |
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.2",
"mui-phone-input": "^0.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.4",
Expand Down
32 changes: 23 additions & 9 deletions examples/material/src/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Demo = () => {
const [value, setValue] = useState<any>(null);
const [mode, setMode] = useState<string>("light");
const [show, setShow] = useState<boolean>(true);
const [arrow, setArrow] = useState<boolean>(false);
const [strict, setStrict] = useState<boolean>(false);
const [search, setSearch] = useState<boolean>(false);
const [copied, setCopied] = useState<boolean>(false);
Expand Down Expand Up @@ -50,13 +51,14 @@ const Demo = () => {
const code = useMemo(() => {
let code = "<PhoneInput\n";
if (disabled) code += " disabled\n";
if (arrow) code += " enableArrow\n";
if (search && dropdown) code += " enableSearch\n";
if (!dropdown) code += " disableDropdown\n";
if (!parentheses) code += " disableParentheses\n";
if (code === "<PhoneInput\n") code = "<PhoneInput />";
else code += "/>";
return code;
}, [disabled, search, dropdown, parentheses])
}, [disabled, arrow, search, dropdown, parentheses])

return (
<ThemeProvider theme={theme}>
Expand Down Expand Up @@ -113,33 +115,44 @@ const Demo = () => {
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
disabled={!dropdown}
onChange={() => setSearch(!search)}
onChange={() => setDropdown(!dropdown)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Search"
label="Dropdown"
/>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={() => setDropdown(!dropdown)}
onChange={() => setParentheses(!parentheses)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Dropdown"
label="Parentheses"
/>
</div>
<div style={{gap: 24, display: "flex", alignItems: "center"}}>
<FormControlLabel
control={<Switch
defaultChecked
color="primary"
onChange={() => setParentheses(!parentheses)}
disabled={!dropdown}
onChange={() => setSearch(!search)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Parentheses"
label="Search"
/>
<FormControlLabel
control={<Switch
color="primary"
onChange={() => setArrow(!arrow)}
/>}
labelPlacement="start"
style={{margin: 0}}
label="Arrow"
/>
</div>
<Divider textAlign="left" style={{margin: "16px 0"}}>Code</Divider>
Expand Down Expand Up @@ -172,6 +185,7 @@ const Demo = () => {
error={error}
disabled={disabled}
onChange={onChange}
enableArrow={arrow}
enableSearch={search}
style={{width: "100%"}}
disableDropdown={!dropdown}
Expand Down
14 changes: 13 additions & 1 deletion src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const PhoneInput = forwardRef(({
searchVariant = undefined,
country = getDefaultISO2Code(),
disabled = false,
enableArrow = false,
enableSearch = false,
disableDropdown = false,
disableParentheses = false,
Expand Down Expand Up @@ -206,10 +207,21 @@ const PhoneInput = forwardRef(({
startAdornment: (
<InputAdornment position="start">
<span
style={{cursor: "pointer"}}
style={{
display: "flex",
cursor: "pointer",
alignItems: "center",
justifyContent: "center",
}}
onClick={() => setOpen(!open)}
>
<div className={`flag ${countryCode}`}/>
{enableArrow && (
<svg viewBox="0 0 24 24" focusable="false" fill="currentColor"
style={{paddingLeft: 4}} width="22" height="20">
<path d="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"/>
</svg>
)}
</span>
</InputAdornment>
)
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;

enableArrow?: boolean;

enableSearch?: boolean;

searchNotFound?: string;
Expand Down
14 changes: 13 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const PhoneInput = forwardRef(({
searchVariant = undefined,
country = getDefaultISO2Code(),
disabled = false,
enableArrow = false,
enableSearch = false,
disableDropdown = false,
disableParentheses = false,
Expand Down Expand Up @@ -201,10 +202,21 @@ const PhoneInput = forwardRef(({
startAdornment: (
<InputAdornment position="start">
<span
style={{cursor: "pointer"}}
style={{
display: "flex",
cursor: "pointer",
alignItems: "center",
justifyContent: "center",
}}
onClick={() => setOpen(!open)}
>
<div className={`flag ${countryCode}`}/>
{enableArrow && (
<svg viewBox="0 0 24 24" focusable="false" fill="currentColor"
style={{paddingLeft: 4}} width="22" height="20">
<path d="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"/>
</svg>
)}
</span>
</InputAdornment>
)
Expand Down
14 changes: 13 additions & 1 deletion src/joy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const PhoneInput = forwardRef(({
searchVariant = undefined,
country = getDefaultISO2Code(),
disabled = false,
enableArrow = false,
enableSearch = false,
disableDropdown = false,
disableParentheses = false,
Expand Down Expand Up @@ -196,10 +197,21 @@ const PhoneInput = forwardRef(({
onKeyDown={onKeyDown}
startDecorator={(
<span
style={{cursor: "pointer"}}
style={{
display: "flex",
cursor: "pointer",
alignItems: "center",
justifyContent: "center",
}}
onClick={() => setOpen(!open)}
>
<div className={`flag ${countryCode}`}/>
{enableArrow && (
<svg viewBox="0 0 24 24" focusable="false" fill="currentColor"
style={{paddingLeft: 4}} width="22" height="20">
<path d="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"/>
</svg>
)}
</span>
)}
{...(muiInputProps as any)}
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;

enableArrow?: boolean;

enableSearch?: boolean;

searchNotFound?: string;
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;

enableArrow?: boolean;

enableSearch?: boolean;

searchNotFound?: string;
Expand Down
Loading