@@ -63,16 +63,27 @@ export function LocaleSwitcher() {
6363
6464## Props
6565
66- | Prop | Type | Required | Description |
67- | --------------- | ------------------------ | -------- | ------------------------------------------------------------ |
68- | ` locales ` | ` Locale[] ` | Yes | Array of available locales — only ` code ` is required |
69- | ` value ` | ` string ` | No | Selected locale code — pass this to control the component |
70- | ` defaultValue ` | ` string ` | No | Initial selected locale code (default: first locale's code) |
71- | ` onValueChange ` | ` (code: string) => void ` | No | Callback when locale changes |
72- | ` label ` | ` "native" \| "english" ` | No | Display labels in native or English (default: ` "english" ` ) |
73- | ` showFlags ` | ` boolean ` | No | Show flag emojis (default: ` false ` ) |
74- | ` maxHeight ` | ` number \| string ` | No | Max height of the scrolling option list (default: ` "15rem" ` ) |
75- | ` className ` | ` string ` | No | Additional CSS classes |
66+ | Prop | Type | Required | Description |
67+ | ------------------- | ------------------------------------- | -------- | ------------------------------------------------------------------------------------ |
68+ | ` locales ` | ` Locale[] ` | Yes | Array of available locales — only ` code ` is required |
69+ | ` value ` | ` string ` | No | Selected locale code — pass this to control the component |
70+ | ` defaultValue ` | ` string ` | No | Initial selected locale code (default: first locale's code) |
71+ | ` onValueChange ` | ` (code: string) => void ` | No | Callback when locale changes |
72+ | ` label ` | ` "native" \| "english" ` | No | Display labels in native or English (default: ` "english" ` ) |
73+ | ` showFlags ` | ` boolean ` | No | Show flag emojis (default: ` false ` ) |
74+ | ` maxHeight ` | ` number \| string ` | No | Max height of the scrolling option list (default: ` "15rem" ` ) |
75+ | ` showCode ` | ` boolean ` | No | Show the locale code beside each option (default: ` false ` ) |
76+ | ` variant ` | ` "outline" \| "ghost" \| "secondary" ` | No | Trigger style (default: ` "outline" ` ) |
77+ | ` size ` | ` "sm" \| "default" \| "lg" ` | No | Trigger size (default: ` "default" ` ) |
78+ | ` align ` | ` "start" \| "end" ` | No | Edge of the trigger the menu lines up with (default: ` "start" ` ) |
79+ | ` side ` | ` "top" \| "bottom" ` | No | Preferred menu side; flips when there is no room (default: ` "bottom" ` ) |
80+ | ` searchable ` | ` boolean ` | No | Show the search field (default: ` true ` ) |
81+ | ` searchPlaceholder ` | ` string ` | No | Search placeholder (default: ` "Search languages..." ` ) |
82+ | ` emptyMessage ` | ` ReactNode ` | No | Shown when the search matches nothing (default: ` "No languages found." ` ) |
83+ | ` disabled ` | ` boolean ` | No | Disable the trigger |
84+ | ` renderOption ` | ` (locale, state) => ReactNode ` | No | Replace each option row's content; ` state ` has ` selected ` , ` active ` , ` label ` , ` flag ` |
85+ | ` classNames ` | ` LanguageSwitcherClassNames ` | No | Per-part classes: ` trigger ` , ` content ` , ` search ` , ` list ` , ` item ` , ` empty ` |
86+ | ` className ` | ` string ` | No | Additional CSS classes on the root |
7687
7788### Locale Object
7889
@@ -184,6 +195,28 @@ export default function App() {
184195}
185196```
186197
198+ ### Customizing parts
199+
200+ The switcher is styled with shadcn theme tokens, so it follows your theme. Use
201+ ` classNames ` to restyle any part, or ` renderOption ` to change what each row shows:
202+
203+ ``` tsx
204+ <LanguageSwitcher
205+ locales = { locales }
206+ variant = " ghost"
207+ size = " sm"
208+ align = " end"
209+ classNames = { { content: " w-64" , item: " py-2" }}
210+ renderOption = { (locale , { label , flag , selected }) => (
211+ <>
212+ <span className = " text-base leading-none" >{ flag } </span >
213+ <span className = " flex-1" >{ label } </span >
214+ <span className = " text-xs text-muted-foreground" >{ selected ? " Current" : locale .code } </span >
215+ </>
216+ )}
217+ />
218+ ```
219+
187220## Keyboard support
188221
189222The popup follows the WAI-ARIA combobox pattern: focus stays in the search field,
0 commit comments