periplo-ui 4.20.2 → 4.21.0

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.
@@ -6,6 +6,8 @@ type CountrySelectBaseProps<T> = CountrySelectComboboxProps & {
6
6
  /** ISO codes pinned above the list, in order. */
7
7
  priorityCountries?: Array<string>;
8
8
  onChange?: (value: string, country: T) => void;
9
+ /** Replaces the default `Flag` in the trigger and the options. */
10
+ renderFlag?: (country: T) => React.ReactNode;
9
11
  };
10
12
  type ResolvedCountrySelectProps<T extends object> = CountrySelectBaseProps<T> & Partial<CountrySelectAccessors<T>> & {
11
13
  /** Defaults to the generated list. */
@@ -7,7 +7,7 @@ import { CheckIcon } from "@phosphor-icons/react/dist/ssr/Check";
7
7
  import { GlobeIcon } from "@phosphor-icons/react/dist/ssr/Globe";
8
8
  //#region src/components/inputs/CountrySelect/CountrySelect.tsx
9
9
  function CountrySelect(props) {
10
- const { countries, locale = "en", priorityCountries, onChange, getCountryValue, getCountryIsoCode, getCountryName, getCountrySearchTerms, className, disabled = false, placeholder = "Select country", ...comboboxProps } = props;
10
+ const { countries, locale = "en", priorityCountries, onChange, renderFlag, getCountryValue, getCountryIsoCode, getCountryName, getCountrySearchTerms, className, disabled = false, placeholder = "Select country", ...comboboxProps } = props;
11
11
  const options = countries ?? buildCountries(locale);
12
12
  const valueOf = getCountryValue ?? ((option) => option.isoCode);
13
13
  const nameOf = getCountryName ?? ((option) => option.name);
@@ -30,7 +30,7 @@ function CountrySelect(props) {
30
30
  const iso = isoOf(option);
31
31
  return /* @__PURE__ */ jsxs("span", {
32
32
  className: "flex min-w-0 items-center gap-2",
33
- children: [iso && /* @__PURE__ */ jsx(Flag, { iso }), /* @__PURE__ */ jsx("span", {
33
+ children: [renderFlag ? renderFlag(option) : iso && /* @__PURE__ */ jsx(Flag, { iso }), /* @__PURE__ */ jsx("span", {
34
34
  className: "truncate",
35
35
  children: nameOf(option)
36
36
  })]
@@ -1 +1 @@
1
- {"version":3,"file":"CountrySelect.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/CountrySelect/CountrySelect.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { GlobeIcon } from '@phosphor-icons/react/dist/ssr/Globe'\nimport type * as React from 'react'\n\nimport { Flag } from '../../data-display/Flag'\nimport { Combobox, type ComboboxSingleProps } from '../Combobox'\n\nimport type { Country, CountrySelectAccessors } from './types'\n\nimport { buildCountries, regionName, resolveIso, splitByPriority } from '@/lib/countries'\nimport { cn, createSearchMatcher } from '@/lib/utils'\n\ntype CountrySelectComboboxProps = Pick<\n ComboboxSingleProps<object>,\n | 'id'\n | 'className'\n | 'disabled'\n | 'error'\n | 'size'\n | 'value'\n | 'placeholder'\n | 'searchPlaceholder'\n | 'emptyMessage'\n | 'aria-invalid'\n | 'aria-describedby'\n>\n\ntype CountrySelectBaseProps<T> = CountrySelectComboboxProps & {\n /** ISO codes pinned above the list, in order. */\n priorityCountries?: Array<string>\n onChange?: (value: string, country: T) => void\n}\n\ntype ResolvedCountrySelectProps<T extends object> = CountrySelectBaseProps<T> &\n Partial<CountrySelectAccessors<T>> & {\n /** Defaults to the generated list. */\n countries?: Array<T>\n /** Ignored when `countries` is passed. */\n locale?: string\n }\n\nexport type CountrySelectDefaultProps = ResolvedCountrySelectProps<Country>\n\nexport type CountrySelectCustomProps<T extends object> = CountrySelectBaseProps<T> &\n CountrySelectAccessors<T> & {\n countries: Array<T>\n }\n\nexport type CountrySelectProps<T extends object = Country> = CountrySelectDefaultProps | CountrySelectCustomProps<T>\n\nexport function CountrySelect(props: Readonly<CountrySelectDefaultProps>): React.ReactElement\nexport function CountrySelect<T extends object>(props: Readonly<CountrySelectCustomProps<T>>): React.ReactElement\nexport function CountrySelect<T extends object>(props: Readonly<ResolvedCountrySelectProps<T>>): React.ReactElement {\n const {\n countries,\n locale = 'en',\n priorityCountries,\n onChange,\n getCountryValue,\n getCountryIsoCode,\n getCountryName,\n getCountrySearchTerms,\n className,\n disabled = false,\n placeholder = 'Select country',\n ...comboboxProps\n } = props\n\n const options = countries ?? (buildCountries(locale) as unknown as Array<T>)\n const valueOf = getCountryValue ?? ((option: T) => (option as unknown as Country).isoCode)\n const nameOf = getCountryName ?? ((option: T) => (option as unknown as Country).name)\n const isoOf = (option: T) => resolveIso(valueOf(option), getCountryIsoCode?.(option))\n\n const { priority, rest } = splitByPriority(options, priorityCountries, isoOf)\n\n const filterOptions = (list: Array<T>, search: string) => {\n const matches = createSearchMatcher(search)\n return list.filter((option) => {\n const iso = isoOf(option)\n const terms = [nameOf(option), iso ?? '', ...(getCountrySearchTerms?.(option) ?? [])]\n if (!countries && iso && locale !== 'en') terms.push(regionName(iso))\n return matches(terms)\n })\n }\n\n const renderCountry = (option: T) => {\n const iso = isoOf(option)\n return (\n <span className=\"flex min-w-0 items-center gap-2\">\n {iso && <Flag iso={iso} />}\n <span className=\"truncate\">{nameOf(option)}</span>\n </span>\n )\n }\n\n return (\n <Combobox<T>\n {...comboboxProps}\n className={cn('w-full', className)}\n disabled={disabled || (options.length <= 1 && !!comboboxProps.value)}\n placeholder={\n <span className=\"flex items-center gap-2\">\n <GlobeIcon className=\"h-5 w-5 shrink-0\" aria-hidden />\n <span className=\"truncate\">{placeholder}</span>\n </span>\n }\n virtualized\n options={rest}\n specialOptions={priority}\n getOptionValue={valueOf}\n getOptionLabel={nameOf}\n filterOptions={filterOptions}\n clearable={false}\n onOpenAutoFocus\n onChange={(value) => {\n const country = options.find((option) => valueOf(option) === value)\n if (country) onChange?.(value, country)\n }}\n renderLabel={renderCountry}\n renderOption={(option, isSelected) => (\n <>\n {renderCountry(option)}\n {isSelected && (\n <CheckIcon\n data-testid=\"selected-check\"\n weight=\"bold\"\n className=\"ml-auto h-4 w-4 shrink-0 text-neutral-950\"\n />\n )}\n </>\n )}\n />\n )\n}\n\nCountrySelect.displayName = 'CountrySelect'\n"],"mappings":";;;;;;;;AAoDA,SAAgB,cAAgC,OAAoE;C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SAAS;EACT,gBAAgB;EAChB,gBAAgB;EAChB,gBAAgB;EACD;EACf,WAAW;EACX,iBAAA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,QAAQ,MAAM,WAAW,QAAQ,MAAM,MAAM,KAAK;GAClE,IAAI,SAAS,WAAW,OAAO,OAAO;EACxC;EACA,aAAa;EACb,eAAe,QAAQ,eACrB,qBAAAA,UAAA,EAAA,UAAA,CACG,cAAc,MAAM,GACpB,cACC,oBAAC,WAAD;GACE,eAAY;GACZ,QAAO;GACP,WAAU;EACX,CAAA,CAEH,EAAA,CAAA;CAEL,CAAA;AAEL;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"CountrySelect.js","names":["_Fragment"],"sources":["../../../../src/components/inputs/CountrySelect/CountrySelect.tsx"],"sourcesContent":["import { CheckIcon } from '@phosphor-icons/react/dist/ssr/Check'\nimport { GlobeIcon } from '@phosphor-icons/react/dist/ssr/Globe'\nimport type * as React from 'react'\n\nimport { Flag } from '../../data-display/Flag'\nimport { Combobox, type ComboboxSingleProps } from '../Combobox'\n\nimport type { Country, CountrySelectAccessors } from './types'\n\nimport { buildCountries, regionName, resolveIso, splitByPriority } from '@/lib/countries'\nimport { cn, createSearchMatcher } from '@/lib/utils'\n\ntype CountrySelectComboboxProps = Pick<\n ComboboxSingleProps<object>,\n | 'id'\n | 'className'\n | 'disabled'\n | 'error'\n | 'size'\n | 'value'\n | 'placeholder'\n | 'searchPlaceholder'\n | 'emptyMessage'\n | 'aria-invalid'\n | 'aria-describedby'\n>\n\ntype CountrySelectBaseProps<T> = CountrySelectComboboxProps & {\n /** ISO codes pinned above the list, in order. */\n priorityCountries?: Array<string>\n onChange?: (value: string, country: T) => void\n /** Replaces the default `Flag` in the trigger and the options. */\n renderFlag?: (country: T) => React.ReactNode\n}\n\ntype ResolvedCountrySelectProps<T extends object> = CountrySelectBaseProps<T> &\n Partial<CountrySelectAccessors<T>> & {\n /** Defaults to the generated list. */\n countries?: Array<T>\n /** Ignored when `countries` is passed. */\n locale?: string\n }\n\nexport type CountrySelectDefaultProps = ResolvedCountrySelectProps<Country>\n\nexport type CountrySelectCustomProps<T extends object> = CountrySelectBaseProps<T> &\n CountrySelectAccessors<T> & {\n countries: Array<T>\n }\n\nexport type CountrySelectProps<T extends object = Country> = CountrySelectDefaultProps | CountrySelectCustomProps<T>\n\nexport function CountrySelect(props: Readonly<CountrySelectDefaultProps>): React.ReactElement\nexport function CountrySelect<T extends object>(props: Readonly<CountrySelectCustomProps<T>>): React.ReactElement\nexport function CountrySelect<T extends object>(props: Readonly<ResolvedCountrySelectProps<T>>): React.ReactElement {\n const {\n countries,\n locale = 'en',\n priorityCountries,\n onChange,\n renderFlag,\n getCountryValue,\n getCountryIsoCode,\n getCountryName,\n getCountrySearchTerms,\n className,\n disabled = false,\n placeholder = 'Select country',\n ...comboboxProps\n } = props\n\n const options = countries ?? (buildCountries(locale) as unknown as Array<T>)\n const valueOf = getCountryValue ?? ((option: T) => (option as unknown as Country).isoCode)\n const nameOf = getCountryName ?? ((option: T) => (option as unknown as Country).name)\n const isoOf = (option: T) => resolveIso(valueOf(option), getCountryIsoCode?.(option))\n\n const { priority, rest } = splitByPriority(options, priorityCountries, isoOf)\n\n const filterOptions = (list: Array<T>, search: string) => {\n const matches = createSearchMatcher(search)\n return list.filter((option) => {\n const iso = isoOf(option)\n const terms = [nameOf(option), iso ?? '', ...(getCountrySearchTerms?.(option) ?? [])]\n if (!countries && iso && locale !== 'en') terms.push(regionName(iso))\n return matches(terms)\n })\n }\n\n const renderCountry = (option: T) => {\n const iso = isoOf(option)\n return (\n <span className=\"flex min-w-0 items-center gap-2\">\n {renderFlag ? renderFlag(option) : iso && <Flag iso={iso} />}\n <span className=\"truncate\">{nameOf(option)}</span>\n </span>\n )\n }\n\n return (\n <Combobox<T>\n {...comboboxProps}\n className={cn('w-full', className)}\n disabled={disabled || (options.length <= 1 && !!comboboxProps.value)}\n placeholder={\n <span className=\"flex items-center gap-2\">\n <GlobeIcon className=\"h-5 w-5 shrink-0\" aria-hidden />\n <span className=\"truncate\">{placeholder}</span>\n </span>\n }\n virtualized\n options={rest}\n specialOptions={priority}\n getOptionValue={valueOf}\n getOptionLabel={nameOf}\n filterOptions={filterOptions}\n clearable={false}\n onOpenAutoFocus\n onChange={(value) => {\n const country = options.find((option) => valueOf(option) === value)\n if (country) onChange?.(value, country)\n }}\n renderLabel={renderCountry}\n renderOption={(option, isSelected) => (\n <>\n {renderCountry(option)}\n {isSelected && (\n <CheckIcon\n data-testid=\"selected-check\"\n weight=\"bold\"\n className=\"ml-auto h-4 w-4 shrink-0 text-neutral-950\"\n />\n )}\n </>\n )}\n />\n )\n}\n\nCountrySelect.displayName = 'CountrySelect'\n"],"mappings":";;;;;;;;AAsDA,SAAgB,cAAgC,OAAoE;CAClH,MAAM,EACJ,WACA,SAAS,MACT,mBACA,UACA,YACA,iBACA,mBACA,gBACA,uBACA,WACA,WAAW,OACX,cAAc,kBACd,GAAG,kBACD;CAEJ,MAAM,UAAU,aAAc,eAAe,MAAM;CACnD,MAAM,UAAU,qBAAqB,WAAe,OAA8B;CAClF,MAAM,SAAS,oBAAoB,WAAe,OAA8B;CAChF,MAAM,SAAS,WAAc,WAAW,QAAQ,MAAM,GAAG,oBAAoB,MAAM,CAAC;CAEpF,MAAM,EAAE,UAAU,SAAS,gBAAgB,SAAS,mBAAmB,KAAK;CAE5E,MAAM,iBAAiB,MAAgB,WAAmB;EACxD,MAAM,UAAU,oBAAoB,MAAM;EAC1C,OAAO,KAAK,QAAQ,WAAW;GAC7B,MAAM,MAAM,MAAM,MAAM;GACxB,MAAM,QAAQ;IAAC,OAAO,MAAM;IAAG,OAAO;IAAI,GAAI,wBAAwB,MAAM,KAAK,CAAC;GAAE;GACpF,IAAI,CAAC,aAAa,OAAO,WAAW,MAAM,MAAM,KAAK,WAAW,GAAG,CAAC;GACpE,OAAO,QAAQ,KAAK;EACtB,CAAC;CACH;CAEA,MAAM,iBAAiB,WAAc;EACnC,MAAM,MAAM,MAAM,MAAM;EACxB,OACE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACG,aAAa,WAAW,MAAM,IAAI,OAAO,oBAAC,MAAD,EAAW,IAAM,CAAA,GAC3D,oBAAC,QAAD;IAAM,WAAU;IAAY,UAAA,OAAO,MAAM;GAAQ,CAAA,CAC7C;;CAEV;CAEA,OACE,oBAAC,UAAD;EACE,GAAI;EACJ,WAAW,GAAG,UAAU,SAAS;EACjC,UAAU,YAAa,QAAQ,UAAU,KAAK,CAAC,CAAC,cAAc;EAC9D,aACE,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,oBAAC,WAAD;IAAW,WAAU;IAAmB,eAAA;GAAa,CAAA,GACrD,oBAAC,QAAD;IAAM,WAAU;IAAY,UAAA;GAAkB,CAAA,CAC1C;;EAER,aAAA;EACA,SAAS;EACT,gBAAgB;EAChB,gBAAgB;EAChB,gBAAgB;EACD;EACf,WAAW;EACX,iBAAA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,QAAQ,MAAM,WAAW,QAAQ,MAAM,MAAM,KAAK;GAClE,IAAI,SAAS,WAAW,OAAO,OAAO;EACxC;EACA,aAAa;EACb,eAAe,QAAQ,eACrB,qBAAAA,UAAA,EAAA,UAAA,CACG,cAAc,MAAM,GACpB,cACC,oBAAC,WAAD;GACE,eAAY;GACZ,QAAO;GACP,WAAU;EACX,CAAA,CAEH,EAAA,CAAA;CAEL,CAAA;AAEL;AAEA,cAAc,cAAc"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "periplo-ui",
3
3
  "description": "IATI UI library",
4
4
  "private": false,
5
- "version": "4.20.2",
5
+ "version": "4.21.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",