diff --git a/src/phone-input/phone-input-dialog.tsx b/src/phone-input/phone-input-dialog.tsx index f77302d..f576718 100644 --- a/src/phone-input/phone-input-dialog.tsx +++ b/src/phone-input/phone-input-dialog.tsx @@ -6,7 +6,13 @@ import styles from './phone-input.module.scss'; import { usePhoneInputCountrySelect } from './phone-input-country-select-context'; import { usePhoneInput } from './phone-input-provider'; -export function PhoneInputDialog(props: React.HTMLAttributes) { +export function PhoneInputDialog( + props: Omit, 'children'> & { + children?: + | (({ open }: { open: boolean }) => React.ReactNode) + | React.ReactNode; + } +) { const dialogRef = useRef(null); const { dialogPosition } = usePhoneInput(); const { isDialogOpen, setIsDialogOpen, triggerRef } = @@ -32,7 +38,9 @@ export function PhoneInputDialog(props: React.HTMLAttributes) { ref={dialogRef} style={{ top: dialogPosition.top }} > - {children} + {typeof children === 'function' + ? children({ open: isDialogOpen }) + : children} ); } diff --git a/stories/phone-input.stories.tsx b/stories/phone-input.stories.tsx index f1c6306..f403b0a 100644 --- a/stories/phone-input.stories.tsx +++ b/stories/phone-input.stories.tsx @@ -295,54 +295,61 @@ export function StyledTwo() { -
-
-
- - - + {({ open }) => ( + <> +
+
+
+ + + +
+ {open && ( + setSearch(e.target.value)} + placeholder="Search" + type="text" + value={search} + /> + )} +
- setSearch(e.target.value)} - placeholder="Search" - type="text" - value={search} - /> -
-
-
    - {searchCountryList.map((countryItem) => ( - - - {countryItem.name} - - ))} -
+
    + {searchCountryList.map((countryItem) => ( + + + {countryItem.name} + + ))} +
+ + )}