UNPKG

@keycloakify/keycloak-account-ui

Version:

<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a

28 lines 1.27 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useMemo } from "react"; import { FormProvider } from "react-hook-form"; import { SelectControl } from "../../ui-shared/controls/select-control/SelectControl"; const localeToDisplayName = (locale) => { try { return new Intl.DisplayNames([locale], { type: "language" }).of(locale); } catch (error) { return locale; } }; export const LocaleSelector = ({ t, form, supportedLocales, currentLocale, }) => { const locales = useMemo(() => supportedLocales .map((locale) => { var _a; return ({ key: locale, value: t(`locale_${locale}`, (_a = localeToDisplayName(locale)) !== null && _a !== void 0 ? _a : locale), }); }) .sort((a, b) => a.value.localeCompare(b.value, currentLocale)), [supportedLocales, currentLocale, t]); if (!locales.length) { return null; } return (_jsx(FormProvider, Object.assign({}, form, { children: _jsx(SelectControl, { "data-testid": "locale-select", name: "attributes.locale", label: t("selectALocale"), controller: { defaultValue: "" }, options: locales, variant: locales.length >= 10 ? "typeahead" : "single" }) }))); }; //# sourceMappingURL=LocaleSelector.js.map