@undefine-ui/design-system 3.6.1 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -600,6 +600,158 @@ const sortOptions: SortOption[] = [
600
600
  - `open` - Whether the button is in open/active state
601
601
  - All standard MUI ButtonBase props
602
602
 
603
+ ### Google Places Autocomplete
604
+
605
+ A Google Places address autocomplete component with structured address parsing, coordinates extraction, and React Hook Form integration. Perfect for address lookup, location selection, and form-based address capture.
606
+
607
+ **Setup:**
608
+
609
+ ```tsx
610
+ import { GooglePlacesProvider } from '@undefine-ui/design-system';
611
+
612
+ // Wrap your app with GooglePlacesProvider
613
+ function App() {
614
+ return (
615
+ <GooglePlacesProvider apiKey={process.env.GOOGLE_MAPS_API_KEY}>
616
+ {/* Your app content */}
617
+ </GooglePlacesProvider>
618
+ );
619
+ }
620
+ ```
621
+
622
+ **Usage:**
623
+
624
+ ```tsx
625
+ import {
626
+ GooglePlacesAutocomplete,
627
+ Field,
628
+ type PlaceType,
629
+ type PlaceDetails
630
+ } from '@undefine-ui/design-system';
631
+
632
+ // Basic usage
633
+ const [value, setValue] = useState<PlaceType | null>(null);
634
+
635
+ <GooglePlacesAutocomplete
636
+ label="Search for a location"
637
+ placeholder="Start typing..."
638
+ onChange={setValue}
639
+ />
640
+
641
+ // With place details (includes parsed address and coordinates)
642
+ <GooglePlacesAutocomplete
643
+ label="Search address"
644
+ fetchPlaceDetails
645
+ onPlaceDetailsChange={(details) => {
646
+ console.log(details?.parsedAddress?.city); // "Lagos"
647
+ console.log(details?.parsedAddress?.country); // "Nigeria"
648
+ console.log(details?.coordinates?.latitude); // 6.5245
649
+ }}
650
+ />
651
+
652
+ // With country restriction
653
+ <GooglePlacesAutocomplete
654
+ label="US addresses only"
655
+ componentRestrictions={{ country: 'us' }}
656
+ onChange={setValue}
657
+ />
658
+ ```
659
+
660
+ **React Hook Form Integration:**
661
+
662
+ ```tsx
663
+ import { Form, Field } from '@undefine-ui/design-system';
664
+ import { useForm } from 'react-hook-form';
665
+
666
+ const MyForm = () => {
667
+ const methods = useForm({
668
+ defaultValues: {
669
+ location: null,
670
+ address: ''
671
+ }
672
+ });
673
+
674
+ return (
675
+ <Form methods={methods} onSubmit={(data) => console.log(data)}>
676
+ {/* Store full PlaceType object */}
677
+ <Field.GooglePlacesAutocomplete name="location" label="Location" valueType="full" />
678
+
679
+ {/* Store only description string */}
680
+ <Field.GooglePlacesAutocomplete name="address" label="Address" valueType="description" />
681
+
682
+ {/* Store PlaceDetails with parsed address */}
683
+ <Field.GooglePlacesAutocomplete
684
+ name="fullAddress"
685
+ label="Full Address"
686
+ valueType="details"
687
+ fetchPlaceDetails
688
+ />
689
+ </Form>
690
+ );
691
+ };
692
+ ```
693
+
694
+ **GooglePlacesAutocomplete Props:**
695
+
696
+ - `label` - Input label
697
+ - `placeholder` - Input placeholder
698
+ - `value` - Selected place (controlled)
699
+ - `onChange` - Callback when selection changes `(place: PlaceType | null) => void`
700
+ - `fetchPlaceDetails` - Fetch full place details on selection (default: `false`)
701
+ - `onPlaceDetailsChange` - Callback with place details `(details: PlaceDetails | null) => void`
702
+ - `componentRestrictions` - Country restrictions `{ country: string | string[] }`
703
+ - `types` - Place types to search for (e.g., `['address']`, `['establishment']`)
704
+ - `debounceMs` - Debounce delay in milliseconds (default: `300`)
705
+ - `error` / `errorMessage` / `helperText` - Error and helper text display
706
+ - All standard MUI TextField props
707
+
708
+ **Field.GooglePlacesAutocomplete Props:**
709
+
710
+ - `name` - Form field name (required)
711
+ - `valueType` - What to store in form: `'full'` (PlaceType), `'description'` (string), or `'details'` (PlaceDetails)
712
+ - `onValueChange` - Callback when value changes (raw PlaceType)
713
+ - `onPlaceDetailsChange` - Callback when place details are fetched
714
+ - All `GooglePlacesAutocomplete` props except `value`, `onChange`, `error`, `errorMessage`
715
+
716
+ **PlaceDetails Structure:**
717
+
718
+ ```typescript
719
+ interface PlaceDetails {
720
+ placeId: string;
721
+ description: string;
722
+ formattedAddress?: string;
723
+ lat?: number;
724
+ lng?: number;
725
+
726
+ // Structured parsed address
727
+ parsedAddress?: {
728
+ streetNumber?: string;
729
+ street?: string;
730
+ address?: string; // Full formatted address
731
+ neighborhood?: string;
732
+ city?: string;
733
+ state?: string;
734
+ stateCode?: string;
735
+ country?: string;
736
+ countryCode?: string;
737
+ postalCode?: string;
738
+ county?: string;
739
+ };
740
+
741
+ // Coordinates
742
+ coordinates?: {
743
+ latitude: number;
744
+ longitude: number;
745
+ };
746
+ }
747
+ ```
748
+
749
+ **Exported Utilities:**
750
+
751
+ - `GooglePlacesProvider` - Context provider for API key
752
+ - `useGooglePlacesAutocomplete` - Hook for custom implementations
753
+ - `parseAddressComponents` - Parse raw Google address components into structured format
754
+
603
755
  ### OTP Input
604
756
 
605
757
  A one-time password input component with keyboard navigation, paste support, and validation. Perfect for email/SMS verification, PIN codes, and security codes.
package/dist/index.cjs CHANGED
@@ -10553,7 +10553,27 @@ var RHFGooglePlacesAutocomplete = ({
10553
10553
  }
10554
10554
  };
10555
10555
  }
10556
- return field.value;
10556
+ if (field.value.address || field.value.city || field.value.country) {
10557
+ const addressParts = [
10558
+ field.value.address,
10559
+ field.value.city,
10560
+ field.value.state,
10561
+ field.value.country
10562
+ ].filter(Boolean);
10563
+ const displayText = addressParts.join(", ");
10564
+ return {
10565
+ description: displayText,
10566
+ structured_formatting: {
10567
+ main_text: field.value.address || field.value.city || displayText,
10568
+ main_text_matched_substrings: [],
10569
+ secondary_text: addressParts.slice(1).join(", ")
10570
+ }
10571
+ };
10572
+ }
10573
+ if (field.value.description) {
10574
+ return field.value;
10575
+ }
10576
+ return null;
10557
10577
  };
10558
10578
  const handleChange = (newValue) => {
10559
10579
  onValueChange?.(newValue);