feat: add CountryCodeDropdown component with libphonenumber validation#127
Merged
garrity-miepub merged 2 commits intomainfrom Mar 9, 2026
Merged
feat: add CountryCodeDropdown component with libphonenumber validation#127garrity-miepub merged 2 commits intomainfrom
garrity-miepub merged 2 commits intomainfrom
Conversation
Add a new CountryCodeDropdown component for selecting international country codes alongside phone number inputs. The component displays emoji flags and dial codes, with a searchable dropdown list of all supported countries. Features: - Defaults to United States (+1) with the American flag displayed - Searchable dropdown filters by country name, ISO code, or dial code - Country list built dynamically from google-libphonenumber supported regions - Country display names resolved via the browser Intl.DisplayNames API - Supports both controlled (value + onChange) and uncontrolled usage - Keyboard navigation (arrow keys, Escape to close) - Click-outside-to-close behavior - Dark mode support - Full accessibility: listbox role, aria-selected, focusable options Exported utilities: - validatePhoneNumber(phoneNumber, countryCode) - validates via libphonenumber - formatE164(phoneNumber, countryCode) - formats to E.164 international format Dependencies: - Added google-libphonenumber as a runtime dependency - Added @types/google-libphonenumber as a dev dependency Also includes: - Storybook stories (Default, WithPhoneInput, PreselectedCountry, Placements, Disabled, Controlled) - Tree-shaking entry point in tsup.config.ts - Barrel export from src/index.ts
7e187fb to
b07cb37
Compare
Deploying ui with
|
| Latest commit: |
a07978c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1c2b928f.ui-6d0.pages.dev |
| Branch Preview URL: | https://feature-country-code-dropdow.ui-6d0.pages.dev |
There was a problem hiding this comment.
Pull request overview
Adds an international country-code selector and libphonenumber-based phone utilities to the UI library, enabling phone inputs to support multiple regions with a searchable, accessible dropdown.
Changes:
- Introduces
CountryCodeDropdowncomponent with search, keyboard navigation, click-outside/Escape close, and dark mode styling. - Exports
validatePhoneNumberandformatE164helpers backed bygoogle-libphonenumber. - Adds a tree-shakeable tsup entry and updates public exports + dependencies.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tsup.config.ts | Adds tree-shaking entry for the new component. |
| src/index.ts | Exposes the new component from the library root barrel. |
| src/components/CountryCodeDropdown/index.ts | Component-level barrel exports for component + utilities + types. |
| src/components/CountryCodeDropdown/CountryCodeDropdown.tsx | Implements dropdown UI, country list generation, and exported phone helpers. |
| src/components/CountryCodeDropdown/CountryCodeDropdown.stories.tsx | Adds Storybook stories demonstrating usage patterns. |
| package.json | Bumps version and adds google-libphonenumber + typings dependency. |
| pnpm-lock.yaml | Locks the new dependency versions for pnpm installs. |
| package-lock.json | Updates lockfile metadata (but currently missing new dependency entries). |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use runtime locale (navigator.languages) instead of hard-coded 'en' for Intl.DisplayNames, with 'en' fallback for SSR environments - Create lazy singleton for Intl.DisplayNames to avoid constructing a new instance on every regionDisplayName() call during list build - Defer country list construction until the dropdown is first opened, with a lightweight fallback for the selected country display - Derive listbox aria-label from the component's aria-label prop instead of hard-coding "Country codes"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
country-code.mov
Add a new CountryCodeDropdown component for selecting international country codes alongside phone number inputs. The component displays emoji flags and dial codes, with a searchable dropdown list of all supported countries.
Features:
Exported utilities:
Dependencies:
Also includes: