gt-react 10.1.0 → 10.1.1

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/client.cjs.min.cjs +3 -3
  3. package/dist/client.d.ts +77 -10
  4. package/dist/client.esm.min.mjs +3 -3
  5. package/dist/hooks/useRegion.d.ts +0 -4
  6. package/dist/hooks/useRegion.d.ts.map +1 -1
  7. package/dist/hooks/useRegionSelector.d.ts +51 -1
  8. package/dist/hooks/useRegionSelector.d.ts.map +1 -1
  9. package/dist/index.cjs.min.cjs +3 -3
  10. package/dist/index.esm.min.mjs +3 -3
  11. package/dist/internal.cjs.min.cjs +3 -3
  12. package/dist/internal.d.ts +2 -2
  13. package/dist/internal.d.ts.map +1 -1
  14. package/dist/internal.esm.min.mjs +1 -1
  15. package/dist/provider/ClientProvider.d.ts +1 -1
  16. package/dist/provider/ClientProvider.d.ts.map +1 -1
  17. package/dist/provider/GTProvider.d.ts.map +1 -1
  18. package/dist/provider/hooks/locales/useDetermineLocale.d.ts.map +1 -0
  19. package/dist/provider/hooks/{useCalculateLocaleData.d.ts → locales/useLocaleState.d.ts} +2 -2
  20. package/dist/provider/hooks/locales/useLocaleState.d.ts.map +1 -0
  21. package/dist/provider/hooks/useRegionState.d.ts +9 -0
  22. package/dist/provider/hooks/useRegionState.d.ts.map +1 -0
  23. package/dist/types/config.d.ts +1 -0
  24. package/dist/types/config.d.ts.map +1 -1
  25. package/dist/ui/LocaleSelector.d.ts +6 -3
  26. package/dist/ui/LocaleSelector.d.ts.map +1 -1
  27. package/dist/ui/RegionSelector.d.ts +19 -1
  28. package/dist/ui/RegionSelector.d.ts.map +1 -1
  29. package/dist/utils/cookies.d.ts +4 -0
  30. package/dist/utils/cookies.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/provider/hooks/useCalculateLocaleData.d.ts.map +0 -1
  33. package/dist/provider/hooks/useDetermineLocale.d.ts.map +0 -1
  34. /package/dist/provider/hooks/{useDetermineLocale.d.ts → locales/useDetermineLocale.d.ts} +0 -0
package/dist/client.d.ts CHANGED
@@ -194,10 +194,11 @@ type ClientProviderProps = {
194
194
  gtServicesEnabled?: boolean;
195
195
  localeCookieName?: string;
196
196
  resetLocaleCookieName: string;
197
+ regionCookieName?: string;
197
198
  customMapping?: CustomMapping;
198
199
  };
199
200
 
200
- declare function ClientProvider({ children, dictionary, initialTranslations, initialTranslationsStatus, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
201
+ declare function ClientProvider({ children, dictionary, initialTranslations, initialTranslationsStatus, locale: _locale, region: _region, _versionId, defaultLocale, translationRequired, dialectTranslationRequired, locales, renderSettings, projectId, devApiKey, runtimeUrl, runtimeTranslationEnabled, resetLocaleCookieName, localeCookieName, regionCookieName, customMapping, }: ClientProviderProps): React$1.JSX.Element;
201
202
 
202
203
  /**
203
204
  * The `<Branch>` component dynamically renders a specified branch of content or a fallback child component.
@@ -486,20 +487,40 @@ declare namespace Var {
486
487
 
487
488
  /**
488
489
  * A dropdown component that allows users to select a locale.
489
- * @param {string[]} locales - An optional list of locales to use for the dropdown. If not provided, the list of locales from the `<GTProvider>` context is used.
490
- * @param {object} customNames - An optional object to map locales to custom names.
490
+ * @param {string[]} [locales] - An optional list of locales to use for the dropdown. If not provided, the list of locales from the `<GTProvider>` context is used.
491
+ * @param {object} [customNames] - (deprecated) An optional object to map locales to custom names. Use `customMapping` instead.
492
+ * @param {CustomMapping} [customMapping] - An optional object to map locales to custom display names, emojis, or other properties.
491
493
  * @returns {React.ReactElement | null} The rendered locale dropdown component or null to prevent rendering.
492
494
  */
493
- declare function LocaleSelector({ locales: _locales, customNames, ...props }: {
495
+ declare function LocaleSelector({ locales: _locales, customNames, customMapping, ...props }: {
494
496
  locales?: string[];
495
497
  customNames?: {
496
498
  [key: string]: string;
497
499
  };
500
+ customMapping?: CustomMapping;
498
501
  [key: string]: any;
499
502
  }): React__default.JSX.Element | null;
500
503
 
501
504
  /**
502
- * A multi-purpose dropdown component that allows users to select a region.
505
+ * A dropdown component that allows users to select a region.
506
+ *
507
+ * @param {string[]} [regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales in the `<GTProvider>` context.
508
+ * @param {React.ReactNode} [placeholder] - Optional placeholder node to display as the first option when no region is selected.
509
+ * @param {object} [customMapping] - An optional object to map region codes to custom display names, emojis, or associated locales. The value can be a string (display name) or an object with `name`, `emoji`, and/or `locale` properties.
510
+ * @param {boolean} [prioritizeCurrentLocaleRegion] - If true, the region corresponding to the current locale is prioritized in the list.
511
+ * @param {boolean} [sortRegionsAlphabetically] - If true, regions are sorted alphabetically by display name.
512
+ * @param {boolean} [asLocaleSelector=false] - If true, selecting a region will also update the locale to the region's associated locale.
513
+ * @param {object} [props] - Additional props to pass to the underlying `<select>` element.
514
+ * @returns {React.JSX.Element | null} The rendered region dropdown component or null if no regions are available.
515
+ *
516
+ * @example
517
+ * ```tsx
518
+ * <RegionSelector
519
+ * regions={['US', 'CA']}
520
+ * customMapping={{ US: { name: "United States", emoji: "🇺🇸" } }}
521
+ * placeholder="Select a region"
522
+ * />
523
+ * ```
503
524
  */
504
525
  declare function RegionSelector<Regions extends string[]>({ regions: _regions, placeholder, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, asLocaleSelector, ...props }: {
505
526
  regions?: Regions;
@@ -611,10 +632,6 @@ declare function useLocaleProperties(locale: string): generaltranslation_dist_lo
611
632
  *
612
633
  * Returns the `region` value as a string (e.g., `"US"`, `"CA"`) or `undefined` if no region has been set.
613
634
  *
614
- * ⚠️ **Note:** This hook must be used within a `<GTProvider>` component.
615
- * If used outside, it will throw an error:
616
- * `"useRegion(): Unable to access user's region outside of a <GTProvider>"`.
617
- *
618
635
  * @returns {string | undefined} The currently active region code, or `undefined` if not set.
619
636
  *
620
637
  * @example
@@ -637,7 +654,57 @@ type RegionData = {
637
654
  locale: string;
638
655
  };
639
656
  /**
640
- * A multi-purpose dropdown component that allows users to select a region.
657
+ * React hook for managing region selection logic in applications supporting multiple regions.
658
+ *
659
+ * This hook provides the necessary data and handlers to implement a region selector UI component.
660
+ * It returns the current region, a list of available regions, region metadata, and functions to update the region or associated locale.
661
+ *
662
+ * ### Parameters
663
+ * @param {Object} [options] - Optional configuration object.
664
+ * @param {string[]} [options.regions] - An optional array of ISO 3166 region codes to display. If not provided, regions are inferred from supported locales.
665
+ * @param {Object.<string, string|{name?: string, emoji?: string, locale?: string}>} [options.customMapping] - Optional mapping to override region display names, emojis, or associated locales.
666
+ * @param {boolean} [options.prioritizeCurrentLocaleRegion=true] - If true, the region corresponding to the current locale is prioritized in the list.
667
+ * @param {boolean} [options.sortRegionsAlphabetically=true] - If true, regions are sorted alphabetically by display name.
668
+ *
669
+ * ### Returns
670
+ * @returns {{
671
+ * region: string | undefined,
672
+ * setRegion: (region: string) => void,
673
+ * regions: string[],
674
+ * regionData: Map<string, { code: string, name: string, emoji: string, locale: string }>,
675
+ * locale: string,
676
+ * setLocale: (locale: string) => void
677
+ * }} An object containing:
678
+ * - `region`: The currently selected region code.
679
+ * - `setRegion`: Function to update the selected region.
680
+ * - `regions`: Array of available region codes.
681
+ * - `regionData`: Map of region codes to their display data (name, emoji, locale).
682
+ * - `locale`: The current locale.
683
+ * - `setLocale`: Function to update the locale.
684
+ *
685
+ * ### Example
686
+ * ```tsx
687
+ * const {
688
+ * region,
689
+ * setRegion,
690
+ * regions,
691
+ * regionData,
692
+ * locale,
693
+ * setLocale
694
+ * } = useRegionSelector({
695
+ * customMapping: { US: { name: "United States", emoji: "🇺🇸" } }
696
+ * });
697
+ *
698
+ * return (
699
+ * <select value={region} onChange={e => setRegion(e.target.value)}>
700
+ * {regions.map(r => (
701
+ * <option key={r} value={r}>
702
+ * {regionData.get(r)?.name}
703
+ * </option>
704
+ * ))}
705
+ * </select>
706
+ * );
707
+ * ```
641
708
  */
642
709
  declare function useRegionSelector({ regions: _regions, customMapping, prioritizeCurrentLocaleRegion, sortRegionsAlphabetically, }?: {
643
710
  regions?: string[];