import { LocaleSwitcher } from "@pixxl-tools/components";
// In Server Components:
import { LocaleSwitcher } from "@pixxl-tools/components/server";| Prop | Type | Default | Description |
|---|---|---|---|
items (required) | readonly LocaleSwitcherItem[] | — | Items to render. |
value (required) | string | — | Current value (controlled); null where it means "nothing selected". |
size | "md" | "sm" | — | Size from the shared scale (xs, sm, md, lg). |
variant | "links" | "menu" | "select" | links | links (default), select (native select) or menu (menu button). |
defaultLocale | string | — | Listed first (with supportedLocales: the shared locale order). |
label | string | "Language" | Accessible name of the group / select / menu (default "Language"). |
onValueChange | (id: string) => void | — | Called with the item id instead of navigating (a plain click on a links / menu link, or a select change). Inside a SitePreferencesProvider the locale is remembered either way. |
order | readonly string[] | — | Explicit order of the items (locale tags, matched like supportedLocales), independent of defaultLocale: e.g. ["en", "pl"] on a site whose default is Polish. Wins over defaultLocale / supportedLocales ordering. |
prefetch | boolean | false | links and menu: router prefetch of the locale links, forwarded to the PixxlProvider linkComponent / renderLink (default false). Keep it off when middleware or a proxy sets a locale cookie: a prefetch would switch the visitor's language without a click. |
renderLink | ( props: LocaleSwitcherLinkRenderProps, item: LocaleSwitcherItem, ) => ReactNode | — | links variant: render with your router (next/link). |
supportedLocales | readonly string[] | — | Orders the items: defaultLocale first, then this order (pass the SitePreferencesProvider lists), so every site lists locales alike. |
itemsrequiredreadonly LocaleSwitcherItem[]
Items to render.
valuerequiredstring
Current value (controlled); null where it means "nothing selected".
size"md" | "sm"
Size from the shared scale (xs, sm, md, lg).
variantdefault links"links" | "menu" | "select"
links (default), select (native select) or menu (menu button).
defaultLocalestring
Listed first (with supportedLocales: the shared locale order).
labeldefault "Language"string
Accessible name of the group / select / menu (default "Language").
onValueChange(id: string) => void
Called with the item id instead of navigating (a plain click on a links / menu link, or a select change). Inside a SitePreferencesProvider the locale is remembered either way.
orderreadonly string[]
Explicit order of the items (locale tags, matched like supportedLocales), independent of defaultLocale: e.g. ["en", "pl"] on a site whose default is Polish. Wins over defaultLocale / supportedLocales ordering.
prefetchdefault falseboolean
links and menu: router prefetch of the locale links, forwarded to the PixxlProvider linkComponent / renderLink (default false). Keep it off when middleware or a proxy sets a locale cookie: a prefetch would switch the visitor's language without a click.
renderLink( props: LocaleSwitcherLinkRenderProps, item: LocaleSwitcherItem, ) => ReactNode
links variant: render with your router (next/link).
supportedLocalesreadonly string[]
Orders the items: defaultLocale first, then this order (pass the SitePreferencesProvider lists), so every site lists locales alike.
Other props are passed to the root element (HTMLAttributes<HTMLDivElement>), including className, style, id and aria-* attributes.
const locale = "en";
const locales = [
{ id: "en", href: "/en", label: "EN", ariaLabel: "English", lang: "en" },
{ id: "pl", href: "/pl", label: "PL", ariaLabel: "Polski", lang: "pl" },
];
// Header (house rule): links, current language first in the site’s own order, size sm.
<LocaleSwitcher
items={[
{ id: "en", href: "/en", label: "EN", ariaLabel: "English", lang: "en" }, // named "EN – English"
{ id: "pl", href: "/pl", label: "PL", ariaLabel: "Polski", lang: "pl" },
]}
value={locale}
/>
// prefetch defaults to false: a prefetch must never run a proxy that sets the locale cookie.