Commit 5ccbc7a
feat(registry): add phone-input (#257)
* chore: cleanup
* feat: add phone input component with country selector
Add a new phone input component with international phone number support:
- Country dropdown with flags and dial codes (50+ countries)
- Built-in search using Command component with keyboard navigation
- Form integration with React Hook Form
- Both controlled and uncontrolled patterns
- Custom country list support
- Full accessibility with ARIA attributes
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: add PhoneInputGroup for input-group pattern
Refactor phone input to use an input-group pattern similar to shadcn:
- Add PhoneInputGroup component that handles flex layout and border styling
- Remove need for manual div wrapper in demos
- Country select and field are now direct children of PhoneInputGroup
- Focus states and borders handled by the group container
- Cleaner API with better component composition
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: simplify phone input API - remove Label and Group
Remove PhoneInputLabel and PhoneInputGroup for a cleaner API:
- PhoneInput now acts as both root container and input group
- Handles layout, borders, and focus states directly
- Labels can be added externally as needed (standard label or FormLabel)
- Reduced from 5 components to 3: PhoneInput, CountrySelect, Field
- Simpler composition with less nesting
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: remove orphaned aria-controls attribute
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: remove unused aria attributes from country select
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: make country select full height with proper border separator
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: improve phone input focus states and use shadcn Input
- Use shadcn Input component for consistent styling
- Individual focus rings for country selector and input field
- Each segment now has its own clear focus state (not entire container)
- Match shadcn input-group focus ring pattern (3px ring with 50% opacity)
- Remove overflow-hidden to prevent focus ring clipping
- Add proper invalid state styling for both segments
* feat: focus input field after country selection
* refactor: clean up phone input component
- Simplify PhoneInputProps to extend React.ComponentProps directly
- Allow PhoneInputCountrySelect to accept all PopoverTrigger props
- Remove unnecessary interface definitions and inline prop types
- Simplify ref handling in PhoneInputField
- Remove redundant comments
* feat: add locale detection for automatic country selection
- Remove hardcoded default country (previously "US")
- Add getCountryFromLocale utility function
- Add locale prop to PhoneInputProps
- Automatically detect country from browser locale (e.g., en-US → US)
- Falls back to first country in list if detection fails
- Update demo to showcase locale detection
- Add documentation for locale detection behavior
* feat: add autoDetect prop to disable automatic country selection
- Add autoDetect prop (default: true) to PhoneInputProps
- When false, no country is pre-selected, forcing explicit selection
- Update initialization logic to respect autoDetect flag
- Add new demo example showcasing disabled auto-detection
- Update documentation with autoDetect usage
* chore: rebuild registry
* chore: sort DEFAULT_COUNTRIES alphabetically by country name
* fix: prevent hydration mismatch in phone input locale detection
- Skip locale detection during SSR to ensure consistent server/client rendering
- Add useEffect to detect and set locale on client after hydration
- Prevents mismatch between server-rendered and client-rendered country
- Fixes hydration error when autoDetect is enabled without defaultCountry
* fix: ensure consistent initial state for SSR hydration
* fix: add useEffect to detect locale after hydration
* fix: run locale detection only once on mount
* refactor: improve phone input state management and API
- Move open/onOpenChange to store for consistent state management
- Change PhoneInputCountrySelect to extend Popover props instead of PopoverTrigger
- Rename isLoadingCountry to isLoading for brevity
- Add loading skeleton for locale detection on client hydration
- Fix SSR hydration mismatch by deferring locale detection to useEffect
* feat: add controlled/uncontrolled open state to PhoneInputCountrySelect
* fix: compose external onOpenChange with internal handler
* fix: compose external onOpenChange with internal handler
* chore: rebuild registry
* refactor: improve phone input loading and empty states
- Simplify locale detection logic with isLoading guard clause
- Add placeholder text when no country is selected to prevent layout shift
- Clean up conditional rendering in country select trigger
* feat: use placeholder block instead of text when no country selected
* refactor: improve phone input state management and loading UX
- Move open state to store for centralized state management
- Compose external onOpenChange with internal handler
- Add loading skeleton during locale detection to prevent hydration mismatch
- Add placeholder block when no country selected to prevent layout shift
- Adjust placeholder widths based on showFlag/showDialCode props
- Simplify locale detection with isLoading guard clause
- Fix SSR hydration by deferring locale detection to useEffect
* refactor: optimize phone input by removing external dependencies
Replace libphonenumber-js, country-telephone-data, and flag icon libraries with lightweight inline data and native browser APIs. This reduces bundle size by ~2-4MB while maintaining all functionality.
Changes:
- Remove libphonenumber-js dependency (~200KB)
- Remove country-telephone-data dependency (~20KB)
- Remove unused country-flag-icons and flag-icons libraries (~2-4MB)
- Inline country data as compact [iso2, dialCode] tuples (~5KB)
- Use native Intl.DisplayNames API for country names
- Generate flag emojis programmatically from country codes
- Update registry dependencies to reflect removed packages
* docs: add attribution for country data source
* chore: cleanup
* chore: rebuild registry again
* fix: use correct KeyboardShortcutsTable component in docs
* chore: fix docs
* chore: better value
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 89a4d9a commit 5ccbc7a
File tree
18 files changed
+1685
-14
lines changed- docs
- __registry__
- app/(lobby)/pg
- content/docs/components
- public/r
- registry
- default
- examples
- ui
- types/docs
18 files changed
+1685
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
420 | 442 | | |
421 | 443 | | |
422 | 444 | | |
| |||
2341 | 2363 | | |
2342 | 2364 | | |
2343 | 2365 | | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
2344 | 2422 | | |
2345 | 2423 | | |
2346 | 2424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 4 | + | |
11 | 5 | | |
12 | 6 | | |
13 | 7 | | |
14 | 8 | | |
15 | 9 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 10 | + | |
23 | 11 | | |
24 | 12 | | |
25 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
522 | 551 | | |
523 | 552 | | |
524 | 553 | | |
| |||
0 commit comments