Skip to content
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
22 changes: 14 additions & 8 deletions development/src/ant-phone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useFormInstance from "antd/es/form/hooks/useFormInstance";
import {ConfigContext} from "antd/es/config-provider";
import {FormContext} from "antd/es/form/context";
import {useWatch} from "antd/es/form/Form";
import version from "antd/es/version";
import Select from "antd/es/select";
import Input from "antd/es/input";

Expand All @@ -36,9 +37,14 @@ import locale from "./locale";
import {injectMergedStyles} from "./styles";
import {PhoneInputProps, PhoneNumber} from "./types";

const [major, minor, _] = version.split(".").map(Number);
const isV5x = major === 5;
const isV5x25 = isV5x && minor >= 25;

const PhoneInput = forwardRef(({
value: initialValue = "",
country = getDefaultISO2Code(),
useSVG = false,
distinct = false,
disabled = false,
enableArrow = false,
Expand Down Expand Up @@ -221,9 +227,9 @@ const PhoneInput = forwardRef(({
inputRef.current.input.focus();
}}
optionLabelProp="label"
dropdownStyle={{minWidth}}
onDropdownVisibleChange={onDropdownVisibleChange}
dropdownRender={(menu) => (
{...(isV5x ? {onOpenChange: onDropdownVisibleChange} : {onDropdownVisibleChange})}
{...(isV5x25 ? {styles: {popup: {root: {minWidth}}}} : {dropdownStyle: {minWidth}})}
{...({[isV5x ? "popupRender" : "dropdownRender"]: (menu: any) => (
<div className={`${prefixCls}-phone-input-search-wrapper`}>
{enableSearch && (
<Input
Expand All @@ -237,15 +243,15 @@ const PhoneInput = forwardRef(({
<div className="ant-select-item-empty">{searchNotFound}</div>
)}
</div>
)}
)})}
>
<Select.Option
children={null}
value={selectValue}
style={{display: "none"}}
key={`${countryCode}_default`}
label={<div style={{display: "flex"}}>
<div className={`flag ${countryCode}`}/>
<div className={`flag ${countryCode} ${useSVG ? "svg" : ""}`}/>
{suffixIcon}
</div>}
/>
Expand All @@ -256,18 +262,18 @@ const PhoneInput = forwardRef(({
value={iso + dial}
key={`${iso}_${mask}`}
label={<div style={{display: "flex"}}>
<div className={`flag ${iso}`}/>
<div className={`flag ${iso} ${useSVG ? "svg" : ""}`}/>
{suffixIcon}
</div>}
children={<div className={`${prefixCls}-phone-input-select-item`}>
<div className={`flag ${iso}`}/>
<div className={`flag ${iso} ${useSVG ? "svg" : ""}`}/>
{countries[name]}&nbsp;{displayFormat(mask)}
</div>}
/>
)
})}
</Select>
), [selectValue, suffixIcon, countryCode, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder])
), [selectValue, suffixIcon, countryCode, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder, useSVG])

return (
<div className={`${prefixCls}-phone-input-wrapper`}
Expand Down
4 changes: 2 additions & 2 deletions development/src/ant-phone/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import {injectStyles, jsonToCss} from "react-phone-hooks/styles";
import commonStyles from "react-phone-hooks/stylesheet.json";
import {injectStyles, jsonToCss} from "../phone-hooks/styles";
import commonStyles from "../phone-hooks/resources/stylesheet.json";
import {defaultPrefixCls} from "antd/es/config-provider";

import customStyles from "./resources/stylesheet.json";
Expand Down
2 changes: 2 additions & 0 deletions development/src/ant-phone/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type PhoneNumber = types.PhoneNumber;
export interface PhoneInputProps extends Omit<InputProps, "value" | "onChange"> {
value?: PhoneNumber | string;

useSVG?: boolean;

country?: string;

distinct?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion development/src/mui-phone/base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(({slotProps, ...props}, r
const PhoneInput = forwardRef(({
value: initialValue = "",
country = getDefaultISO2Code(),
useSVG = false,
disableParentheses = false,
onlyCountries = [],
excludeCountries = [],
Expand Down Expand Up @@ -138,7 +139,7 @@ const PhoneInput = forwardRef(({
onInput={onInput}
onChange={onChange}
onKeyDown={onKeyDown}
startAdornment={<div className={`flag ${countryCode}`}/>}
startAdornment={<div className={`flag ${countryCode} ${useSVG ? "svg" : ""}`}/>}
{...(muiInputProps as any)}
/>
)
Expand Down
2 changes: 2 additions & 0 deletions development/src/mui-phone/base/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type PhoneNumber = types.PhoneNumber;
export interface PhoneInputProps extends Omit<InputProps, "onChange"> {
value?: PhoneNumber | string;

useSVG?: boolean;

country?: string;

disableParentheses?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions development/src/mui-phone/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(),
useSVG = false,
distinct = false,
disabled = false,
enableArrow = false,
Expand Down Expand Up @@ -181,7 +182,7 @@ const PhoneInput = forwardRef(({
setTimeout(() => input.focus(), 100);
}}
children={<div className="mui-phone-input-select-item">
<div className={`flag ${iso}`}/>
<div className={`flag ${iso} ${useSVG ? "svg" : ""}`}/>
<div className="label">
{countries[name]}&nbsp;{displayFormat(mask)}
</div>
Expand Down Expand Up @@ -214,7 +215,7 @@ const PhoneInput = forwardRef(({
}}
onClick={() => setOpen(!open)}
>
<div className={`flag ${countryCode}`}/>
<div className={`flag ${countryCode} ${useSVG ? "svg" : ""}`}/>
{enableArrow && (
<svg viewBox="0 0 24 24" focusable="false" fill="currentColor"
style={{paddingLeft: 4}} width="22" height="20">
Expand Down
5 changes: 3 additions & 2 deletions development/src/mui-phone/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(),
useSVG = false,
distinct = false,
disabled = false,
enableArrow = false,
Expand Down Expand Up @@ -178,7 +179,7 @@ const PhoneInput = forwardRef(({
setTimeout(() => input.focus(), 100);
}}
children={<div className="mui-phone-input-select-item">
<div className={`flag ${iso}`}/>
<div className={`flag ${iso} ${useSVG ? "svg" : ""}`}/>
<div className="label">
{countries[name]}&nbsp;{displayFormat(mask)}
</div>
Expand Down Expand Up @@ -209,7 +210,7 @@ const PhoneInput = forwardRef(({
}}
onClick={() => setOpen(!open)}
>
<div className={`flag ${countryCode}`}/>
<div className={`flag ${countryCode} ${useSVG ? "svg" : ""}`}/>
{enableArrow && (
<svg viewBox="0 0 24 24" focusable="false" fill="currentColor"
style={{paddingLeft: 4}} width="22" height="20">
Expand Down
2 changes: 2 additions & 0 deletions development/src/mui-phone/joy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type PhoneNumber = types.PhoneNumber;
export interface PhoneInputProps extends Omit<InputProps, "value" | "onChange"> {
value?: PhoneNumber | string;

useSVG?: boolean;

searchVariant?: InputProps["variant"];

country?: string;
Expand Down
4 changes: 2 additions & 2 deletions development/src/mui-phone/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import {injectStyles, jsonToCss} from "react-phone-hooks/styles";
import commonStyles from "react-phone-hooks/stylesheet.json";
import {injectStyles, jsonToCss} from "../phone-hooks/styles";
import commonStyles from "../phone-hooks/resources/stylesheet.json";

import customStyles from "./resources/stylesheet.json";

Expand Down
2 changes: 2 additions & 0 deletions development/src/mui-phone/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type PhoneNumber = types.PhoneNumber;
export interface PhoneInputProps extends Omit<TextFieldProps, "onChange"> {
value?: PhoneNumber | string;

useSVG?: boolean;

searchVariant?: TextFieldProps["variant"];

country?: string;
Expand Down
1,163 changes: 928 additions & 235 deletions development/src/phone-hooks/resources/stylesheet.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.16",
"version": "0.1.17",
"name": "react-phone-hooks",
"description": "React hooks and utility functions for parsing and validating phone numbers.",
"keywords": [
Expand Down
1,163 changes: 928 additions & 235 deletions resources/stylesheet.json

Large diffs are not rendered by default.