Skip to content

Commit c816118

Browse files
committed
feat(locale-picker): shadcn tokens, motion popup, and LanguageSwitcher parity
1 parent ef3f5cd commit c816118

9 files changed

Lines changed: 602 additions & 217 deletions

File tree

‎content/docs/components/locale-pickers/locale-picker.mdx‎

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,114 @@ import { Tabs, Tab } from "fumadocs-ui/components/tabs";
2020
>
2121
<Tab value="shadcn" className="border-none bg-transparent p-0 mt-3">
2222
<Tabs items={["npx", "pnpm", "yarn", "bun"]} defaultValue="npx" groupId="installation-tabs">
23-
<Tab value="npx">```bash npx shadcn@latest add @elements/locale-picker ```</Tab>
24-
<Tab value="pnpm">```bash pnpm dlx shadcn@latest add @elements/locale-picker ```</Tab>
25-
<Tab value="yarn">```bash yarn dlx shadcn@latest add @elements/locale-picker ```</Tab>
26-
<Tab value="bun">```bash bunx shadcn@latest add @elements/locale-picker ```</Tab>
23+
<Tab value="npx">
24+
25+
```bash
26+
npx shadcn@latest add @babelize/locale-picker
27+
```
28+
29+
</Tab>
30+
<Tab value="pnpm">
31+
32+
```bash
33+
pnpm dlx shadcn@latest add @babelize/locale-picker
34+
```
35+
36+
</Tab>
37+
<Tab value="yarn">
38+
39+
```bash
40+
yarn dlx shadcn@latest add @babelize/locale-picker
41+
```
42+
43+
</Tab>
44+
<Tab value="bun">
45+
46+
```bash
47+
bunx shadcn@latest add @babelize/locale-picker
48+
```
49+
50+
</Tab>
2751
</Tabs>
52+
2853
</Tab>
2954
<Tab value="Elements CLI" className="border-none bg-transparent p-0 mt-3">
3055
<Tabs items={["npx", "pnpm", "yarn", "bun"]} defaultValue="npx" groupId="elements-cli-tabs">
31-
<Tab value="npx">```bash npx @babelize/elements add locale-picker ```</Tab>
32-
<Tab value="pnpm">```bash pnpm dlx @babelize/elements add locale-picker ```</Tab>
33-
<Tab value="yarn">```bash yarn dlx @babelize/elements add locale-picker ```</Tab>
34-
<Tab value="bun">```bash bunx @babelize/elements add locale-picker ```</Tab>
56+
<Tab value="npx">
57+
58+
```bash
59+
npx @babelize/elements add locale-picker
60+
```
61+
62+
</Tab>
63+
<Tab value="pnpm">
64+
65+
```bash
66+
pnpm dlx @babelize/elements add locale-picker
67+
```
68+
69+
</Tab>
70+
<Tab value="yarn">
71+
72+
```bash
73+
yarn dlx @babelize/elements add locale-picker
74+
```
75+
76+
</Tab>
77+
<Tab value="bun">
78+
79+
```bash
80+
bunx @babelize/elements add locale-picker
81+
```
82+
83+
</Tab>
3584
</Tabs>
85+
3686
</Tab>
3787
</Tabs>
3888

3989
## Usage
4090

4191
```tsx
4292
import { LocalePicker } from "@/components/ui/locale-picker";
93+
import { regions } from "@/lib/elements-config";
4394
```
4495

4596
```tsx
4697
<LocalePicker
47-
regions={["IN", "US", "GB", "DE", "JP"]}
98+
regions={regions}
4899
defaultValue="en-IN"
49-
onValueChange={(locale) => console.log(locale)}
100+
onValueChange={(locale) => console.log("Selected locale:", locale)}
101+
label="english" // native, english
102+
variant="outline" // outline, ghost, secondary
103+
size="default" // sm, default, lg
50104
/>
51105
```
52106

107+
The sample `regions` list comes from the docs site's `lib/elements-config.ts`;
108+
point it at your own array of ISO 3166-1 alpha-2 codes.
109+
53110
## Props
54111

55-
| Prop | Type | Required | Default | Description |
56-
| --------------- | -------------------------- | -------- | ------------------- | -------------------------------------------------------------- |
57-
| `regions` | `string[]` | Yes | — | Regions to choose from, ISO 3166-1 alpha-2 codes |
58-
| `value` | `string` | No | — | Selected locale (BCP 47) — pass this to control the component |
59-
| `defaultValue` | `string` | No | `en-<first region>` | Initial selected locale when uncontrolled |
60-
| `onValueChange` | `(locale: string) => void` | No | — | Callback when the region changes — receives the new BCP 47 tag |
61-
| `label` | `"native" \| "english"` | No | `"english"` | Region names in English, or localized to the selected locale |
62-
| `showFlags` | `boolean` | No | `true` | Show the region's flag emoji next to its name |
63-
| `maxHeight` | `number \| string` | No | `"15rem"` | Max height of the scrolling option list, before it scrolls |
64-
| `className` | `string` | No | — | Additional CSS classes |
112+
| Prop | Type | Required | Default | Description |
113+
| ------------------- | ------------------------------------- | -------- | --------------------- | ------------------------------------------------------------------------------------ |
114+
| `regions` | `string[]` | Yes | — | Regions to choose from, ISO 3166-1 alpha-2 codes |
115+
| `value` | `string` | No | — | Selected locale (BCP 47) — pass this to control the component |
116+
| `defaultValue` | `string` | No | `en-<first region>` | Initial selected locale when uncontrolled |
117+
| `onValueChange` | `(locale: string) => void` | No | — | Callback when the region changes — receives the new BCP 47 tag |
118+
| `label` | `"native" \| "english"` | No | `"english"` | Region names in English, or localized to the selected locale |
119+
| `showFlags` | `boolean` | No | `true` | Show the region's flag emoji next to its name |
120+
| `maxHeight` | `number \| string` | No | `"15rem"` | Max height of the scrolling option list, before it scrolls |
121+
| `variant` | `"outline" \| "ghost" \| "secondary"` | No | `"outline"` | Trigger style |
122+
| `size` | `"sm" \| "default" \| "lg"` | No | `"default"` | Trigger size |
123+
| `align` | `"start" \| "end"` | No | `"start"` | Edge of the trigger the popup lines up with |
124+
| `side` | `"top" \| "bottom"` | No | `"bottom"` | Preferred popup side — flips when the viewport has no room |
125+
| `searchable` | `boolean` | No | `true` | Show the search field |
126+
| `searchPlaceholder` | `string` | No | `"Search regions..."` | Placeholder for the search field |
127+
| `emptyMessage` | `React.ReactNode` | No | `"No results"` | Content shown when the search matches nothing |
128+
| `disabled` | `boolean` | No | `false` | Disable the trigger |
129+
| `classNames` | `LocalePickerClassNames` | No | — | Per-part classes: `trigger`, `content`, `search`, `list`, `item`, `empty`, `summary` |
130+
| `className` | `string` | No | — | Additional CSS classes |
65131

66132
The selected value is a full BCP 47 tag: its **region** subtag is the picked
67133
region, and its **language** subtag survives region changes. Picking Germany
@@ -100,11 +166,13 @@ announced through `aria-activedescendant`.
100166
## Features
101167

102168
- **Derived defaults** — currency, date format, number format, and first day of week, resolved live through `Intl`
103-
- **Dropdown with search** — filter regions by English name, localized name, or code
169+
- **Dropdown with search** — filter regions by English name, localized name, or region code, with a clear button
170+
- **Motion** — the popup fades and slides via `motion/react`, honouring `prefers-reduced-motion`, and leaves the accessibility tree as it closes
104171
- **RTL-aware** — flips direction for RTL locales (ar, he, fa, ur) via `dir` on the root
105172
- **Keyboard accessible** — arrow keys, Home / End, Enter, and Escape navigation
106173
- **ARIA labels** — `role="combobox"` search field with `aria-activedescendant`, plus `aria-expanded`, `aria-haspopup`, and `aria-selected`
107-
- **Dark mode** — built with Tailwind CSS, dark-mode compatible
174+
- **Themed with shadcn tokens** — `bg-popover`, `border-input`, `bg-accent` and friends, so it inherits your theme; dark mode comes from the tokens
175+
- **Customisable** — `variant` / `size` triggers plus per-part `classNames` (`LocalePickerClassNames` is exported from the barrel), with `lucide-react` icons throughout
108176
- **Controlled or uncontrolled** — `value` / `defaultValue` / `onValueChange`
109177

110178
## Examples
@@ -129,6 +197,8 @@ With `de-DE` selected, the trigger reads "Deutschland" and the options read
129197
This component uses:
130198

131199
- `clsx` and `tailwind-merge` (bundled as dependencies)
200+
- `lucide-react` (icons)
201+
- `motion` (popup animation)
132202

133203
Peer dependencies:
134204

‎content/docs/components/meta.json‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"title": "Components",
3-
"pages": [
4-
"language-switchers",
5-
"locale-pickers",
6-
"navigation",
7-
"inputs",
8-
"translation",
9-
"formatters"
10-
],
3+
"pages": ["language-switchers", "locale-pickers", "navigation", "inputs", "translation"],
114
"collapsible": false
125
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
"use client";
22

33
import { LocalePicker } from "@/registry/components/locale-picker";
4+
import { regions } from "@/lib/elements-config";
45

56
export function LocalePickerDemo() {
67
return (
78
<LocalePicker
8-
regions={["IN", "US", "GB", "DE", "JP"]}
9+
regions={regions}
910
defaultValue="en-IN"
10-
onValueChange={(locale) => console.log(locale)}
11+
onValueChange={(locale) => console.log("Selected locale:", locale)}
12+
label="english" // native, english
13+
variant="outline" // outline, ghost, secondary
14+
size="default" // sm, default, lg
1115
/>
1216
);
1317
}

‎src/lib/elements-config.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const pillLocales: Locale[] = [
2121
{ code: "ar", label: "عربي" },
2222
];
2323

24+
/** ISO 3166-1 alpha-2 regions the LocalePicker demo offers. */
25+
export const regions = ["IN", "US", "GB", "DE", "JP"];
26+
2427
/** NavBar links and CTA, translated for every demo locale. */
2528
export const navCopy: Record<string, { links: NavLink[]; cta: string }> = {
2629
en: { links: links("Product", "Docs", "Pricing"), cta: "Get started" },

‎src/registry/components/index.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ export { NavBar } from "./navbar";
2222
export type { NavBarProps, NavBarClassNames, NavLink } from "./navbar";
2323

2424
export { TranslationWidget } from "./translation-widget";
25-
export type { TranslationWidgetProps } from "./translation-widget";
26-
27-
export { LocaleNumber } from "./locale-number";
28-
export type { LocaleNumberProps } from "./locale-number";
29-
30-
export { RelativeTime } from "./relative-time";
31-
export type { RelativeTimeProps } from "./relative-time";
25+
export type { TranslationWidgetProps, TranslationWidgetClassNames } from "./translation-widget";
3226

3327
export { LocalePicker } from "./locale-picker";
34-
export type { LocalePickerProps } from "./locale-picker";
28+
export type { LocalePickerProps, LocalePickerClassNames } from "./locale-picker";

0 commit comments

Comments
 (0)