Skip to content

feat: add CountryCodeDropdown component with libphonenumber validation#127

Merged
garrity-miepub merged 2 commits intomainfrom
feature/country-code-dropdown
Mar 9, 2026
Merged

feat: add CountryCodeDropdown component with libphonenumber validation#127
garrity-miepub merged 2 commits intomainfrom
feature/country-code-dropdown

Conversation

@garrity-miepub
Copy link
Copy Markdown
Contributor

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:

  • 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

Copilot AI review requested due to automatic review settings March 9, 2026 19:56
@garrity-miepub garrity-miepub marked this pull request as ready for review March 9, 2026 19:56
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
@garrity-miepub garrity-miepub force-pushed the feature/country-code-dropdown branch from 7e187fb to b07cb37 Compare March 9, 2026 19:59
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 9, 2026

Deploying ui with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CountryCodeDropdown component with search, keyboard navigation, click-outside/Escape close, and dark mode styling.
  • Exports validatePhoneNumber and formatE164 helpers backed by google-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"
@garrity-miepub garrity-miepub merged commit 60e0e6f into main Mar 9, 2026
9 of 10 checks passed
@garrity-miepub garrity-miepub deleted the feature/country-code-dropdown branch March 9, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants