# Introduction Accessible React components on Base UI and Tailwind CSS. You copy each one into your project with the CLI, and from then on the code is yours to change. ## What it is YolkUI is a personal project, and an exploration more than a product. I wanted to see how far a small set of components could go if every detail got real attention: the focus ring, a disabled button that can still tell you why it's off, a menu that opens on the correct side in Arabic. I share it here in case it helps you too. ## How it works You don't install YolkUI as a package. The CLI copies a component's source into your project, together with any component it builds on, and the file is yours from that moment. Change the markup, the classes or the behavior however you like. Nothing waits upstream to overwrite your edits. The components so far run from [Accordion](https://yolkui.com/docs/components/accordion) to [Tooltip](https://yolkui.com/docs/components/tooltip), and each one has a page with examples you can copy. ```tsx npx @yolkui/cli add button ``` ## What it's built on [Base UI](https://base-ui.com) does the hard part: keyboard support, focus and the ARIA attributes a screen reader needs. Its team has done careful, patient work there, and YolkUI leans on it everywhere. [Tailwind CSS](https://tailwindcss.com) v4 draws the look through a small set of color, radius and type tokens, which [Theming](https://yolkui.com/docs/theming) explains. A component file stands on its own and needs no icon library. ## Works with shadcn/ui I learned a lot from [shadcn/ui](https://ui.shadcn.com), and YolkUI follows its conventions on purpose. The parts, the prop names and the theme tokens match, so a shadcn theme pastes in and shadcn components sit next to these ones. You can even add a YolkUI component with the shadcn CLI. The one difference you'll notice is the radius scale, and [Theming](https://yolkui.com/docs/theming#shadcn-themes) shows how the two line up. ```tsx npx shadcn add https://yolkui.com/r/button.json ``` ## What I check on every component Before a component goes up, it has to do all of this, and [Accessibility](https://yolkui.com/docs/accessibility) covers each check in detail: - Work with a keyboard alone, and say what it is to a screen reader. - Look right in light and dark, with every text color at WCAG AA contrast in both. - Mirror itself in right to left languages such as Arabic and Hebrew. - Stay visible in Windows High Contrast mode. - Keep a disabled control in the Tab order, so a tooltip can explain why it's off. - Pass its own tests, including an automated accessibility check. ## Made to work with AI The code lives in your project, so an AI assistant can read it and change it like any other file. Every page also has a Copy page button that gives you the whole page as Markdown, ready to paste into a chat. AI tools can read [llms.txt](https://yolkui.com/llms.txt), a list of every page, or [llms-full.txt](https://yolkui.com/llms-full.txt), every page in one file. ## Requirements React 19.2 or newer and Tailwind CSS v4, in a Next.js or Vite project. It runs in current versions of Chrome, Edge, Firefox and Safari. [Installation](https://yolkui.com/docs/installation) walks you through the setup. ## Questions ### Is YolkUI free? Yes. YolkUI uses the MIT license, so you can use it in personal and commercial projects. ### Does it work with shadcn/ui? Yes. The theme tokens, parts and prop names match shadcn/ui, so a shadcn theme pastes in and shadcn components sit next to YolkUI ones. [Works with shadcn/ui](#shadcn) has the details. ### Do I need an icon library? No. The few icons a component needs, such as a check mark or a chevron, live inside its file. For your own icons any library works, and the examples use [Lucide](https://lucide.dev). ### How do I get updates? Run the add command again. The CLI asks before it replaces a file you already have, so your own changes stay put until you say yes. ### Can I use it in production? Yes, but read the code before you ship it, since YolkUI is still young. I use it on this site, and every component has its own tests. ## Who makes it I'm [Antoni Botev](https://antonibotev.com), a product designer. I design products full of data and build them in code, and YolkUI is where I try out ideas about components before I use them in real work. You'll find me on [X](https://x.com/Sinote), [GitHub](https://github.com/antonibotev) and [LinkedIn](https://www.linkedin.com/in/antonibotev/). --- # Installation Install YolkUI in a Next.js or Vite project with Tailwind CSS v4. Run init once, then add any component with one command and change its code as you like. ## Requirements React 19.2 or newer, Tailwind CSS v4 and an import alias such as `@/`. YolkUI ships TypeScript files. ## Next.js A new Next.js app comes with Tailwind CSS v4 and the `@/` alias, so `init` needs nothing else. In an existing app, run `init` in its folder. ```bash npx create-next-app@latest my-app --yes cd my-app npx @yolkui/cli init ``` ## Vite Set up Tailwind CSS v4 first with [its Vite guide](https://tailwindcss.com/docs/installation/using-vite). Then add the `@/` alias to `tsconfig.app.json` and `vite.config.ts`, and run `init`. ```tsx // tsconfig.app.json, in compilerOptions "baseUrl": ".", "paths": { "@/*": ["./src/*"] } // vite.config.ts import path from "node:path" export default defineConfig({ plugins: [react(), tailwindcss()], resolve: { alias: { "@": path.resolve(__dirname, "./src") }, }, }) ``` ## What init changes `init` finds your CSS file and your import alias, adds the theme tokens to your CSS, writes `components.json` and adds `cn()` to `lib/utils.ts`. The rest of your CSS stays as it is. [CLI](https://yolkui.com/docs/cli#init) lists every step, and [Theming](https://yolkui.com/docs/theming) explains the tokens. ## Add a component Each component lands in `components/ui`, together with the components it uses. Import it from there, and change the file however you like. Every component page has its own install command, starting with [Button](https://yolkui.com/docs/components/button). ```bash npx @yolkui/cli add button ``` ```tsx import { Button } from "@/components/ui/button" export default function Page() { return } ``` ## Without the CLI Install the two packages `cn()` uses and add it to `lib/utils.ts`. Then paste the [full theme](https://yolkui.com/docs/theming#full-theme) into your CSS file. After that, the Manual tab on each component page lists the packages it needs and the file to copy. ```bash npm install clsx tailwind-merge ``` ```ts import { clsx, type ClassValue } from "clsx"; import { extendTailwindMerge } from "tailwind-merge"; /** * tailwind-merge only knows Tailwind's own font sizes. Our semantic type roles * (`text-label`, `text-h1`, …) look like colours to it, so it drops them the * moment a real colour follows — `cn("text-label", "text-primary-foreground")` * silently returned only the colour. Naming the roles here keeps both. * * Every role added to `@theme` in globals.css must be listed. */ const twMerge = extendTailwindMerge({ extend: { classGroups: { "font-size": [ { text: [ "display", "h1", "h2", "h3", "h4", "h5", "h6", "body-lg", "body", "body-sm", "label", "label-sm", "caption", "overline", "overline-mono", "code", ], }, ], }, }, }); /** Merge class names, letting later Tailwind classes override earlier ones. */ export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } ``` ## Dark mode The dark theme turns on under a `dark` class or `data-theme="dark"` on any parent element, usually ``, so [next-themes](https://github.com/pacocoursey/next-themes) works as it is. Set it before the first paint, or the page flashes light for a moment. --- # Theming Color tokens as CSS variables for light and dark mode, with the contrast of every pair. Change a color, add one, set radius and fonts, or paste a shadcn theme. ## How the colors work Every color comes as a pair: a fill and the text on it, such as `--primary` and `--primary-foreground`. Components use only these names, never a color of their own, so one value changes everything that uses it. Each value points at a color of Tailwind's palette, and the dark theme sets the same names again. `@theme inline` turns each one into a utility, `bg-primary` or `text-primary-foreground`, as [Tailwind's theme variables](https://tailwindcss.com/docs/theme) explain. ```tsx :root { --primary: var(--color-gray-900); --primary-foreground: var(--color-gray-50); } .dark, [data-theme="dark"] { --primary: var(--color-gray-50); --primary-foreground: var(--color-gray-900); } @theme inline { --color-primary: var(--primary); --color-primary-foreground: var(--primary-foreground); } ``` ## Colors Every token, in light and in dark. The number under each swatch is its contrast: text on its fill needs 4.5:1, a focus ring, a field border or a chart mark 3:1 on the page. Every pair passes WCAG AA in both themes, and a test checks it whenever a value changes. Fills also have `-hover`, `-active` and `-separator` states, and a few components have tokens of their own (`--switch-*`, `--segment-*`, `--toggle-active`); they are in the full theme at the end of this page. | Token | Text on it | Used for | | --- | --- | --- | | `--background` | `--foreground` | The page and the text on it. | | `--card` | `--card-foreground` | Card and Alert. A step above the page in dark. | | `--popover` | `--popover-foreground` | Everything that floats: menus, Select, Combobox, Popover, Dialog, Toast. | | `--muted` | `--muted-foreground` | Quiet fills (a read-only field, the Progress track); its text is the secondary text everywhere. | | `--primary` | `--primary-foreground` | The default Button, a checked Checkbox, Radio and Switch, the selected day, the Slider. | | `--secondary` | `--secondary-foreground` | The secondary Button, a neutral Badge, the Avatar fallback. | | `--accent` | `--accent-foreground` | Hover on anything without a fill of its own: outline and ghost buttons, menu items, Toggle. | | `--accent-primary` | `--accent-primary-foreground` | The blue Button (variant="accent"), for an action that should stand out. | | `--soft` | `--soft-foreground` | The raised surface: soft buttons, fields, the selected tab. | | `--brand` | `--brand-foreground` | The Yolk color. Small highlights only, as a fill: as text it is too light. | | `--success` | `--success-foreground` | Done, saved, online. | | `--info` | `--info-foreground` | Something to know, with nothing wrong. | | `--warning` | `--warning-foreground` | Needs attention soon. | | `--destructive` | `--destructive-foreground` | Errors, an invalid field, actions that delete. | | `--success-subtle` | `--success-subtle-foreground` | A quiet tint for dense lists: a subtle Badge, an Alert. | | `--info-subtle` | `--info-subtle-foreground` | The quiet tint of info. | | `--warning-subtle` | `--warning-subtle-foreground` | The quiet tint of warning. | | `--destructive-subtle` | `--destructive-subtle-foreground` | The quiet tint of destructive. | | `--accent-subtle` | `--accent-subtle-foreground` | The quiet tint of the blue. | | `--brand-subtle` | `--brand-subtle-foreground` | The quiet tint of the brand. | | `--border` | | Lines and dividers: separators, Accordion, Tabs. | | `--hairline` | | The 1px edge of cards and popups, translucent so it reads on any fill. | | `--input` | | A field's border in shadcn components; YolkUI fields draw the soft ring instead. | | `--ring` | | The focus outline on every control. | | `--chart-1` | | Series 1, blue. Each hue stands 3:1 off the page. | | `--chart-2` | | Series 2, emerald. Each hue stands 3:1 off the page. | | `--chart-3` | | Series 3, amber. Each hue stands 3:1 off the page. | | `--chart-4` | | Series 4, rose. Each hue stands 3:1 off the page. | | `--chart-5` | | Series 5, violet. Each hue stands 3:1 off the page. | | `--sidebar` | `--sidebar-foreground` | An app sidebar, a step off the page. | | `--sidebar-primary` | `--sidebar-primary-foreground` | The current item. | | `--sidebar-accent` | `--sidebar-accent-foreground` | Hover on an item. | | `--sidebar-border` | | Its edge and dividers. | | `--sidebar-ring` | | Focus inside it. | ## Dark mode The dark theme turns on under a `dark` class or `data-theme="dark"` on any parent element, usually ``, so [next-themes](https://github.com/pacocoursey/next-themes) works as it is. Set it before the first paint, from a small script in ``, or the page flashes light for a moment. ```tsx // next-themes ``` ## A dark section on a light page `data-theme="dark"` works on any element, not only ``: everything inside it takes the dark tokens. YolkUI doesn't support the opposite, a light section on a dark page: components draw some details with Tailwind's `dark:` variant, which follows the dark parent. ```tsx import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" /** A dark section on a light page: data-theme on the section, not on . */ export default function ThemingDarkSection() { return (
New

Dark inside, light around it

Every component in this section takes the dark tokens.

) } ``` ## Radius One value, `--radius`, rounds everything. The steps are Tailwind's, written as multiples of it, so at the default 0.5rem the numbers match Tailwind's docs and a new value re-rounds every component in proportion. | Token | Of --radius | Default | Used for | | --- | --- | --- | --- | | --radius-xs | ×0.25 | 2px | Small marks inside a component | | --radius-sm | ×0.5 | 4px | Menu and list rows, Checkbox, chips | | --radius-md | ×0.75 | 6px | Badge, a Button at xs, Tooltip | | --radius-lg | ×1 | 8px | Button, Input, Select, every popup | | --radius-xl | ×1.5 | 12px | Card, Toast, Toolbar | | --radius-2xl | ×2 | 16px | Dialog, Alert Dialog | | --radius-3xl | ×3 | 24px | — | | --radius-4xl | ×4 | 32px | — | ```tsx :root { --radius: 0.75rem; /* controls 12, cards 18 */ } ``` ## Fonts Components use `font-sans` for text and `font-mono` for code and numbers, never a font's name, so a project keeps its own. Point the two at your fonts in `@theme inline`. ```tsx @theme inline { --font-sans: var(--font-inter); --font-mono: var(--font-geist-mono); } ``` ## Change a color Set the token in both blocks. Here the blue action becomes green. Keep the text on it at 4.5:1: white needs a `-600` or darker step. ```tsx :root { --accent-primary: var(--color-emerald-700); } .dark, [data-theme="dark"] { --accent-primary: var(--color-emerald-600); } ``` ## Add a color Define the pair in both themes, then map it in `@theme inline`. `bg-highlight` and `text-highlight-foreground` work from then on. ```tsx :root { --highlight: var(--color-violet-600); --highlight-foreground: var(--color-white); } .dark, [data-theme="dark"] { --highlight: var(--color-violet-400); --highlight-foreground: var(--color-violet-950); } @theme inline { --color-highlight: var(--highlight); --color-highlight-foreground: var(--highlight-foreground); } ``` ```tsx
New
``` ## Themes from shadcn/ui The token names and meanings are shadcn/ui's, so a [shadcn theme](https://ui.shadcn.com/themes) pastes in over ours and its components drop in. One difference: our radius steps are Tailwind's, so a theme's `--radius: 0.625rem` rounds controls to 10px, and a pasted shadcn component's `rounded-md` comes out 6px beside our 8px controls. ## The full theme Every token above in one file, as the CLI's [init command](https://yolkui.com/docs/cli#init) adds it to your CSS. It leaves the rest of your file as it is. To set it up by hand, follow [Without the CLI](https://yolkui.com/docs/installation#without-the-cli). ```css @import "tailwindcss"; @custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *, .dark, .dark *)); :root, [data-theme="light"] { color-scheme: light; --background: var(--color-white); --foreground: var(--color-gray-950); --card: var(--color-white); --card-foreground: var(--color-gray-950); --popover: var(--color-white); --popover-foreground: var(--color-gray-950); --primary: var(--color-gray-900); --primary-foreground: var(--color-gray-50); --primary-hover: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700)); --primary-active: var(--color-gray-700); --primary-separator: var(--color-gray-700); --secondary: var(--color-gray-100); --secondary-foreground: var(--color-gray-900); --secondary-hover: color-mix(in oklab, var(--color-gray-100) 25%, var(--color-gray-200)); --secondary-active: color-mix(in oklab, var(--color-gray-200), var(--color-gray-300)); --secondary-separator: var(--color-gray-200); --segment-track: var(--secondary); --segment-indicator: var(--soft); --switch-track: var(--border); --switch-ring: var(--hairline); --switch-thumb: var(--soft); --switch-thumb-checked: var(--soft); --switch-thumb-ring: var(--soft-ring-hover); --switch-thumb-edge: var(--soft-edge-hover); --switch-track-hover: var(--color-gray-300); --switch-track-active: color-mix(in oklab, var(--color-gray-300), var(--color-gray-400)); --switch-on-hover: var(--primary-active); --switch-on-active: color-mix(in oklab, var(--color-gray-700), var(--color-gray-600)); --toggle-active: var(--color-gray-300); --accent: var(--color-gray-100); --accent-foreground: var(--color-gray-950); --accent-active: color-mix(in oklab, var(--color-gray-100) 40%, var(--color-gray-200)); --muted: var(--color-gray-100); --muted-foreground: var(--color-gray-600); --accent-primary: var(--color-blue-700); --accent-primary-foreground: var(--color-white); --accent-primary-hover: color-mix(in oklab, var(--color-blue-700), var(--color-blue-800)); --accent-primary-active: var(--color-blue-800); --accent-soft-ring: --alpha(var(--color-blue-950) / 50%); --accent-soft-edge: --alpha(var(--color-blue-950) / 75%); --accent-primary-separator: --alpha(var(--color-white) / 15%); --brand: var(--color-amber-500); --brand-foreground: var(--color-gray-950); --brand-hover: color-mix(in oklab, var(--color-amber-500), var(--color-amber-400)); --brand-active: var(--color-amber-400); --brand-soft-ring: var(--soft-ring); --brand-soft-edge: var(--soft-edge); --brand-separator: var(--brand-soft-ring); --destructive: var(--color-rose-700); --destructive-foreground: var(--color-white); --destructive-hover: color-mix(in oklab, var(--color-rose-700), var(--color-rose-800)); --destructive-active: var(--color-rose-800); --destructive-separator: var(--color-rose-600); --success: var(--color-emerald-700); --success-foreground: var(--color-white); --success-hover: color-mix(in oklab, var(--color-emerald-700), var(--color-emerald-800)); --warning: var(--color-orange-500); --warning-foreground: var(--color-orange-950); --warning-hover: color-mix(in oklab, var(--color-orange-500), var(--color-orange-400)); --info: var(--color-indigo-600); --info-foreground: var(--color-white); --info-hover: color-mix(in oklab, var(--color-indigo-600), var(--color-indigo-700)); --brand-subtle: var(--color-amber-100); --brand-subtle-foreground: var(--color-amber-900); --success-subtle: var(--color-emerald-100); --success-subtle-foreground: var(--color-emerald-800); --warning-subtle: var(--color-orange-100); --warning-subtle-foreground: var(--color-orange-800); --info-subtle: var(--color-indigo-100); --info-subtle-foreground: var(--color-indigo-800); --destructive-subtle: var(--color-rose-100); --destructive-subtle-foreground: var(--color-rose-800); --accent-subtle: var(--color-blue-100); --accent-subtle-foreground: var(--color-blue-800); --border: var(--color-gray-200); --outline-border: var(--border); --outline-fill: var(--background); --outline-fill-active: var(--accent-active); --input: var(--color-gray-500); --ring: var(--color-gray-900); --soft: var(--color-white); --soft-foreground: var(--color-gray-800); --soft-hover: color-mix(in oklab, var(--color-gray-50), var(--color-gray-100)); --soft-active: color-mix(in oklab, var(--color-gray-100), var(--color-gray-200)); --soft-edge: --alpha(var(--color-gray-950) / 16%); --soft-edge-offset: -1px; --soft-ring: --alpha(var(--color-gray-950) / 15%); --soft-lift: --alpha(var(--color-gray-950) / 4%); --soft-ring-hover: --alpha(var(--color-gray-950) / 22%); --soft-edge-hover: --alpha(var(--color-gray-950) / 22%); --input-action: color-mix(in oklab, var(--color-gray-400), var(--color-gray-500)); --hairline: --alpha(var(--color-gray-950) / 12%); --popover-shadow: 0 12px 28px -4px --alpha(var(--color-gray-900) / 12%), 0 2px 6px -1px --alpha(var(--color-gray-900) / 6%); --dialog-shadow: 0 16px 40px -8px --alpha(var(--color-gray-900) / 20%), 0 2px 6px -1px --alpha(var(--color-gray-900) / 6%); --chart-1: var(--color-blue-600); --chart-2: var(--color-emerald-600); --chart-3: var(--color-amber-600); --chart-4: var(--color-rose-600); --chart-5: var(--color-violet-600); --sidebar: var(--color-gray-50); --sidebar-foreground: var(--color-gray-950); --sidebar-primary: var(--color-gray-900); --sidebar-primary-foreground: var(--color-gray-50); --sidebar-accent: var(--color-gray-100); --sidebar-accent-foreground: var(--color-gray-900); --sidebar-border: var(--color-gray-200); --sidebar-ring: var(--color-gray-900); --radius: 0.5rem; } .dark, [data-theme="dark"] { color-scheme: dark; --background: var(--color-gray-950); --foreground: var(--color-gray-50); --card: var(--color-gray-900); --card-foreground: var(--color-gray-50); --popover: var(--color-gray-900); --popover-foreground: var(--color-gray-50); --primary: var(--color-gray-50); --primary-foreground: var(--color-gray-900); --primary-hover: color-mix(in oklab, var(--color-gray-200), var(--color-gray-300)); --primary-active: color-mix(in oklab, var(--color-gray-300), var(--color-gray-400)); --primary-separator: var(--color-gray-200); --secondary: color-mix(in oklab, var(--color-gray-900), var(--color-gray-800)); --secondary-foreground: var(--color-gray-50); --secondary-hover: var(--color-gray-800); --secondary-active: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700)); --secondary-separator: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700)); --segment-track: var(--muted); --segment-indicator: color-mix(in oklab, var(--muted), var(--soft-active)); --switch-ring: color-mix(in oklab, var(--soft-ring) 70%, transparent); --switch-thumb: var(--color-gray-600); --switch-thumb-checked: var(--primary-foreground); --switch-thumb-ring: var(--soft-ring-hover); --switch-thumb-edge: --alpha(var(--color-white) / 20%); --switch-track-hover: var(--secondary-active); --switch-track-active: var(--soft-active); --switch-on-hover: var(--primary-hover); --switch-on-active: var(--primary-active); --toggle-active: var(--soft-active); --accent: color-mix(in oklab, var(--color-gray-900), var(--color-gray-800)); --accent-foreground: var(--color-gray-50); --accent-active: var(--color-gray-800); --muted: var(--color-gray-800); --muted-foreground: var(--color-gray-400); --accent-primary: var(--color-blue-600); --accent-primary-foreground: var(--color-white); --accent-primary-hover: color-mix(in oklab, var(--color-blue-600), var(--color-blue-700)); --accent-primary-active: var(--color-blue-700); --accent-soft-ring: --alpha(var(--color-white) / 15%); --accent-soft-edge: --alpha(var(--color-white) / 10%); --brand-soft-ring: --alpha(var(--color-white) / 32%); --brand-soft-edge: --alpha(var(--color-white) / 20%); --destructive: var(--color-rose-400); --destructive-foreground: var(--color-rose-950); --destructive-hover: color-mix(in oklab, var(--color-rose-400), var(--color-rose-300)); --destructive-active: var(--color-rose-300); --success: var(--color-emerald-400); --success-foreground: var(--color-emerald-950); --success-hover: color-mix(in oklab, var(--color-emerald-400), var(--color-emerald-300)); --warning: var(--color-orange-400); --warning-foreground: var(--color-orange-950); --warning-hover: color-mix(in oklab, var(--color-orange-400), var(--color-orange-300)); --info: var(--color-indigo-400); --info-foreground: var(--color-indigo-950); --info-hover: color-mix(in oklab, var(--color-indigo-400), var(--color-indigo-300)); --brand-subtle: var(--color-amber-950); --brand-subtle-foreground: var(--color-amber-300); --success-subtle: var(--color-emerald-950); --success-subtle-foreground: var(--color-emerald-300); --warning-subtle: var(--color-orange-950); --warning-subtle-foreground: var(--color-orange-300); --info-subtle: var(--color-indigo-950); --info-subtle-foreground: var(--color-indigo-300); --destructive-subtle: var(--color-rose-950); --destructive-subtle-foreground: var(--color-rose-300); --accent-subtle: var(--color-blue-950); --accent-subtle-foreground: var(--color-blue-300); --border: var(--color-gray-800); --outline-border: var(--secondary-separator); --outline-fill: transparent; --outline-fill-active: var(--secondary-active); --input: var(--color-gray-500); --ring: var(--color-gray-300); --soft: var(--color-gray-800); --soft-foreground: var(--color-gray-200); --soft-hover: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700)); --soft-active: var(--color-gray-700); --soft-edge: --alpha(var(--color-white) / 14%); --soft-edge-offset: 1px; --soft-ring: --alpha(var(--color-white) / 11%); --soft-lift: --alpha(var(--color-black) / 30%); --soft-ring-hover: --alpha(var(--color-white) / 19%); --soft-edge-hover: --alpha(var(--color-white) / 12%); --hairline: --alpha(var(--color-white) / 14%); --popover-shadow: 0 12px 32px -6px --alpha(var(--color-black) / 50%); --dialog-shadow: 0 16px 48px -8px --alpha(var(--color-black) / 60%); --chart-1: var(--color-blue-400); --chart-2: var(--color-emerald-400); --chart-3: var(--color-amber-400); --chart-4: var(--color-rose-400); --chart-5: var(--color-violet-400); --sidebar: var(--color-gray-900); --sidebar-foreground: var(--color-gray-50); --sidebar-primary: var(--color-gray-50); --sidebar-primary-foreground: var(--color-gray-900); --sidebar-accent: var(--color-gray-800); --sidebar-accent-foreground: var(--color-gray-50); --sidebar-border: var(--color-gray-800); --sidebar-ring: var(--color-gray-300); } @theme inline { --color-background: var(--background); --color-foreground: var(--foreground); --color-card: var(--card); --color-card-foreground: var(--card-foreground); --color-popover: var(--popover); --color-popover-foreground: var(--popover-foreground); --color-primary: var(--primary); --color-primary-foreground: var(--primary-foreground); --color-primary-hover: var(--primary-hover); --color-primary-active: var(--primary-active); --color-primary-separator: var(--primary-separator); --color-secondary: var(--secondary); --color-secondary-foreground: var(--secondary-foreground); --color-secondary-hover: var(--secondary-hover); --color-secondary-active: var(--secondary-active); --color-secondary-separator: var(--secondary-separator); --color-accent: var(--accent); --color-accent-foreground: var(--accent-foreground); --color-accent-active: var(--accent-active); --color-muted: var(--muted); --color-muted-foreground: var(--muted-foreground); --color-accent-primary: var(--accent-primary); --color-accent-primary-foreground: var(--accent-primary-foreground); --color-accent-primary-hover: var(--accent-primary-hover); --color-accent-primary-active: var(--accent-primary-active); --color-accent-soft-ring: var(--accent-soft-ring); --color-accent-soft-edge: var(--accent-soft-edge); --color-accent-primary-separator: var(--accent-primary-separator); --color-brand: var(--brand); --color-brand-foreground: var(--brand-foreground); --color-brand-hover: var(--brand-hover); --color-brand-active: var(--brand-active); --color-brand-soft-ring: var(--brand-soft-ring); --color-brand-soft-edge: var(--brand-soft-edge); --color-brand-separator: var(--brand-separator); --color-destructive: var(--destructive); --color-destructive-foreground: var(--destructive-foreground); --color-destructive-hover: var(--destructive-hover); --color-destructive-active: var(--destructive-active); --color-destructive-separator: var(--destructive-separator); --color-success: var(--success); --color-success-foreground: var(--success-foreground); --color-success-hover: var(--success-hover); --color-warning: var(--warning); --color-warning-foreground: var(--warning-foreground); --color-warning-hover: var(--warning-hover); --color-info: var(--info); --color-info-foreground: var(--info-foreground); --color-info-hover: var(--info-hover); --color-brand-subtle: var(--brand-subtle); --color-brand-subtle-foreground: var(--brand-subtle-foreground); --color-success-subtle: var(--success-subtle); --color-success-subtle-foreground: var(--success-subtle-foreground); --color-warning-subtle: var(--warning-subtle); --color-warning-subtle-foreground: var(--warning-subtle-foreground); --color-info-subtle: var(--info-subtle); --color-info-subtle-foreground: var(--info-subtle-foreground); --color-destructive-subtle: var(--destructive-subtle); --color-destructive-subtle-foreground: var(--destructive-subtle-foreground); --color-accent-subtle: var(--accent-subtle); --color-accent-subtle-foreground: var(--accent-subtle-foreground); --color-border: var(--border); --color-outline-border: var(--outline-border); --color-segment-track: var(--segment-track); --color-segment-indicator: var(--segment-indicator); --color-switch-track: var(--switch-track); --color-switch-ring: var(--switch-ring); --color-switch-thumb: var(--switch-thumb); --color-switch-thumb-checked: var(--switch-thumb-checked); --color-toggle-active: var(--toggle-active); --color-outline-fill: var(--outline-fill); --color-outline-fill-active: var(--outline-fill-active); --color-input: var(--input); --color-ring: var(--ring); --color-soft: var(--soft); --color-soft-foreground: var(--soft-foreground); --color-soft-hover: var(--soft-hover); --color-soft-active: var(--soft-active); --color-soft-edge: var(--soft-edge); --color-soft-lift: var(--soft-lift); --color-soft-ring: var(--soft-ring); --color-soft-ring-hover: var(--soft-ring-hover); --color-soft-edge-hover: var(--soft-edge-hover); --color-input-action: var(--input-action); --color-hairline: var(--hairline); --color-chart-1: var(--chart-1); --color-chart-2: var(--chart-2); --color-chart-3: var(--chart-3); --color-chart-4: var(--chart-4); --color-chart-5: var(--chart-5); --color-sidebar: var(--sidebar); --color-sidebar-foreground: var(--sidebar-foreground); --color-sidebar-primary: var(--sidebar-primary); --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); --color-sidebar-accent: var(--sidebar-accent); --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); --color-sidebar-border: var(--sidebar-border); --color-sidebar-ring: var(--sidebar-ring); --shadow-soft: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge), inset 0 0 0 1px var(--soft-ring); --shadow-accent-soft: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--accent-soft-edge), inset 0 0 0 1px var(--accent-soft-ring); --shadow-brand-soft: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--brand-soft-edge), inset 0 0 0 1px var(--brand-soft-ring); --shadow-soft-hover: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge-hover), inset 0 0 0 1px var(--soft-ring-hover); --shadow-soft-invalid: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge), inset 0 0 0 1px var(--destructive); --shadow-soft-invalid-hover: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge-hover), inset 0 0 0 1px var(--destructive); --radius-xs: calc(var(--radius) * 0.25); --radius-sm: calc(var(--radius) * 0.5); --radius-md: calc(var(--radius) * 0.75); --radius-lg: var(--radius); --radius-xl: calc(var(--radius) * 1.5); --radius-2xl: calc(var(--radius) * 2); --radius-3xl: calc(var(--radius) * 3); --radius-4xl: calc(var(--radius) * 4); --text-display: var(--text-5xl); --text-display--line-height: 3.25rem; --text-display--font-weight: var(--font-weight-bold); --text-display--letter-spacing: var(--tracking-tight); --text-h1: var(--text-4xl); --text-h1--line-height: var(--text-4xl--line-height); --text-h1--font-weight: var(--font-weight-bold); --text-h1--letter-spacing: var(--tracking-tight); --text-h2: var(--text-3xl); --text-h2--line-height: var(--text-3xl--line-height); --text-h2--font-weight: var(--font-weight-semibold); --text-h2--letter-spacing: var(--tracking-tight); --text-h3: var(--text-2xl); --text-h3--line-height: var(--text-2xl--line-height); --text-h3--font-weight: var(--font-weight-semibold); --text-h4: var(--text-xl); --text-h4--line-height: var(--text-xl--line-height); --text-h4--font-weight: var(--font-weight-semibold); --text-h5: var(--text-lg); --text-h5--line-height: var(--text-lg--line-height); --text-h5--font-weight: var(--font-weight-semibold); --text-h6: var(--text-base); --text-h6--line-height: var(--text-base--line-height); --text-h6--font-weight: var(--font-weight-semibold); --text-body-lg: var(--text-lg); --text-body-lg--line-height: var(--text-lg--line-height); --text-body: var(--text-base); --text-body--line-height: var(--text-base--line-height); --text-body-sm: var(--text-sm); --text-body-sm--line-height: var(--text-sm--line-height); --text-label: var(--text-sm); --text-label--line-height: var(--text-sm--line-height); --text-label--font-weight: var(--font-weight-medium); --text-label-sm: var(--text-xs); --text-label-sm--line-height: var(--text-xs--line-height); --text-label-sm--font-weight: var(--font-weight-medium); --text-caption: var(--text-xs); --text-caption--line-height: var(--text-xs--line-height); --text-overline: var(--text-xs); --text-overline--line-height: var(--text-xs--line-height); --text-overline--font-weight: var(--font-weight-semibold); --text-overline--letter-spacing: 0.06em; --text-overline-mono: var(--text-xs); --text-overline-mono--line-height: var(--text-xs--line-height); --text-overline-mono--font-weight: var(--font-weight-normal); --text-overline-mono--letter-spacing: 0.06em; --text-code: var(--text-sm); --text-code--line-height: var(--text-sm--line-height); --font-sans: var(--font-inter); --font-mono: var(--font-paper-mono); } @utility text-overline-mono { font-family: var(--font-mono); text-transform: uppercase; } @layer base { * { @apply border-border outline-ring; } body { @apply bg-background text-foreground font-sans; } } ``` --- # Accessibility How YolkUI components work with a keyboard, screen readers, WCAG AA contrast, right to left and Windows High Contrast, how I test them, and the known gaps. ## What you get YolkUI builds on [Base UI](https://base-ui.com/react/overview/accessibility), which handles the parts that are hardest to get right: ARIA roles and states, keyboard support from the [WAI-ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/), and focus that moves where it should. On top of that, every component goes through the checks on this page before it goes up. Nothing here is a certification, and I list the gaps I know about near the end. ## Keyboard and screen readers Every component works with a keyboard alone and tells a screen reader what it is, what state it's in and what it's called. A test runs each example on these pages through the WAI-ARIA pattern of every widget it holds: the roles, the Tab stops and the arrow keys. In development, a component warns in the console when nothing gives it a name. ## Focus Focus shows as a 2px outline in `--ring`, 2px away from the control, and it appears at once rather than fading in. It's an outline, not a box shadow, because Windows High Contrast mode removes shadows and the focus would vanish with them. ## Contrast Every text color passes WCAG AA, 4.5:1 on its fill, in light and in dark. Focus outlines, chart colors and other marks that must stand out from the page pass 3:1. A test reads the theme and checks every pair whenever a value changes, and [Theming](https://yolkui.com/docs/theming#colors) shows each number. ## Disabled controls A disabled button, checkbox, tab or menu item stays in the Tab order with `aria-disabled`, so a keyboard user can still reach it and a tooltip can say why it's off. It fades to 60% and still responds to hover, so the tooltip opens. Input, Native Select, Combobox and Slider use the browser's own disabled state instead, which Tab skips, so their pages put the reason in a FieldDescription, where everyone can read it. ## Color is never the only signal Each status has words or an icon as well as a color. An invalid field shows its error message, an Alert and a Toast draw an icon for their type, and a Badge says what it means in its label. ## Windows High Contrast In forced colors mode the system replaces every color. Components draw a border wherever their edge was a fill or a shadow, mark the selected item in the system's highlight color, and use the system's gray for disabled controls in place of the fade. ## Right to left Components use logical properties (start and end, never left and right), so they mirror themselves for Arabic, Hebrew and Persian. Arrow keys and popups follow Base UI's DirectionProvider, so wrap your app in it beside `dir="rtl"`. ```tsx import { DirectionProvider } from "@base-ui/react/direction-provider" export default function App({ children }) { return (
{children}
) } ``` ## Reduced motion When the system asks for reduced motion, popups fade without the zoom, the selection in Tabs and Segmented Control moves without sliding, and a loading spinner turns more slowly. ## Phones and touch Text in a field is 16px on small screens, so iOS Safari doesn't zoom in when you tap it. Hover colors only apply on devices that can hover, so a tap never leaves a control lit. ## How I test Every component runs through these before it goes up, and again on every change: - **axe** on every component. - **WAI-ARIA patterns** for every example: roles, names, Tab stops and arrow keys. - **Right to left:** every horizontal widget pressed in both directions, ArrowLeft in RTL against ArrowRight in LTR. - **Contrast** of every color pair in both themes, read from the theme file. - **Server rendering:** every example rendered on a server and hydrated in a browser with another locale and time zone, with no mismatch. - **Browsers:** Playwright in Chromium, Firefox, WebKit and an iPhone profile for the first components, Windows High Contrast emulated in Chromium. - **VoiceOver with Safari,** by hand, for several components so far. ## Known gaps Where YolkUI falls short today: - The soft ring around a field and the selected state in Tabs, Toggle and Pagination are about 1.2:1 against the page, under the 3:1 that WCAG 1.4.11 asks for. shadcn/ui makes the same trade. A project that needs strict compliance can raise `--input` and the selected fills in its theme. - I haven't checked NVDA or JAWS on Windows yet, and VoiceOver hasn't covered every component. - The newer components don't have browser tests yet. A full pass across browsers and real devices comes before version 1.0. ## Your part A component can only be as accessible as the content you give it: - Give every field a label, with [Field](https://yolkui.com/docs/components/field) or [Label](https://yolkui.com/docs/components/label). - Give an icon-only button an `aria-label`. - Write alt text for images that carry meaning, and `alt=""` for decoration. - If you change a color token, check its text still reaches 4.5:1 in both themes. - Keep the focus outline. If you restyle it, keep it visible and keep it an outline. - When a control is disabled, say why, in a tooltip or a description. --- # CLI The YolkUI CLI sets up your project and copies components into it. Three commands, init, add and list, plus options for CI, AI agents and other registries. ## init Sets up YolkUI in your project. It checks for React, Tailwind CSS v4, a CSS file that imports Tailwind and an import alias such as `@/`, and stops with a message if one is missing. Then it writes `components.json`, adds the theme tokens to your CSS and adds `cn()` to `lib/utils.ts`. If `components.json` is already there, `init` uses its paths. ```bash npx @yolkui/cli init ``` ## add Copies one or more components into your project, together with the components they use, and installs their npm packages with the package manager your lockfile names. It never replaces a file you already have unless you say yes. If your CSS sets some tokens to other values, `add` asks once whether to use the YolkUI values. It leaves the rest of the file as it is. In a project without `components.json`, `add` offers to run `init` first. ```bash npx @yolkui/cli add button input tooltip ``` ## list Shows every component with one line about it. ```bash npx @yolkui/cli list ``` ## Options Every command takes these. | Option | What it does | | --- | --- | | -y, --yes | Takes the default answer to every question: keeps the files you already have and uses the YolkUI token values. | | -o, --overwrite | Replaces files that already exist and differ. | | --no-install | Prints the install command instead of running it. | | --cwd | Runs in another folder. The default is the current one. | | --registry | Reads another registry, such as a local copy. The default is `https://yolkui.com/r`. | | -h, --help | Shows the commands and options. | | -v, --version | Shows the version. | ## In CI and with AI agents Without a terminal to ask in, the CLI takes the default answer to each question, the same as `--yes`: it keeps the component files you already have and uses the YolkUI token values in your CSS. It prints each file it created, kept or updated, so a script or an AI agent can see what changed. ```bash npx @yolkui/cli add dialog --yes ``` ## components.json The CLI reads its paths from `components.json`, the file other registry CLIs read too, so a project keeps one set. Change the aliases there to put components somewhere else, and the CLI rewrites their imports to match. ```tsx { "tailwind": { "css": "app/globals.css" }, "aliases": { "components": "@/components", "ui": "@/components/ui", "utils": "@/lib/utils", "lib": "@/lib" } } ``` ## Registry Every component is also a JSON file in the public registry item format, at `yolkui.com/r/.json`, so any client that reads that format can install it, the shadcn CLI included. ```bash npx shadcn add https://yolkui.com/r/button.json ``` ## When something goes wrong The CLI stops before it writes anything and says what is missing. The usual causes: - **No package.json:** run the command in your project's folder, or pass `--cwd`. - **No Tailwind CSS, or Tailwind CSS v3:** YolkUI needs Tailwind CSS v4. Its [upgrade guide](https://tailwindcss.com/docs/upgrade-guide) moves a v3 project across. - **No CSS file imports Tailwind:** add `@import "tailwindcss"` to your main CSS file and run `init` again. - **No import alias found:** add `"paths": { "@/*": ["./*"] }` to `tsconfig.json` (or `./src/*` in a Vite project) and run `init` again. - **Installing failed:** the CLI prints the install command, so you can run it yourself. --- # All components Every YolkUI component on one page: buttons, form controls, menus, dialogs, navigation and feedback, each built on Base UI and styled with Tailwind CSS v4. - [Accordion](https://yolkui.com/docs/components/accordion): Headings that each open the section under them: questions and answers, settings, filters. - [Alert](https://yolkui.com/docs/components/alert): A message in the page, where it applies: a notice, a success, a warning or an error, with buttons and a close. - [Alert Dialog](https://yolkui.com/docs/components/alert-dialog): Asks before something that cannot be undone; a click outside never closes it. - [Avatar](https://yolkui.com/docs/components/avatar): A photo with initials as the fallback, a status badge and overlapping groups. - [Badge](https://yolkui.com/docs/components/badge): A status or category label in solid, subtle, outline or dot emphasis. - [Breadcrumb](https://yolkui.com/docs/components/breadcrumb): The path from the top of a site to the current page, each step a link back. - [Button](https://yolkui.com/docs/components/button): A button or a link styled as one, with sizes, variants, icons and a loading state that keeps its width. - [Button Group](https://yolkui.com/docs/components/button-group): Joins buttons and fields into one control, with separators that match each button. - [Calendar](https://yolkui.com/docs/components/calendar): A month of days to pick a date or a range, with days that cannot be picked. - [Card](https://yolkui.com/docs/components/card): A container with header, content and footer that share one edge. - [Checkbox](https://yolkui.com/docs/components/checkbox): An on/off choice, mixed for a parent over a group. - [Combobox](https://yolkui.com/docs/components/combobox): A field you type into to filter a list, with chips for several values. - [Context Menu](https://yolkui.com/docs/components/context-menu): A menu of actions on whatever was right-clicked or long-pressed. - [Dialog](https://yolkui.com/docs/components/dialog): A window over the page that holds focus until it closes: a form, a confirmation, details. - [Dropdown Menu](https://yolkui.com/docs/components/dropdown-menu): A menu of actions opened from a button: icons, shortcuts, check and radio items, submenus. - [Field](https://yolkui.com/docs/components/field): Label, description and error message wired to a field, and a fieldset with its legend. - [Input](https://yolkui.com/docs/components/input): Text, password, search and file fields in four sizes. - [Input Group](https://yolkui.com/docs/components/input-group): The field surface: an input with text, icons or buttons at either end. - [Label](https://yolkui.com/docs/components/label): A plain label for a control outside a Field. - [Native Select](https://yolkui.com/docs/components/native-select): The browser's own select, styled: the system's list on every device. - [Navigation Menu](https://yolkui.com/docs/components/navigation-menu): The row of links at the top of a site; some items open a panel of more links. - [Pagination](https://yolkui.com/docs/components/pagination): Links to the pages of a long list: Previous, the page numbers, Next. - [Popover](https://yolkui.com/docs/components/popover): A small panel opened from a button: a short form, settings or a date picker, with the page usable around it. - [Progress](https://yolkui.com/docs/components/progress): How much of a task is done, as a bar with a label and a value; a sliding piece when nobody knows how long. - [Radio Group](https://yolkui.com/docs/components/radio-group): One choice from a short list, named by a legend. - [Segmented Control](https://yolkui.com/docs/components/segmented-control): Picks one value from a few and is never empty; the selection slides between equal-width items. - [Select](https://yolkui.com/docs/components/select): Picks one value from a list that opens over the trigger, the chosen item in place. - [Slider](https://yolkui.com/docs/components/slider): A value picked by dragging along a line: one thumb for a number, two for a range. - [Switch](https://yolkui.com/docs/components/switch): A setting that turns on or off and takes effect at once. - [Tabs](https://yolkui.com/docs/components/tabs): Switches the panel below it; each tab hugs its label and the selection slides between them. - [Textarea](https://yolkui.com/docs/components/textarea): A multi-line field that grows with its content. - [Toast](https://yolkui.com/docs/components/toast): A short message at the edge of the screen that leaves by itself: saved, sent, failed, undo. - [Toggle](https://yolkui.com/docs/components/toggle): A button that stays pressed: bold in a toolbar, a pinned item, a filter. - [Toggle Group](https://yolkui.com/docs/components/toggle-group): Toggles that work as one: one tab stop, arrow keys between items, one or several on. - [Toolbar](https://yolkui.com/docs/components/toolbar): Buttons, toggles and toggle groups in one row: one tab stop, arrow keys across them all. - [Tooltip](https://yolkui.com/docs/components/tooltip): A short description of a control, on hover and on keyboard focus. --- # Accordion Headings that each open the section under them: questions and answers, settings, filters. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" /** Questions and answers: one section open at a time, the first open to start with. */ export default function AccordionDemo() { return ( How long does shipping take? Orders leave our warehouse the next working day and arrive in three to five working days. What is your return policy? Send anything back within 30 days of delivery, unused and in its box, for a full refund. How do I reach support? Write to us from the Help page in your account. We answer within one working day. ) } ``` ## Installation ```bash npx @yolkui/cli add accordion ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/accordion.tsx. ## Usage For several sections a reader opens one at a time: questions and answers, settings, filters. For views of the same content side by side, use Tabs; for a small panel over the page, a Popover. Each AccordionItem holds an AccordionTrigger, the heading, and an AccordionContent, its section. One section is open at a time; defaultValue (an array of item values) opens some to start with, and value with onValueChange controls them from the page. A line separates the sections and there is no box, so it sits in a page, a card or a popover as text does. - The heading is a real heading (h3 by default). Set headingLevel on AccordionTrigger to fit the page's outline, as headingLevel={4} inside a Card with an h3 title. - Links in a section are underlined; paragraphs are 16 apart. - For a single section that shows and hides on its own, a button and a panel are enough; for views of the same content side by side, use Tabs. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" How long does shipping take? Three to five working days. ``` ## Composition ```text Accordion └── AccordionItem ├── AccordionTrigger └── AccordionContent ``` ## Examples ### Several open at once With multiple, opening one section leaves the others as they are: settings, filters, anything a person compares. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" /** With multiple, opening one section leaves the others as they are. */ export default function AccordionMultiple() { return ( Notifications

Email for mentions and replies, a weekly summary on Mondays.

Push notifications are off on this device.

Privacy Your profile is visible to members of your workspace only. Signed-in devices MacBook Pro, Safari, last active today. iPhone 15, last active yesterday.
) } ``` ### Disabled disabled on an AccordionItem keeps its section closed. The heading fades and stays focusable, so wrap it in a Tooltip that says why; disabled on the Accordion turns off every section. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" /** * A disabled section fades to 60% and does not open, but its heading keeps focus * (aria-disabled), so Tab still reaches it and a screen reader says it is dimmed. A * Tooltip around it says why, on hover and on focus. */ export default function AccordionDisabled() { return ( Plan and billing Pro plan, billed yearly. Next invoice on 1 March. }>Single sign-on Available on the Business plan Connect your identity provider with SAML. Export data Download every project as a ZIP of JSON files. ) } ``` ### In a box For a busy page, give the Accordion a border, a radius and some padding: className="rounded-lg border border-border px-4". ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" /** A box around it, for a busy page: a border and radius on the Accordion, padding inside. */ export default function AccordionBorders() { return ( How does billing work? You are billed at the start of each month for the seats in your workspace. Can I change the number of seats? Yes. Added seats are charged for the rest of the month; removed ones are credited. How do I cancel? From Settings, Billing. Your workspace stays open until the end of the paid month. ) } ``` ### In a Card In a Card the accordion needs nothing extra: the card's edge is the only box. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" /** In a Card it has no box of its own, so the card's edge is the only one. */ export default function AccordionCard() { return ( }>Frequently asked About your subscription. Is there a free trial? Fourteen days on any plan, no card needed. Can I upgrade later? Any time. You pay the difference for the rest of the billing period. ) } ``` ### Found by the browser's search hiddenUntilFound keeps closed sections in the page, hidden until found: the browser's find (Ctrl+F or Cmd+F) searches them and opens the one with the match, and search engines read them. Browsers that do not support it keep them closed until opened. ```tsx import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" /** * hiddenUntilFound keeps closed sections in the page as hidden="until-found": the * browser's find (Ctrl+F or Cmd+F) searches them and opens the one that matches, and * search engines index them. Try "restocking". */ export default function AccordionFind() { return ( Can I exchange an item? Yes, for another size or color within 30 days. Are there any fees? Returns are free. Large items carry a restocking fee of 10%. ) } ``` ### Right to left In a right-to-left page the heading starts on the right and the chevron sits on the left, on their own. ```tsx import { DirectionProvider } from "@base-ui/react/direction-provider" import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion" /** Right to left: the heading starts on the right and the chevron sits on the left, on their own (logical properties). */ export default function AccordionRtl() { return (
{/* How long does shipping take? / Three to five working days. */} كم يستغرق الشحن؟ من ثلاثة إلى خمسة أيام عمل. {/* What is your return policy? / Within 30 days, for a full refund. */} ما هي سياسة الإرجاع؟ خلال 30 يومًا من الاستلام، مع استرداد كامل المبلغ.
) } ``` ## API Reference Our additions on top of Base UI's Accordion (value, defaultValue, onValueChange, multiple, disabled, hiddenUntilFound, keepMounted and the rest work as in Base UI). | Prop | On | Values | Default | | --- | --- | --- | --- | | headingLevel | `AccordionTrigger` | `2` · `3` · `4` · `5` · `6` | `3` | | className | `AccordionContent` | goes on the inner box that holds the text and its padding | — | ## Accessibility Each heading is a button inside a heading, which says whether its section is open; the section is a region named by its heading. Screen readers list the headings with the rest of the page's. - Every heading is its own Tab stop; Enter and Space open and close it. Arrow keys do not move between headings, as the WAI-ARIA accordion pattern now says. - A disabled heading stays focusable and is announced as dimmed, so a Tooltip can explain it. - Each open section is a region, a landmark screen readers list. When many sections can be open at once (multiple, more than about six), give AccordionContent role="group" so the landmark list stays short. - The section slides open in 150ms, and at once when the system asks for reduced motion. - Color is never the only sign: the chevron turns with the section, and the screen reader hears expanded or collapsed. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the next heading. | | Shift + Tab | Moves to the previous heading. | | Enter · Space | Opens or closes the focused heading's section. | --- # Alert A message in the page, where it applies: a notice, a success, a warning or an error, with buttons and a close. ```tsx import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" export default function AlertDemo() { return ( Your trial ends in 3 days Add a card to keep your projects and everyone on your team. ) } ``` ## Installation ```bash npx @yolkui/cli add alert ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/alert.tsx. ## Usage A message about this part of the page that stays until it is dealt with: a notice, a success, a warning, an error. For a passing message use a Toast; for a question that must be answered first, an Alert Dialog; for an error on one field, its FieldError. ```tsx import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" Your trial ends in 3 days Add a payment method to keep your projects. ``` ## Composition ```text Alert ├── AlertTitle ├── AlertDescription ├── AlertAction └── AlertClose ``` ## Examples ### Tones tone sets the icon and the color of the icon and the text: neutral, info, success, warning or destructive. The alert itself stays a neutral card. Write the title so it says what happened without the color. ```tsx import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" /** Each tone has its icon and writes the text in its color; the words still say what happened. */ export default function AlertTones() { return (
Scheduled maintenance The dashboard will be read-only on Sunday from 02:00 to 04:00 UTC. A new version is ready Reload the page to get it. Payment received A receipt is on its way to your email. Storage almost full You have used 9.4 of 10 GB. Payment failed Check your card details and try again.
) } ``` ### With buttons AlertAction holds the buttons. One button sits at the end of the text; with layout="stacked" on the Alert they go under it, which suits two buttons. Use an outline Button for the main action and a ghost one for the second, both size sm. ```tsx "use client" import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert" import { Button } from "@/components/ui/button" /** One button sits at the end of the text; two go under it with layout="stacked". Outline for the main action, ghost for the second. */ export default function AlertActionExample() { return (
A new version is ready Restart to update. Your open work is saved first. Payment failed Your card was declined. Update it to keep your plan.
) } ``` ### In a narrow place When the alert itself is narrower than 384px, the button moves under the text by itself. It follows the alert's width, not the screen's, so an alert in a sidebar stacks on a wide screen too. layout="inline" or layout="stacked" fixes one of the two. ```tsx import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert" import { Button } from "@/components/ui/button" /** * The same alert in a narrow column and in a wide one. Under 384px of its own * width the button moves under the text by itself; it follows the alert, not the * screen, so a sidebar on a wide screen stacks too. */ export default function AlertNarrow() { return (
A new version is ready Restart to update.
A new version is ready Restart to update.
) } ``` ### Tinted emphasis="subtle" fills the whole alert with the tone's light color and writes the text in its dark one. Use it for a message that has to be seen at once among cards and fields; the plain alert is the everyday one. ```tsx import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" /** emphasis="subtle" tints the whole alert, for a message that has to be seen from afar. */ export default function AlertSubtle() { return (
Scheduled maintenance The dashboard will be read-only on Sunday from 02:00 to 04:00 UTC. A new version is ready Reload the page to get it. Payment received A receipt is on its way to your email. Storage almost full You have used 9.4 of 10 GB. Payment failed Check your card details and try again.
) } ``` ### Tinted, with buttons A gray or a black button sits badly on a color. So on a tinted alert use a secondary Button for the main action: inside it the button takes the alert's own color, one step darker, a look it has only here. A ghost Button for the second action darkens the tint under the pointer the same way, and so does the close button. ```tsx "use client" import { Alert, AlertAction, AlertClose, AlertDescription, AlertTitle } from "@/components/ui/alert" import { Button } from "@/components/ui/button" /** * On a tinted alert the main action is a secondary Button: there it takes the * alert's own color, a step darker. The second action stays a ghost Button. */ export default function AlertSubtleAction() { return (
A new version is ready Restart to update. Your open work is saved first. Payment failed Your card was declined. Update it to keep your plan.
) } ``` ### Closing it AlertClose adds a × that hides the alert. Focus then goes to the next thing after the alert that can take it, so someone using the keyboard stays where they were; finalFocus on the Alert names another place. Left alone the alert stays closed only while it is on the page: a reload or a new page shows it again. To remember the choice, keep the state with open and onOpenChange and store it. ```tsx "use client" import * as React from "react" import { Alert, AlertClose, AlertTitle } from "@/components/ui/alert" import { Button } from "@/components/ui/button" /** * AlertClose hides the alert and hands focus to what comes after it. Here the * page keeps the state, so it can bring the alert back. */ export default function AlertCloseExample() { const [open, setOpen] = React.useState(true) return (
Your changes are saved
) } ``` ### With a list A list inside AlertDescription gets its bullets and spacing. Count the problems in the title, so the first words already say how much there is to fix. ```tsx import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" /** Several problems at once: a title that counts them and a list. */ export default function AlertList() { return ( There were 2 problems with your password
  • It must include at least 1 number
  • It must include at least 2 uppercase letters
) } ``` ### One line, with a link A short message needs no title: AlertDescription alone is one line. A link in the text keeps the text's color and is underlined. ```tsx import { Alert, AlertDescription } from "@/components/ui/alert" /** A single line needs no title. A link in the text is underlined and keeps the text's color. */ export default function AlertLink() { return ( Your trial ends in 3 days. Add a card to keep your projects. ) } ``` ### Another icon, or none icon replaces the tone's icon with yours, at the same 16px, and icon={false} leaves it out. An svg passed as a child of Alert works too. Without the icon the color is the only thing that tells the tone at a glance, so let the title say it. ```tsx import { Rocket } from "lucide-react" import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" /** icon replaces the tone's icon; icon={false} leaves it out. */ export default function AlertIcon() { return (
}> Dark mode is here Turn it on under your profile settings. You are viewing an archived project Nothing here can be changed.
) } ``` ### Right to left Under dir="rtl" the icon moves to the right and the buttons to the left on their own. Translate toneLabel with the rest of the text. ```tsx "use client" import { Alert, AlertAction, AlertClose, AlertDescription, AlertTitle } from "@/components/ui/alert" import { Button } from "@/components/ui/button" /** * In a right-to-left page the icon moves to the right and the button and the × * to the left on their own. The text is Arabic (lang="ar"), as in a real RTL app. */ export default function AlertRtl() { return ( // "Information" / "A new version is ready" / "Restart to update." / "Restart" / "Close" إصدار جديد جاهز أعد التشغيل للتحديث. ) } ``` ## API Reference Every part takes className and the props of its element. | Prop | Type | What it does | | --- | --- | --- | | tone | `neutral` · `info` · `success` · `warning` · `destructive` | On Alert: the icon and the color. `neutral` by default. | | emphasis | `plain` · `subtle` | On Alert: a neutral card with the icon and the text in the tone's color, or the whole alert tinted. `plain` by default. | | layout | `auto` · `inline` · `stacked` | On Alert: AlertAction at the end of the text or under it. `auto` by default: at the end, and under it when the alert is narrower than 384px. | | toneLabel | `string` · `false` | On Alert: the word a screen reader hears first, "Info", "Success", "Warning" or "Error" by tone. A translation, or `false` for none. | | icon | node · `false` | On Alert: replaces the tone's icon, or leaves it out. | | open | `boolean` | On Alert: whether it shows, when the page keeps the state. | | defaultOpen | `boolean` | On Alert: whether it shows at first. `true` by default. | | onOpenChange | `(open) => void` | On Alert: called when AlertClose is pressed. | | finalFocus | ref | On Alert: where focus goes when AlertClose closes it. By default the next element after the alert that can take focus, or the one before it. | | variant | `default` · `destructive` | On Alert: the names other libraries use, mapped to `neutral` and `destructive`. `tone` wins. | | AlertTitle | `div` | The heading. `render` makes it a heading of the page's level, e.g. `render={

}`. | | AlertDescription | `div` | The text. Takes paragraphs, lists and links. | | AlertAction | `div` | The buttons. | | AlertClose | Button | The ×, named "Close"; `aria-label` translates it. | ## Accessibility An alert that appears while someone is on the page is read aloud without taking focus. - warning and destructive are role="alert": a screen reader reads them at once, interrupting what it was saying. The other tones are role="status" and wait until it is idle. Pass role to change it; an alert that is already there when the page loads is not announced either way. - The tone is never the only sign: every tone has its own icon, and a screen reader hears it as a word before the text ("Error: Payment failed"), which toneLabel translates. The icon itself is hidden from screen readers. Write the title so it says what happened in words. - The close button is named "Close" and takes the usual focus outline. When it is pressed the alert leaves the page and focus moves to the next element after it that can take focus (the one before it when the alert is last), so a keyboard or screen reader user is not sent back to the top of the page. finalFocus picks another place. - Text keeps at least 4.5:1 in both themes, on the plain alert and on every tint, the buttons included. - An alert does not leave by itself. For a message that should, use a Toast; for a question that must be answered before going on, an Alert Dialog; for an error on one field, the field's own error text. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the alert's buttons and links, in order. | | Enter · Space | Presses the focused button; on the close button, the alert leaves and focus moves to the next element. | --- # Alert Dialog Asks before something that cannot be undone; a click outside never closes it. ```tsx "use client" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" /** Asks before something that cannot be undone. Focus starts on Cancel. */ export default function AlertDialogDemo() { return ( }>Delete project Delete “Yolk website”? Its pages and files are removed for everyone. This cannot be undone. Cancel Delete project ) } ``` ## Installation ```bash npx @yolkui/cli add alert-dialog ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/alert-dialog.tsx. ## Usage Asks before something that cannot be undone, like deleting a project. It must be answered: a click outside never closes it. For a form, details or settings, use a Dialog. An Alert Dialog asks a question that must be answered before something that cannot be undone. For anything else, a form, a setting, a long text, use Dialog. It is Dialog's surface without the ×: the choice is a button. AlertDialogCancel goes first and AlertDialogAction last; the action names what happens ("Delete project", not "OK") and takes variant="destructive" when it destroys something. Both close the alert (the action after its work, when its onClick is async); a click on the backdrop does not, Escape does, as Cancel. - Ask only when it matters: an alert for every small action teaches people to click through without reading. ```tsx import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" }>Delete project Delete this project? Its pages and files are removed for everyone. Cancel Delete ``` ### Icon AlertDialogMedia, first in the header, holds an icon in a 40px square, with a 16px glyph as every icon here. It looks best centered, above the title; at the start it sits beside the title and description. tone paints it as the subtle Badge of that tone; match the action, tone="destructive" for a delete. It is hidden from screen readers, so the title must say everything. ## Composition ```text AlertDialog ├── AlertDialogTrigger └── AlertDialogContent ├── AlertDialogHeader │ ├── AlertDialogMedia │ ├── AlertDialogTitle │ └── AlertDialogDescription └── AlertDialogFooter ├── AlertDialogCancel └── AlertDialogAction ``` ## Examples ### Layout layout decides the text and the buttons, and nothing else. "start", the default above, puts the text at the start and the buttons at the end, stacked on a phone with the action on top, as Dialog: for a question with more to read. "center" centers the text in balanced lines and gives the buttons equal shares of the row at every width, as macOS and iOS alerts: for a short, clear question, usually with an icon. ```tsx "use client" import { Trash2 } from "lucide-react" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" /** layout="center" with an icon above the title in the action's tone, as macOS alerts. */ export default function AlertDialogMediaExample() { return ( }>Delete chat Delete this chat? Its messages and files are removed for everyone in it. This cannot be undone. Cancel Delete chat ) } ``` ### Size size decides the width, and nothing else: 448px at the start, 384px centered, 320px at "sm". As shadcn's sm, size="sm" centers unless you pass a layout. For a short yes or no. ```tsx "use client" import { Bell } from "lucide-react" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" /** size="sm": 320 wide. Without a layout it centers (shadcn's sm); for a short yes or no. */ export default function AlertDialogSmall() { return ( }>Notifications Turn on notifications? We let you know when someone mentions you. Not now Turn on ) } ``` ### From a menu "Delete…" in a Dropdown Menu or Context Menu opens the alert: control open and set it in the item's onClick. The menu closes first, and when the alert closes focus goes back to the menu's button. End the item's label with an ellipsis: it asks before it acts. ```tsx "use client" import * as React from "react" import { Copy, Ellipsis, Pencil, Trash2 } from "lucide-react" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" /** "Delete…" in a menu opens the alert; the menu closes first, and focus returns to its button. */ export default function AlertDialogFromMenu() { const [open, setOpen] = React.useState(false) return ( <> }> Rename Duplicate setOpen(true)}> Delete… Delete “Yolk website”? Its pages and files are removed for everyone. This cannot be undone. Cancel Delete project ) } ``` ### Work that takes time When the action waits for a server, give AlertDialogAction an async onClick (or return the promise). The alert stays open while it runs: the action shows its loading state, Escape is off, and it closes when the work is done, so a delete is never left running with nothing on screen to say so. If the promise rejects or resolves to false the alert stays open, ready to show the error and try again (show it in the alert with role="alert", so a screen reader hears it). Cancel still works while it loads, so a request that never answers locks no one in; abort the request in onOpenChange if it should stop. loadingText ("Working" by default) is announced to screen readers. - When your code tracks the work itself and has no promise to return (mutate() and isPending in a data library, a transition), pass loading={isPending}. The action then loads while it is true and never closes the alert by itself; close it from your code when the work succeeds (setOpen(false) in onSuccess). - Code pasted from shadcn's Base UI alert, where the action never closes, works when its onClick is async and closes the alert itself. ```tsx "use client" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" /** * Work that takes time: an async onClick is all it needs. The alert stays open with * the action loading, Cancel and Escape off, and closes when the work is done. * Return false (or let it throw) to keep it open and show an error. */ export default function AlertDialogAsync() { async function remove() { await new Promise((resolve) => setTimeout(resolve, 1500)) // your request here } return ( }>Remove member Remove Ada Lovelace? Ada loses access to every project in this workspace. Cancel Remove member ) } ``` ## API Reference Our props on top of Base UI's AlertDialog (open, defaultOpen, onOpenChange, actionsRef, handle and the rest work as in Base UI). A click outside never closes an alert. | Prop | On | Values | Default | | --- | --- | --- | --- | | layout | `AlertDialogContent` | `"start"` · `"center"` | `"start"`, `"center"` at size="sm" | | size | `AlertDialogContent` | `"default"` · `"sm"` | `"default"` (448, centered 384; sm 320) | | tone | `AlertDialogMedia` | neutral · brand · accent · success · info · warning · destructive | `"neutral"` | | variant | `AlertDialogAction` | Button's variants | `"default"` | | onClick | `AlertDialogAction` | a function; when it returns a promise the alert waits for it, and stays open on a rejection or `false` | — | | loading | `AlertDialogAction` | `true` · `false`: your own work state; the action loads and your code closes the alert | — | | loadingText | `AlertDialogAction` | text announced when the work starts | `"Working"` | | variant | `AlertDialogCancel` | Button's variants | `"outline"` | | createAlertDialogHandle() | — | links triggers anywhere to one alert, with a payload | — | ## Accessibility The popup is an alertdialog, named by its title and described by its description, which screen readers read as it opens. Focus starts on Cancel, wherever it sits in the footer, so Enter on a freshly opened alert never deletes anything; Tab stays inside, and focus returns to the trigger when it closes. ### Keyboard | Key | What it does | | --- | --- | | Tab · Shift + Tab | Moves between the buttons; focus stays inside the dialog. | | Enter · Space | Presses the focused button. Focus starts on Cancel. | | Escape | Cancels and closes, unless an action is running. | --- # Avatar A photo with initials as the fallback, a status badge and overlapping groups. ```tsx import { Avatar, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage } from "@/components/ui/avatar" /** Name the group; the count says how many more, in words for a screen reader. */ export default function AvatarGroupExample() { return (
{(["sm", "default", "lg"] as const).map((size) => ( +3 ))}
) } ``` ## Installation ```bash npx @yolkui/cli add avatar ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/avatar.tsx. ## Usage A person or a team in a small picture: their photo when it loads, their initials when it doesn't, and a status dot. Beside a printed name it only helps the eye find it. ```tsx import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" ``` ## Composition ```text Avatar ├── AvatarImage ├── AvatarFallback └── AvatarBadge AvatarGroup ├── Avatar … └── AvatarGroupCount ``` ## Examples ### Sizes and shape Five sizes, 24 · 32 · 40 · 48 · 64, and shape="square". name gives the initials and the accessible name. ```tsx import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" const sizes = [ { size: "sm", label: "sm · 24" }, { size: "default", label: "default · 32" }, { size: "lg", label: "lg · 40" }, { size: "xl", label: "xl · 48" }, { size: "2xl", label: "2xl · 64" }, ] as const /** A photo, initials from the name, a blank fallback, and the square shape. */ export default function AvatarSizes() { return (
{sizes.map(({ size, label }) => (
{label}
))}
) } ``` ### Fallback A photo that fails to load ends in initials, from the name or your own text. ```tsx import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" /** A broken photo ends in initials, from the name or your own text. */ export default function AvatarFallbackExample() { return (
CN
) } ``` ### Status AvatarBadge's label is read with the name, "Ada Lovelace (Online)", so the color is never the only signal. ```tsx import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar" /** The status words are read with the name: "Ada Lovelace (Online)". */ export default function AvatarStatus() { return (
) } ``` ### Notification position="top" puts the dot at the top corner, for unread activity. ```tsx import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar" /** position="top" puts the dot at the top corner, for unread activity. */ export default function AvatarNotification() { return (
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => ( ))}
) } ``` ### A real photo A notification at the top and presence at the bottom, on a photo. ```tsx import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar" /** A real photo, with a notification at the top and presence at the bottom. */ export default function AvatarPhoto() { return (
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => ( ))}
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => ( ))}
) } ``` ### In a list When the name is printed beside it, hide the avatar from assistive technology (aria-hidden). On a card-colored surface set --avatar-cutout. ```tsx import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar" const members = [ { name: "Ada Lovelace", email: "ada@yolkui.com", role: "Owner", photo: "/avatars/ada.svg", status: { tone: "success", label: "Online" } }, { name: "Grace Hopper", email: "grace@yolkui.com", role: "Editor", status: { tone: "warning", label: "Away" } }, { name: "Margaret Hamilton", email: "margaret@yolkui.com", role: "Viewer", photo: "/avatars/margaret.svg" }, ] as const satisfies { name: string email: string role: string photo?: string status?: { tone: "success" | "warning"; label: string } }[] /** * The name is printed beside it, so the avatar is hidden from assistive technology. * On a card-colored surface the cutout ring takes that color (--avatar-cutout). */ export default function AvatarList() { return (
    {members.map((member) => (
  • {member.name}

    {member.email} {"status" in member ? ` · ${member.status.label.toLowerCase()}` : ""}

    {member.role}
  • ))}
) } ``` ## API Reference Our additions on top of Base UI's Avatar. | Prop | On | Values | Default | | --- | --- | --- | --- | | size | `Avatar` | `sm` · `default` · `lg` · `xl` · `2xl` (24 · 32 · 40 · 48 · 64) | `default` | | shape | `Avatar` | `circle` (people) · `square` (teams, apps) | `circle` | | name | `Avatar` | the person's name: the initials and the photo's alt text | — | | tone | `AvatarBadge` | `success` · `warning` · `destructive` · `neutral` | — | | label | `AvatarBadge` | the status in words, read with the name ("Online") | — | | position | `AvatarBadge` | `bottom` (presence) · `top` (a notification) | `bottom` | | label | `AvatarGroupCount` | the count in words ("3 more people") | — | ## Accessibility The photo's alt text is the name, and the initials stand in for it until the photo loads. - Beside a printed name, pass alt="" on AvatarImage so the name is not read twice. - A status is never only a color: AvatarBadge's label is read with the name ("Ada Lovelace, Online"). - AvatarGroupCount says the number in words, not just "+3". --- # Badge A status or category label in solid, subtle, outline or dot emphasis. ```tsx import { ArrowUpRight, Check, CircleAlert, RefreshCw } from "lucide-react" import { Badge } from "@/components/ui/badge" /** Icons are 12px beside the label; a long label ends in an ellipsis. */ export default function BadgeIcons() { return (
Verified Expiring Docs Syncing
Quarterly-report-final-version-3
) } ``` ## Installation ```bash npx @yolkui/cli add badge ``` Manual: install @base-ui/react@^1.8.0, class-variance-authority@^0.7.1, then copy components/ui/badge.tsx. ## Usage A short status or category beside something: "Beta", "Paid", a count. It is text, not a control; for an action use a Button, for a removable value a Combobox chip. ```tsx import { Badge } from "@/components/ui/badge" Paid ``` ## Examples ### Tones and emphasis tone picks the color and emphasis how loud it is: solid, subtle, outline or dot. The words carry the meaning, never the color alone. ```tsx import { Badge } from "@/components/ui/badge" const tones = [ { tone: "neutral", label: "Draft" }, { tone: "brand", label: "Beta" }, { tone: "accent", label: "New" }, { tone: "success", label: "Paid" }, { tone: "info", label: "Syncing" }, { tone: "warning", label: "Expiring" }, { tone: "destructive", label: "Failed" }, ] as const const emphases = ["solid", "subtle", "outline", "dot"] as const /** tone picks the color, emphasis how loud it is. The words carry the meaning. */ export default function BadgeTones() { return (
{tones.map(({ tone, label }) => (
{tone} {emphases.map((emphasis) => ( {label} ))}
))}
) } ``` ### Sizes, shape and count sm and default, shape="pill", and size="count" for a number. A count alone says only a number, so give it context nearby ("3 unread"). ```tsx import { Badge } from "@/components/ui/badge" /** A count badge alone says only a number: give it context ("3 unread") nearby. */ export default function BadgeSizes() { return (
Paid Paid Paid Paid Paid 3 12 99+ 2
) } ``` ## API Reference Badge is a span; these are its props. | Prop | On | Values | Default | | --- | --- | --- | --- | | tone | `Badge` | `neutral` · `brand` · `accent` · `success` · `info` · `warning` · `destructive` | `neutral` | | emphasis | `Badge` | `solid` · `subtle` · `outline` · `dot` | `subtle` | | size | `Badge` | `sm` · `default` · `count` | `default` | | shape | `Badge` | `default` · `pill` | `default` | | variant | `Badge` | shadcn's names (`default` · `secondary` · `destructive` · `outline`), mapped onto tone and emphasis | — | ## Accessibility A badge is read as part of the text around it. - Color is never the only sign: the word says the status. - A count alone ("3") needs words for a screen reader: an aria-label or visually hidden text ("3 unread"). - Every tone keeps 4.5:1 contrast in both themes. --- # Breadcrumb The path from the top of a site to the current page, each step a link back. ```tsx import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" export default function BreadcrumbDemo() { return ( Home Projects Atlas Settings ) } ``` ## Installation ```bash npx @yolkui/cli add breadcrumb ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/breadcrumb.tsx. ## Usage The path from the top of a site to the current page, each step a link back. Not for steps in a process (use a progress of steps) or for switching views (use Tabs). ```tsx import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" Home Settings ``` ## Composition ```text Breadcrumb └── BreadcrumbList ├── BreadcrumbItem │ ├── BreadcrumbLink │ ├── BreadcrumbEllipsis · BreadcrumbEllipsisButton │ └── BreadcrumbPage └── BreadcrumbSeparator ``` ## Examples ### With icons An icon inside a link or the page sits 6 from its label and takes its color. It stays 16px. ```tsx import { FolderOpen, House } from "lucide-react" import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" export default function BreadcrumbIcons() { return ( Home Projects Atlas ) } ``` ### Custom separator BreadcrumbSeparator draws a chevron. Pass anything else as its children; it is centered in the same 16px. ```tsx import { Slash } from "lucide-react" import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" /** Anything passed to BreadcrumbSeparator replaces the chevron. */ export default function BreadcrumbSeparatorExample() { return ( yolkui components breadcrumb.tsx ) } ``` ### Collapsed A deep path can hide its middle steps behind three dots. BreadcrumbEllipsisButton is the trigger of a Dropdown Menu whose items are links, so every step stays reachable. Your app decides which steps hide. ```tsx import { Breadcrumb, BreadcrumbEllipsisButton, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" import { DropdownMenu, DropdownMenuContent, DropdownMenuLinkItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" /** * A deep path keeps its first step and its last two; the ones between sit in a * menu behind the three dots. The menu's items are links too. */ export default function BreadcrumbEllipsis() { return ( Home } /> Workspace Atlas Billing Invoices March 2026 ) } ``` ### A long path A path wider than its container wraps onto the next line, so nothing is hidden and nothing scrolls. A separator stays with the step before it and never starts a line. ```tsx import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" /** * In a narrow column the path wraps onto the next line. A chevron stays with the * step before it, so it never starts a line. */ export default function BreadcrumbLong() { return ( Home Workspace Atlas Billing Invoices March 2026 ) } ``` ### Long names A name of unknown length takes a max width and truncate on its link or page, and ends in an ellipsis. Add a title so the whole name shows on hover. ```tsx import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" /** * A name of unknown length (a file, a project someone named) takes a max width and * truncate, and ends in an ellipsis. The title keeps the whole name on hover. */ export default function BreadcrumbTruncate() { return ( Projects Atlas redesign for the spring launch Quarterly planning notes, final version ) } ``` ### With a router BreadcrumbLink is an . Pass your router's link in render, so a step changes the page without a reload. ```tsx import Link from "next/link" import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" /** A router's link goes in render, so a step changes the page without a reload. */ export default function BreadcrumbRouterLink() { return ( }>Docs }>Components Breadcrumb ) } ``` ### Right to left Under dir="rtl" the path starts at the right and the chevrons turn around. A separator of your own is not mirrored. ```tsx import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb" /** * In a right-to-left page the path starts at the right and the chevrons turn * around on their own. The text is Arabic (lang="ar"), as in a real RTL app. */ export default function BreadcrumbRtl() { return ( // Path: Home, Projects, Atlas, Settings الرئيسية المشاريع أطلس الإعدادات ) } ``` ## API Reference Every part takes className and the props of its element. | Part | Element | What it is | | --- | --- | --- | | Breadcrumb | `nav` | The landmark, named "Breadcrumb". `aria-label` translates the name. | | BreadcrumbList | `ol` | The row of steps. It wraps when it does not fit. | | BreadcrumbItem | `li` | One step: a link, the page or the three dots. | | BreadcrumbLink | `a` | A step that goes somewhere. `render` takes a router's link. | | BreadcrumbPage | `span` | The current page, the last step. Not a link. | | BreadcrumbSeparator | `li` | The mark between two steps: a chevron, or its children. | | BreadcrumbEllipsisButton | `button` | Three dots that open a menu of hidden steps. Named "Show hidden steps"; `aria-label` translates it. | | BreadcrumbEllipsis | `span` | Three dots with no action, for steps that are simply left out. | ## Accessibility The path is a nav landmark holding an ordered list, so a screen reader can jump to it and hears how many steps there are. - The current page carries aria-current="page" and is read as the current page. It is the last step, is not a link, and is darker and heavier than the links, so color is never its only sign. - Separators are decoration and are hidden from screen readers. - Links take the usual focus outline. Their text is 20px high and the area that takes a click or a tap is 24. - With several nav landmarks on a page, each needs its own name: keep "Breadcrumb" here, or translate it with aria-label. - A breadcrumb shows where a page sits in the site, not the pages someone went through. Do not use it for the steps of a form. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the next link (the current page is not a link). | | Enter | Follows the focused link. | --- # Button A button or a link styled as one, with sizes, variants, icons and a loading state that keeps its width. ```tsx import { Check } from "lucide-react" import { Button } from "@/components/ui/button" export default function ButtonDemo() { return (
) } ``` ## Installation ```bash npx @yolkui/cli add button ``` Manual: install @base-ui/react@^1.8.0, class-variance-authority@^0.7.1, then copy components/ui/button.tsx. ## Usage Starts an action: save, send, delete, open. For going to another page use ButtonLink (a link that looks like a button); for an on/off state, a Toggle or Switch. ```tsx import { Button } from "@/components/ui/button" ``` ## Examples ### Variants Eleven variants in four sizes, 28 · 32 · 36 · 40, and an icon-only button at each size. Icon-only buttons need an aria-label. ```tsx import { Plus } from "lucide-react" import { Button } from "@/components/ui/button" const variants = [ "default", "secondary", "outline", "soft", "ghost", "destructive", "accent", "accent-soft", "brand", "brand-soft", "link", ] as const export default function ButtonVariants() { return (
{variants.map((variant) => (
{variant} {variant !== "link" && ( <> )}
))}
) } ``` ### Pill shape="pill" rounds both ends; an icon-only pill is a circle. ```tsx import { Plus } from "lucide-react" import { Button } from "@/components/ui/button" const variants = [ "default", "secondary", "outline", "soft", "ghost", "destructive", "accent", "accent-soft", "brand", "brand-soft", "link", ] as const export default function ButtonPill() { return (
{variants.map((variant) => (
{variant} {variant !== "link" && ( <> )}
))}
) } ``` ### Icons Icons are 16px, 14 at xs and sm. The side holding an icon gets less padding, worked out from the markup, so there is no prop to set. ```tsx import { ChevronRight, Plus } from "lucide-react" import { Button } from "@/components/ui/button" const sizes = [ { size: "xs", label: "xs · 28" }, { size: "sm", label: "sm · 32" }, { size: "default", label: "default · 36" }, { size: "lg", label: "lg · 40" }, ] as const /** The side holding an icon gets less padding; the button works it out from the markup. */ export default function ButtonIcons() { return (
{sizes.map(({ size, label }) => (
{label}
))}
) } ``` ### States Loading keeps the width and the name, and is announced once. Disabled stays focusable so a tooltip can say why. aria-invalid draws the error ring. A link styled as a button is ButtonLink. ```tsx import { ChevronRight, Plus } from "lucide-react" import { Button, ButtonLink } from "@/components/ui/button" export default function ButtonStates() { return (
Link, not a button
) } ``` ## API Reference Button is Base UI's Button; these are our additions. | Prop | On | Values | Default | | --- | --- | --- | --- | | variant | `Button` · `ButtonLink` | `default` · `secondary` · `outline` · `soft` · `ghost` · `destructive` · `accent` · `accent-soft` · `brand` · `brand-soft` · `link` | `default` | | size | `Button` · `ButtonLink` | `xs` · `sm` · `default` · `lg` (28 · 32 · 36 · 40) · `icon-xs` · `icon-sm` · `icon` · `icon-lg` | `default` | | shape | `Button` · `ButtonLink` | `default` · `pill` | `default` | | loading | `Button` | `boolean`: inactive, a spinner, the width kept, announced once | `false` | | loadingText | `Button` | what a screen reader hears while loading | — | | disabled | `Button` | `boolean`: stays focusable (aria-disabled) so a Tooltip can say why | `false` | ## Accessibility A real button element, with Base UI's keyboard handling. - An icon-only button needs an aria-label; in development a warning says when it has none. - Disabled stays in the Tab order and is announced as dimmed, so a Tooltip can explain it. - Loading is aria-busy and announced once, without a second focus. - The focus outline is a real outline, so it shows in Windows High Contrast too. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the button. | | Enter · Space | Presses it. | --- # Button Group Joins buttons and fields into one control, with separators that match each button. ```tsx import { ArrowLeft, Ellipsis } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup } from "@/components/ui/button-group" export default function ButtonGroupDemo() { return ( ) } ``` ## Installation ```bash npx @yolkui/cli add button-group ``` Manual: install class-variance-authority@^0.7.1, then copy components/ui/button-group.tsx. ## Usage Joins buttons, and fields with buttons, into one control: a split button, pagination arrows, a search field with its submit. For a set of toggles use a Toggle Group; for a row of tools, a Toolbar. ```tsx import { Button } from "@/components/ui/button" import { ButtonGroup } from "@/components/ui/button-group" ``` ## Composition ```text ButtonGroup ├── Button · Input · Select … ├── ButtonGroupSeparator └── ButtonGroupText ``` ## Examples ### Separator and text A separator takes the color of the button before it; ButtonGroupText holds static context such as a page range. ```tsx import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText } from "@/components/ui/button-group" export default function ButtonGroupSeparatorExample() { return (
1–10 of 240
) } ``` ### Orientation and size orientation="vertical" stacks the buttons. Size stays on each button: the group owns layout, never style. ```tsx import { Minus, Plus, RotateCcw } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup } from "@/components/ui/button-group" export default function ButtonGroupOrientation() { return (
{(["sm", "default", "lg"] as const).map((size) => ( ))}
) } ``` ### Soft Soft buttons share one ring, edge and lift across the group, and a separator draws each seam. ```tsx import { ArrowLeft, ArrowRight, ChevronsUpDown, Circle, CloudDownload, Ellipsis, Eye, Image as ImageIcon, Pencil, Type, ZoomIn, ZoomOut, } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group" /** Soft buttons share one ring, edge and lift; a separator draws each seam. */ export default function ButtonGroupSoft() { return (
{(["icon", "icon-sm"] as const).map((size) => ( ))}
{(["icon", "icon-sm"] as const).map((size) => ( ))}
) } ``` ### Variants Every variant has a separator in its own color. Outline shares its border instead, so it needs none. ```tsx import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group" const variants = [ "default", "secondary", "outline", "soft", "ghost", "destructive", "accent", "accent-soft", "brand", "brand-soft", "link", ] as const /** Every variant has a separator in its own color; outline shares its border instead. */ export default function ButtonGroupVariants() { return (
{variants.map((variant) => (
{variant} {variant !== "outline" && }
))}
) } ``` ### With an input A field in a group takes the free width, so give the group one (w-full). Beside outline and solid buttons the field keeps its own ring. ```tsx import { Copy, Search } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group" import { Input } from "@/components/ui/input" /** A field in a group takes the free width; give the group one (w-full). */ export default function ButtonGroupInput() { return (
} />
) } ``` ### Pill A pill field or button rounds the whole group, so the shared ring follows the curve. ```tsx import { Search } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group" import { Input } from "@/components/ui/input" /** A pill field or button rounds the whole group. */ export default function ButtonGroupPill() { return (
} />
) } ``` ### With soft buttons Beside a soft button the field hands its resting ring to the group, and a separator draws the seam, as between two soft buttons. ```tsx import { ArrowRight, ListFilter, Minus, Plus } from "lucide-react" import { Button } from "@/components/ui/button" import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group" import { Input } from "@/components/ui/input" /** Beside a soft button the field hands its ring to the group; a separator draws the seam. */ export default function ButtonGroupInputSoft() { return (
{(["sm", "default", "lg"] as const).map((size) => ( ))}
) } ``` ## API Reference ButtonGroup owns the layout; each button keeps its own variant and size. | Prop | On | Values | Default | | --- | --- | --- | --- | | orientation | `ButtonGroup` | `horizontal` · `vertical` | `horizontal` | | aria-label | `ButtonGroup` | the group's name, read on entering it | — | | orientation | `ButtonGroupSeparator` | `vertical` · `horizontal` (follows the group) | `vertical` | ## Accessibility The group is role="group" and needs a name: an aria-label, or aria-labelledby pointing at a visible label. - Every button keeps its own Tab stop; a group is not one control to the keyboard. - ButtonGroupText is plain text in the group, read in order. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the next button or field in the group. | | Enter · Space | Presses the focused button. | --- # Calendar A month of days to pick a date or a range, with days that cannot be picked. ```tsx "use client" import * as React from "react" import { Calendar } from "@/components/ui/calendar" export default function CalendarDemo() { const [date, setDate] = React.useState(new Date()) return } ``` ## Installation ```bash npx @yolkui/cli add calendar ``` Manual: install @base-ui/react@^1.8.0, react-day-picker@^10.0.2, then copy components/ui/calendar.tsx. ## Usage Shows a month to pick a date, several dates or a range. In a form, pair it with a Popover as a date picker; for a date someone already knows (a birthday), a typed field is quicker. ```tsx import { Calendar } from "@/components/ui/calendar" const [date, setDate] = React.useState(new Date()) ``` ## Examples ### A range mode="range" picks a start and an end: the first click starts the range, the second ends it. The days between sit on a gray band that is cut at the end of each week. numberOfMonths shows months side by side from md, stacked on a phone. ```tsx "use client" import * as React from "react" import type { DateRange } from "react-day-picker" import { Calendar } from "@/components/ui/calendar" /** mode="range": the first click starts the range, the second ends it. Two months side by side from md. */ export default function CalendarRange() { const [range, setRange] = React.useState(() => { const from = new Date() from.setDate(from.getDate() - 3) const to = new Date() to.setDate(to.getDate() + 5) return { from, to } }) return } ``` ### Days that cannot be picked disabled takes dates and rules: { before: date }, { after: date }, { dayOfWeek: [0, 6] } or a function. Those days fade and cannot be clicked; the arrow keys skip them. startMonth and endMonth stop the arrows at the months you allow. ```tsx "use client" import * as React from "react" import { Calendar } from "@/components/ui/calendar" /** disabled takes dates and rules: here every past day and every weekend. */ export default function CalendarDisabled() { const [date, setDate] = React.useState() const today = React.useMemo(() => { const day = new Date() day.setHours(0, 0, 0, 0) return day }, []) return ( ) } ``` ### Days of the months around By default a month shows only its own days. showOutsideDays fills the first and last rows with the days around it in muted text, and fixedWeeks keeps six rows, so the calendar never changes height between months. ```tsx "use client" import * as React from "react" import { Calendar } from "@/components/ui/calendar" /** showOutsideDays fills the first and last rows with the days of the months around, in muted text. */ export default function CalendarOutsideDays() { const [date, setDate] = React.useState() return } ``` ### In a card The calendar has no fill of its own, so it sits on whatever surface holds it. Inside a Card drop its padding with className="p-0". ```tsx "use client" import * as React from "react" import { Calendar } from "@/components/ui/calendar" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" /** In a Card the calendar has no fill of its own, so it sits on the card's surface. */ export default function CalendarCard() { const [date, setDate] = React.useState() return ( }>Delivery day We deliver on weekdays. {date ? `Delivery on ${date.toLocaleDateString("en-US", { weekday: "long", month: "long", day: "numeric" })}` : "Pick a day."} ) } ``` ### Date picker A Button that opens the Calendar in a Popover, under a label. The button is named by the label and its own text together (aria-labelledby with both ids), so a screen reader hears what the date is for and the date. The popover drops its own padding (className="w-auto p-0"; the calendar keeps its 12) and takes an aria-label, since it has no title. Control open and close it in onSelect, so picking a day closes it and focus goes back to the button. ```tsx "use client" import * as React from "react" import { CalendarDays } from "lucide-react" import { Button } from "@/components/ui/button" import { Calendar } from "@/components/ui/calendar" import { Field, FieldLabel } from "@/components/ui/field" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" /** * A date picker: a Button that opens a Calendar in a Popover. The button is named by * its label and its text together ("Delivery date, Pick a date", then "Delivery * date, November 24, 2026"), so a screen reader hears what the date is for and its * value. The popover drops its own padding (the calendar has 12 of its own) and takes * an aria-label, since it has no title. Focus starts on the picked day, or today; * picking a day closes it and focus returns to the button. */ export default function CalendarDatePicker() { const id = React.useId() const [open, setOpen] = React.useState(false) const [date, setDate] = React.useState() return ( Delivery date } > {date ? ( date.toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" }) ) : ( Pick a date )} {/* Focus starts on the picked day, or today (the APG date picker), not on the first arrow. */} { setDate(day) setOpen(false) }} /> ) } ``` ### Right to left and other languages locale (from react-day-picker/locale) writes the month and weekdays in a language and starts the week on its day. In a right-to-left app the Calendar reads Base UI's DirectionProvider: the week runs from the right, the arrows turn round and ArrowLeft moves to the next day. ```tsx "use client" import * as React from "react" import { DirectionProvider } from "@base-ui/react/direction-provider" import { defaultDateLib } from "react-day-picker" import { ar } from "react-day-picker/locale" import { Calendar } from "@/components/ui/calendar" /** * A right-to-left page: the week starts at the right and ArrowLeft moves to the next * day (Base UI's DirectionProvider), the month and days in Arabic (locale). Arabic * writes a weekday as a whole word, too wide for a 32px column, so the header uses * its one-letter form (date-fns, as every other name in the calendar, so the server * and the browser write the same). */ export default function CalendarRtl() { const [date, setDate] = React.useState(new Date()) return ( (dateLib ?? defaultDateLib).format(day, "EEEEE") }} /> ) } ``` ## API Reference Calendar takes every prop of react-day-picker's DayPicker; the ones used most: | Prop | Type | What it does | | --- | --- | --- | | mode | `single` · `multiple` · `range` | How days are picked. Without a mode the calendar only shows dates. | | selected · onSelect | `Date` · `Date[]` · `DateRange` | The picked day, days or range, and what to do when it changes. | | disabled | `Matcher | Matcher[]` | Days that cannot be picked: dates, { before }, { after }, { dayOfWeek } or a function. | | defaultMonth · month · onMonthChange | `Date` | The month shown first, or the shown month controlled. | | startMonth · endMonth | `Date` | The first and last month the arrows reach. | | numberOfMonths | `number` | Months shown side by side (stacked below md). | | showOutsideDays · fixedWeeks | `boolean` | The days of the months around in muted text (off by default); six rows in every month. | | locale · weekStartsOn | `Locale` · `0–6` | The language of the month and weekdays, and the first day of the week. | | captionLayout | `label` · `dropdown` · `dropdown-months` · `dropdown-years` | The month's name, or dropdowns to jump to a month and year (or only one of them); give startMonth and endMonth to set the years listed. | | buttonVariant | Button's `variant` | The Button variant of the arrows; `ghost` by default. | | className | `string` | A day is 32px (`--cell-size`); `[--cell-size:--spacing(9)]` makes it 36, the default control height, for a calendar on its own on a touch screen. | ## Accessibility The month is a grid named by its month and year; each day is a button whose name is the full date, with "Today" and "selected" when they apply. - Tab reaches the arrows and then one day; the arrow keys move between days, Page Up and Page Down by month (with Shift by year), Home and End to the week's ends. Enter or Space picks. - Changing the month is announced: the month's name is a polite live region. - An arrow with no month left fades but keeps its place in the Tab order, so focus is never lost. - Today and the picked day differ by more than color: today keeps the text color on a gray fill, the picked day inverts it, and a screen reader hears both. In Windows High Contrast the picked days take the system highlight and today a frame. ### Keyboard | Key | What it does | | --- | --- | | Arrow keys | Move by a day, or a week up and down. | | Page Up · Page Down | Previous or next month; with Shift, a year. | | Home · End | The start or end of the week. | | Enter · Space | Picks the focused day. | --- # Card A container with header, content and footer that share one edge. ```tsx import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Button } from "@/components/ui/button" import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" const members = [ { name: "Ada Lovelace", email: "ada@yolkui.com", role: "Owner", photo: "/avatars/ada.svg" }, { name: "Grace Hopper", email: "grace@yolkui.com", role: "Editor" }, ] /** Header with an action, content, and a footer; the heading level is the page's. */ export default function CardDemo() { return ( }>Invite your team Everyone you invite can edit this workspace.
    {members.map((member) => (
  • {member.photo ? : null}

    {member.name}

    {member.email}

    {member.role}
  • ))}
2 of 5 seats used
) } ``` ## Installation ```bash npx @yolkui/cli add card ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/card.tsx. ## Usage Groups one thing's content in a box: a summary, a form, a list. Not for every section of a page; a heading and space usually do. ```tsx import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" Storage 18.4 GB of 50 GB used. … ``` ## Composition ```text Card ├── CardHeader │ ├── CardTitle │ ├── CardDescription │ └── CardAction ├── CardContent └── CardFooter ``` ## Examples ### Small size="sm": a smaller title and buttons, the same spacing. ```tsx import { Badge } from "@/components/ui/badge" import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" /** size="sm": a smaller title, the same spacing. */ export default function CardSmall() { return ( }>Storage Resets on 1 December Healthy

18.4 GB of 50 GB

) } ``` ### Image An image placed first drops the top padding and takes the card's corners. ```tsx import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardAction, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" /** An image placed first drops the top padding and takes the card's corners. */ export default function CardImage() { return ( {/* eslint-disable-next-line @next/next/no-img-element */} }>Design systems meetup Thursday, 14 November · Sofia Featured ) } ``` ### Image last An image placed last drops the bottom padding and takes the bottom corners. ```tsx import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" /** An image placed last drops the bottom padding and takes the bottom corners. */ export default function CardImageEnd() { return ( }>Venue Sofia Tech Park, Hall 2 {/* eslint-disable-next-line @next/next/no-img-element */} ) } ``` ### Footer Footer actions sit at the end: secondary first, primary last. ```tsx import { Button } from "@/components/ui/button" import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" /** Footer actions sit at the end: secondary first, primary last. */ export default function CardFooterExample() { return ( }>Archive project It leaves your list. You can restore it at any time. ) } ``` ### Divider A line under the header or above the footer is opt-in: className="border-b" or "border-t". ```tsx import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" /** A line under the header is opt-in: className="border-b". */ export default function CardDivider() { return ( }>Notifications Choose what reaches your inbox.
  • Comments and mentions On
  • Weekly summary Off
) } ``` ## API Reference Every part is a div with its data-slot; Card has one prop. | Prop | On | Values | Default | | --- | --- | --- | --- | | size | `Card` | `default` · `sm` (tighter spacing, smaller title) | `default` | | render | `CardTitle` | the heading element: `}>` to fit the page's outline | a div | ## Accessibility A card is a box, not a landmark. - Give CardTitle the right heading level with render (`

`, `

`) so the card appears in the page's outline. - A whole card that is a link needs one link with the title as its text; the rest of the card is not a second link. --- # Checkbox An on/off choice, mixed for a parent over a group. ```tsx import { Checkbox } from "@/components/ui/checkbox" import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" /** The label wraps the box, so a click on the text toggles it too. */ export default function CheckboxDemo() { return (
Remember this device Product updates A short email when something new ships, at most once a month.
) } ``` ## Installation ```bash npx @yolkui/cli add checkbox ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/checkbox.tsx. ## Usage An on/off choice inside a form, sent when the form is submitted. For a setting that takes effect at once use a Switch; for one choice out of several, a Radio Group. ```tsx import { Checkbox } from "@/components/ui/checkbox" import { Field, FieldLabel } from "@/components/ui/field" Accept the terms ``` ### Read-only readOnly shows a value someone else controls. Unlike disabled, it stays at full strength and a form submits it; it cannot change, so it drops the pointer and the hover. Screen readers hear "read-only". Say who controls it in a FieldDescription. ## Examples ### Group CheckboxGroup holds a list that shares one value, an array of the checked values. Give it allValues and mark one checkbox parent: the parent checks or clears every child, and is mixed while only some are checked. Name it with a FieldLegend inside, which screen readers hear when focus enters the group (or aria-label when the heading is elsewhere). Give each child the same name and its own value, and a form submits one entry per checked child; the parent submits nothing. ```tsx "use client" import * as React from "react" import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox" import { Field, FieldLabel, FieldLegend } from "@/components/ui/field" const activity = [ { value: "mentions", label: "Mentions" }, { value: "comments", label: "Comments" }, { value: "followers", label: "New followers" }, ] /** * A parent checks or clears every child and is mixed while only some are checked. * The group needs a controlled value and allValues for that. Each child carries the * name, so a form submits one notify entry per checked child; the parent submits nothing. */ export default function CheckboxGroupExample() { const [value, setValue] = React.useState(["mentions", "comments"]) return ( item.value)}> Notify me about All activity
{activity.map((item) => ( {item.label} ))}
) } ``` ### Invalid An invalid checkbox draws its ring in red. Red is never the only signal: pair it with a FieldError that says what to do. ```tsx import { Checkbox } from "@/components/ui/checkbox" import { Field, FieldError, FieldLabel } from "@/components/ui/field" /** Red is never the only signal: the error says what to do, beside an icon. */ export default function CheckboxInvalid() { return ( I agree to the terms Accept the terms to continue. ) } ``` ### Disabled A disabled checkbox fades with its label and cannot be changed, and a form leaves it out. It stays focusable and keeps pointer events, so a Tooltip around the box can say why: it opens on hover over the box and on keyboard focus, not over the label's text. Keep the tooltip on the box, so screen readers hear it with the checkbox; if the reason matters to everyone, write it in a FieldDescription instead. ```tsx import { Checkbox } from "@/components/ui/checkbox" import { Field, FieldLabel } from "@/components/ui/field" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" /** * A disabled checkbox keeps focus and pointer events (aria-disabled), so a tooltip * can say why, on hover and on keyboard focus. */ export default function CheckboxDisabled() { return (
} /> Available on the Business plan Require single sign-on Daily backups
) } ``` ## API Reference Base UI's Checkbox and CheckboxGroup (checked, defaultChecked, onCheckedChange, indeterminate, value, allValues…); our additions: | Prop | On | Values | Default | | --- | --- | --- | --- | | disabled | `Checkbox` | `boolean`: stays focusable so a Tooltip can say why | `false` | | readOnly | `Checkbox` | `boolean`: full strength, sent with the form, cannot change | `false` | | aria-invalid | `Checkbox` | draws the error ring; inside a Field, set by the Field | — | ## Accessibility Screen readers hear the label, the state (checked, not checked or mixed) and "dimmed" when disabled. Space toggles it. - Wrap it in FieldLabel with its text, so the label names it and a click on the text toggles it. - The box is 16px; the area that takes a click is 24px, and the whole label. - A description in FieldDescription is read after the label. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the checkbox. | | Space | Checks or unchecks it. | --- # Combobox A field you type into to filter a list, with chips for several values. ```tsx "use client" import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "@/components/ui/combobox" import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" const frameworks = [ { label: "Next.js", value: "next" }, { label: "Remix", value: "remix" }, { label: "Astro", value: "astro" }, { label: "SvelteKit", value: "sveltekit" }, { label: "Nuxt", value: "nuxt" }, ] /** Type to filter; the × empties the field, the chevron opens the list without typing. */ export default function ComboboxDemo() { return ( Framework No framework found. {(item: (typeof frameworks)[number]) => ( {item.label} )} Used for the project template. ) } ``` ## Installation ```bash npx @yolkui/cli add combobox ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/combobox.tsx. ## Usage A field you type into to filter a long list, then pick one value, or several as chips. For a short list with no typing, use a Select; for free text with suggestions, an Input. Pass the options to Combobox as items ({ label, value }) and render each one from ComboboxList as a ComboboxItem: typing filters the list, Base UI matches on the label. The field is Input's surface, with its sizes and shape="pill"; the list is Select's, the chosen item checked at the end. While there is a value, an × before the chevron empties the field; showClear={false} or showTrigger={false} on ComboboxInput leaves either out. - For a short, fixed list where nobody types, Select is simpler: it opens on the chosen item and needs no filtering. - ComboboxEmpty shows when nothing matches; Base UI announces it to screen readers. ```tsx import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, ComboboxList } from "@/components/ui/combobox" {(item) => {item}} ``` ## Composition ```text Combobox ├── ComboboxInput (or ComboboxChips > ComboboxChip, ComboboxChipsTrigger) └── ComboboxContent ├── ComboboxSearch ├── ComboboxEmpty └── ComboboxList ├── ComboboxGroup > ComboboxLabel ├── ComboboxItem └── ComboboxSeparator ``` ## Examples ### Several values With multiple, each value is a chip in ComboboxChips, with its own × to remove it; chips wrap onto new rows and the field grows. The dashed + button after them (ComboboxChipsTrigger) opens the list, and ComboboxSearch at the list's top takes the typing. Its placeholder ("Select") shows inside it while nothing is chosen, and starts its name meanwhile ("Select Frameworks"), so the visible text is in the name; the label still names it on its own. The list stays open while you pick, and the form sends every value chosen. - From the + button, the Left arrow moves into the chips (Right in a right-to-left layout); Backspace or Delete removes the focused chip. - Name the chips with aria-label on ComboboxChips ("Selected frameworks"): they are a toolbar. While there are chips, the + button tells a screen reader how many and how to reach them ("2 selected. Press Left Arrow to reach them."). - The strings are English by default: removeLabel and aria-description on ComboboxChip, formatChipsDescription on ComboboxChipsTrigger translate them. - A text field among the chips, as in shadcn's examples, is ComboboxChipsInput: it still works, and Backspace in it removes the last chip. ```tsx "use client" import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsTrigger, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxSearch, ComboboxValue, } from "@/components/ui/combobox" import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" const frameworks = [ { label: "Next.js", value: "next" }, { label: "Remix", value: "remix" }, { label: "Astro", value: "astro" }, { label: "SvelteKit", value: "sveltekit" }, { label: "Nuxt", value: "nuxt" }, { label: "Gatsby", value: "gatsby" }, ] type Framework = (typeof frameworks)[number] /** * Each value is a chip with its own ×. The + opens the list, the search field at its * top; the list stays open while you pick. */ export default function ComboboxMultiple() { return ( Frameworks {(values: Framework[]) => values.map((item) => {item.label}) } No framework found. {(item: Framework) => ( {item.label} )} Pick any you work in. ) } ``` ### Groups Pass groups ({ value, items }) as items and render each with ComboboxGroup, a ComboboxLabel and a ComboboxCollection of its items, so a filtered list keeps every label above its matches. ComboboxSeparator draws a line between groups. ```tsx "use client" import { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxLabel, ComboboxList, ComboboxSeparator, } from "@/components/ui/combobox" const timezones = [ { value: "Europe", items: [ { label: "London (GMT)", value: "europe/london" }, { label: "Berlin (CET)", value: "europe/berlin" }, { label: "Sofia (EET)", value: "europe/sofia" }, ], }, { value: "Americas", items: [ { label: "New York (EST)", value: "america/new_york" }, { label: "Chicago (CST)", value: "america/chicago" }, { label: "Los Angeles (PST)", value: "america/los_angeles" }, ], }, { value: "Asia", items: [ { label: "Tokyo (JST)", value: "asia/tokyo" }, { label: "Singapore (SGT)", value: "asia/singapore" }, ], }, ] type Zone = { label: string; value: string } /** Groups pass through ComboboxCollection, so filtering keeps each label above its items. */ export default function ComboboxGroups() { return ( No time zone found. {(group: (typeof timezones)[number], index: number) => ( {index > 0 && } {group.value} {(item: Zone) => ( {item.label} )} )} ) } ``` ### Invalid aria-invalid on ComboboxInput (or an invalid Field) turns the edge and the focus outline red, and FieldError says why, with an icon and words. ```tsx "use client" import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "@/components/ui/combobox" import { Field, FieldError, FieldLabel } from "@/components/ui/field" const countries = [ { label: "Bulgaria", value: "bg" }, { label: "Germany", value: "de" }, { label: "Japan", value: "jp" }, { label: "United Kingdom", value: "gb" }, { label: "United States", value: "us" }, ] /** Red is never alone: the FieldError says what is wrong. */ export default function ComboboxInvalid() { return ( Country No country found. {(item: (typeof countries)[number]) => ( {item.label} )} Choose the country you ship from. ) } ``` ### Disabled A disabled combobox is a disabled text field: it fades, is skipped by Tab and is left out of the form, as Input. Say why in a FieldDescription. ```tsx "use client" import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, ComboboxList, } from "@/components/ui/combobox" import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" const owners = [ { label: "Ada Lovelace", value: "ada" }, { label: "Grace Hopper", value: "grace" }, ] /** A disabled field is native: skipped by Tab, so the reason goes in a FieldDescription. */ export default function ComboboxDisabled() { return ( Owner {(item: (typeof owners)[number]) => ( {item.label} )} Only an admin can change the owner. ) } ``` ### Read-only readOnly on Combobox shows the value at full strength and sends it with the form, but nothing changes it: the field has no × and no chevron, chips lose their ×, and the list never opens. There is nothing to add, so the + is not drawn, but the field keeps one Tab stop with its focus outline, as a read-only input does: a screen reader hears it is read-only and how many are chosen, and the Left Arrow reaches the chips. Say who can change it in a FieldDescription. ```tsx "use client" import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsTrigger, ComboboxInput, ComboboxValue, } from "@/components/ui/combobox" import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" const frameworks = [ { label: "Next.js", value: "next" }, { label: "Remix", value: "remix" }, { label: "Astro", value: "astro" }, ] type Framework = (typeof frameworks)[number] /** * Read-only shows the value at full strength and is submitted with the form, but cannot * change: no ×, no chevron, chips without ×. Say who can change it in a FieldDescription. */ export default function ComboboxReadOnly() { return (
Framework Set when the project was created. Frameworks {(values: Framework[]) => values.map((item) => {item.label}) } Only an admin can change them.
) } ``` ## API Reference Base UI's Combobox (items, value, defaultValue, onValueChange, multiple, filter…); our additions: | Prop | On | Values | Default | | --- | --- | --- | --- | | size | `ComboboxInput` | `xs` · `sm` · `default` · `lg` | `default` | | shape | `ComboboxInput` | `default` · `pill` | `default` | | showTrigger | `ComboboxInput` | `boolean`: the chevron that opens the list | `true` | | showClear | `ComboboxInput` | `boolean`: the × that clears the value | `true` | | showRemove | `ComboboxChip` | `boolean`: the × on a chip | `true` | | removeLabel | `ComboboxChip` | the ×'s name ("Remove") | `"Remove"` | | placeholder | `ComboboxChipsTrigger` | text beside the + while there are no chips, read with its name | — | ## Accessibility The field is a combobox and the list a listbox. Typing opens and filters it, the Down and Up arrows move through it, Enter picks the highlighted item and Escape closes the list. Screen readers hear the label, the value and how many results match. - Give it a label: a FieldLabel in a Field, or aria-label on ComboboxInput when it stands alone. With chips the + button is the field's control: a FieldLabel names it, or an aria-label ("Add framework") outside a Field. Name the search field and the list too. - The × and the chevron are left out of the Tab order (Base UI's): from the keyboard, select the text and delete it, or open the list with the Down arrow. - The chosen item is marked with a check, never color alone. ### Keyboard | Key | What it does | | --- | --- | | Arrow Down · Arrow Up | Opens the list and moves through the items. | | Enter | Picks the highlighted item. | | Escape | Closes the list; again, clears the text. | | Backspace | In an empty chips field, removes the last chip. | | Arrow Left · Arrow Right | Moves between chips. | --- # Context Menu A menu of actions on whatever was right-clicked or long-pressed. ```tsx import { ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuItem, ContextMenuLabel, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "@/components/ui/context-menu" /** An area that opens a menu on a right click, a long press, or Shift+F10 when focused. */ export default function ContextMenuDemo() { return ( Right-click here, or press and hold Back ⌘[ Forward ⌘] Reload ⌘R More tools Save page as… ⇧⌘S Create shortcut… Developer tools Show bookmarks bar Show full URLs People Ada Lovelace Grace Hopper ) } ``` ## Installation ```bash npx @yolkui/cli add context-menu ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/context-menu.tsx. ## Usage Actions on whatever was right-clicked or long-pressed: a file, a row, a canvas object. Every action in it must also be reachable another way (a button or a Dropdown Menu), since many people never right-click. Wrap the area in ContextMenuTrigger: a right click opens the menu at the pointer, a long press (half a second) opens it on a phone or tablet, and Shift+F10 or the Menu key opens it from a focused element inside the area. The menu is Dropdown Menu's, with the same parts under ContextMenu names: icons, ContextMenuShortcut, checkbox and radio items, ContextMenuSub, variant="destructive", inset. The trigger is a div with no style of its own; nothing changes on it while the menu is open, and data-popup-open is there if you want the row lit. - A long press never selects the text under the finger; on a desktop the text stays selectable. ```tsx import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu" Right-click here Rename Delete ``` ## Composition ```text ContextMenu ├── ContextMenuTrigger └── ContextMenuContent ├── ContextMenuGroup > ContextMenuLabel ├── ContextMenuItem > ContextMenuShortcut ├── ContextMenuLinkItem ├── ContextMenuCheckboxItem ├── ContextMenuRadioGroup > ContextMenuRadioItem ├── ContextMenuSeparator └── ContextMenuSub ├── ContextMenuSubTrigger └── ContextMenuSubContent ``` ## Examples ### In a list Wrap each row in its own ContextMenu, so the menu acts on the row that was clicked. Put the same actions behind a visible button too (a DropdownMenu on an icon button): a context menu is a shortcut, and nothing on a phone says it is there. ```tsx import { Copy, Ellipsis, FileText, Pencil, Trash2 } from "lucide-react" import { Button } from "@/components/ui/button" import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger, } from "@/components/ui/context-menu" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" const files = [ { name: "Q3 report.pdf", size: "2.4 MB" }, { name: "Invoice 0142.pdf", size: "180 KB" }, { name: "Brand guidelines.pdf", size: "12 MB" }, ] /** * Each row opens its menu on a right click or a long press, and the same actions sit * behind a visible button, so nobody has to know the gesture (a phone shows no hint). */ export default function ContextMenuList() { return (
    {files.map((file) => (
  • Rename F2 Duplicate ⌘D Delete
  • ))}
) } ``` ## API Reference Base UI's Context Menu; the same parts as Dropdown Menu. Our additions: | Prop | On | Values | Default | | --- | --- | --- | --- | | variant | `ContextMenuItem` | `default` · `destructive` (red text, for a delete) | `default` | | inset | `ContextMenuItem` · `ContextMenuLinkItem` · `ContextMenuCheckboxItem` · `ContextMenuRadioItem` · `ContextMenuSubTrigger` | `boolean`: lines the text up with items that have an icon | `false` | ## Accessibility The popup is a menu of menuitems, menuitemcheckboxes and menuitemradios, with Dropdown Menu's keys: the arrows move, Home and End go to the ends, typing jumps to an item, ArrowRight opens a submenu and ArrowLeft closes it, Escape closes it and returns focus to where it was. - Never put an action only in a context menu. Keyboard and touch users rarely find it; keep it reachable another way, as Apple's Human Interface Guidelines ask. - A keyboard opens it with Shift+F10 or the Menu key, which reach only a focused element: put the trigger around rows that hold a link or button, or give the area tabIndex={0} and a focus style. - A Mac has no such key: without VoiceOver (which opens it with VO+Shift+M) a keyboard user there cannot open a context menu at all, one more reason to keep its actions in a visible control. - The shortcut text is hidden from screen readers; the item carries the keys as aria-keyshortcuts instead. ### Keyboard | Key | What it does | | --- | --- | | Shift + F10 · Menu key (Windows) | Opens the menu on the focused element. | | Arrow Down · Arrow Up | Moves through the items. | | Arrow Right · Arrow Left | Opens or closes a submenu (mirrored right to left). | | Enter · Space | Chooses the item. | | Escape | Closes the menu. | --- # Dialog A window over the page that holds focus until it closes: a form, a confirmation, details. ```tsx "use client" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Field, FieldLabel } from "@/components/ui/field" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" const visibility = [ { label: "Only me", value: "private" }, { label: "My team", value: "team" }, { label: "Anyone with the link", value: "link" }, ] /** * A form in a dialog: focus starts on the first field and returns to the button when * it closes. Save is async, so the dialog waits for it, loading, and then closes. */ export default function DialogDemo() { async function save() { await new Promise((resolve) => setTimeout(resolve, 1000)) // your request here } return ( }>Edit project Edit project Your team sees the name in the sidebar. Name Visibility }>Cancel } onClick={save}> Save ) } ``` ## Installation ```bash npx @yolkui/cli add dialog ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/dialog.tsx. ## Usage A window over the page that keeps focus until it closes: a form, settings, details. For a yes/no before something that cannot be undone, use an Alert Dialog; for a small panel that leaves the page usable, a Popover. Pass the button that opens it through render: render={

) } ``` ### One dialog, many triggers For an Edit button on every row, render one dialog and link the buttons to it with a handle: createDialogHandle(), passed as handle to Dialog and to each DialogTrigger, with the row's data as payload. Dialog's children become a function of the payload. Triggers can sit anywhere on the page, and focus returns to the one that was pressed. handle.open(), openWithPayload() and close() open and close it from code. ```tsx "use client" import { Button } from "@/components/ui/button" import { createDialogHandle, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Field, FieldLabel } from "@/components/ui/field" import { Input } from "@/components/ui/input" type Member = { name: string; email: string } const members: Member[] = [ { name: "Ada Lovelace", email: "ada@yolkui.com" }, { name: "Grace Hopper", email: "grace@yolkui.com" }, { name: "Alan Turing", email: "alan@yolkui.com" }, ] // One handle links every row's button to the one dialog below (Base UI's handle). const editMember = createDialogHandle() /** * One dialog, many triggers: each row's Edit button carries its member as the * payload, and the dialog reads it. Focus returns to the row's own button. */ export default function DialogDetachedTriggers() { return ( <>
    {members.map((member) => (
  • {member.name} {member.email}
    } > Edit
  • ))}
{({ payload }) => ( Edit {payload?.name} Changes are seen by everyone in the workspace. Email }>Cancel }>Save )} ) } ``` ### Unsaved changes To ask before closing a form with changes, control open and cancel the close in onOpenChange (details.cancel()), then open an Alert Dialog. Put it inside DialogContent: it is then nested, the dialog steps back behind it (a little smaller, lower and dimmer) and only one backdrop covers the page. "Keep editing" returns to the form as it was. ```tsx "use client" import * as React from "react" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Field, FieldLabel } from "@/components/ui/field" import { Input } from "@/components/ui/input" const saved = "Yolk website" /** * Closing with unsaved changes asks first, in an alert over the dialog: the dialog * steps back and stays as it was, so "Keep editing" returns to the form untouched. */ export default function DialogConfirmClose() { const [open, setOpen] = React.useState(false) const [confirming, setConfirming] = React.useState(false) const [name, setName] = React.useState(saved) const dirty = name !== saved return ( { // Escape, the backdrop, the × and Cancel all land here; Save does not. if (!next && dirty) { details.cancel() setConfirming(true) return } setOpen(next) if (next) setName(saved) }} > }>Rename project Rename project Change the name and close without saving to see the question. Name }>Cancel {/* Inside DialogContent, so Base UI knows it is nested. */} Discard changes? You changed the name. Your changes will be lost. Keep editing { setName(saved) setOpen(false) }} > Discard ) } ``` ### Where focus goes Focus moves to the first control when the dialog opens and back to its trigger when it closes. initialFocus and finalFocus on DialogContent change that: a ref to the element, or false to leave focus where it is. Send it to the field people came for, and after an action that removes the trigger, to where the result shows. ```tsx "use client" import * as React from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Field, FieldLabel } from "@/components/ui/field" import { Input } from "@/components/ui/input" /** * Focus goes where you say: initialFocus sends it to the email field, past the link * that comes first, and finalFocus to the list's heading when the dialog closes, * where the new member will show. */ export default function DialogFocus() { const email = React.useRef(null) const heading = React.useRef(null) return (
) } ``` ### Leaving the page usable modal={false} on Dialog keeps the page working behind it: no backdrop, no scroll lock, and focus may leave. Place it out of the way with className. modal="trap-focus" keeps focus inside but still leaves the page clickable. Use these for something that stays open while people work; a question or a form wants the default. ```tsx "use client" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" /** * modal={false}: the page stays usable, so there is no backdrop, no scroll lock and * focus may leave. It sits in a corner, out of the way, and closes on Escape or a * click outside it. For something to keep open while working: a notice, a helper. */ export default function DialogNonModal() { return ( }>Keyboard shortcuts Keyboard shortcuts Keep this open while you work.
Search
⌘K
New project
⌘N
Toggle sidebar
⌘B
}>Close
) } ``` ### Right to left Under dir="rtl" the × moves to the top left and the actions to the left on their own. The dialog is portaled to the end of the body, so put dir and lang on (or on DialogContent, as this example does inside an LTR page); wrap the app in Base UI's DirectionProvider as for Tabs. ```tsx "use client" import { DirectionProvider } from "@base-ui/react/direction-provider" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" /** * Right to left: the × moves to the top left and the footer's actions to the left, * on their own (logical properties). dir and lang go on the content too, since it * is portaled out of the RTL box; an RTL app sets them once on . */ export default function DialogRtl() { return (
{/* Open the dialog */} }>فتح الحوار {/* Leave the project? / You lose access to its pages until someone invites you again. / Cancel · Leave */} مغادرة المشروع؟ ستفقد الوصول إلى صفحاته حتى يدعوك أحد مرة أخرى. }>إلغاء }>مغادرة
) } ``` ## API Reference Our props on top of Base UI's Dialog (open, defaultOpen, onOpenChange, modal, disablePointerDismissal, actionsRef, handle and the rest work as in Base UI). The width is 448; change it with className. | Prop | On | Values | Default | | --- | --- | --- | --- | | scroll | `DialogContent` | `"inside"` · `"outside"` | `"inside"` | | showCloseButton | `DialogContent` | `true` · `false` | `true`, the × in the corner | | closeLabel | `DialogContent` | text | `"Close"`, the ×'s name | | showCloseButton | `DialogFooter` | `true` · `false` | `false`, an outline Close at the end | | closeLabel | `DialogFooter` | text | `"Close"`, the button's text | | onClick | `DialogClose` | a function; when it returns a promise the dialog waits for it, and stays open on a rejection or `false` | — | | loading | `DialogClose` | `true` · `false`: your own work state; the button loads and your code closes the dialog | — | | createDialogHandle() | — | links triggers anywhere to one dialog, with a payload | — | ## Accessibility The popup is a dialog named by its DialogTitle and described by its DialogDescription. Focus moves to the first control inside when it opens (the dialog itself when opened by touch, so no keyboard pops up), Tab and Shift+Tab stay inside, and the page behind is inert and does not scroll. - Always give it a DialogTitle; when the title should not show, give it className="sr-only". - The ×'s name is "Close"; closeLabel translates it. - For a question that needs an answer before anything else happens (deleting, discarding), use Alert Dialog. ### Keyboard | Key | What it does | | --- | --- | | Tab · Shift + Tab | Moves between the controls; focus stays inside. | | Escape | Closes the dialog; focus goes back to what opened it. | --- # Dropdown Menu A menu of actions opened from a button: icons, shortcuts, check and radio items, submenus. ```tsx import { ChevronDown, Copy, Folder, Pencil, Trash2 } from "lucide-react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" /** Actions on a project: icons at the start, shortcuts at the end, a submenu, a destructive item last. */ export default function DropdownMenuDemo() { return ( }> Options Rename F2 Duplicate ⌘D Move to Inbox Archive Shared (read-only) Delete project ⌘⌫ ) } ``` ## Installation ```bash npx @yolkui/cli add dropdown-menu ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/dropdown-menu.tsx. ## Usage A list of actions opened from a button: Edit, Duplicate, Delete, with icons, shortcuts, check and radio items and submenus. For picking a value use a Select; for site navigation, a Navigation Menu. Pass the control the trigger should look like through render: render={ ))} ) } ``` ### Pill shape="pill", the same as the pill Button, with more end padding. ```tsx import { Button } from "@/components/ui/button" import { SearchInput } from "@/components/ui/input" export default function InputPill() { return (
{(["xs", "sm", "default", "lg"] as const).map((size) => (
{size}
))}
) } ``` ### States Rest, filled, invalid, disabled and read-only. Pair an invalid field with FieldError: red is never the only signal. ```tsx import { Input } from "@/components/ui/input" /** Rest, filled, invalid, disabled and read-only. Hover and click the first one. */ export default function InputStates() { return (
) } ``` ### Web form fields The fields a sign-up or checkout form needs, with labels, hints, units and inline actions. ```tsx "use client"; import * as React from "react"; import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field"; import { Input, PasswordInput } from "@/components/ui/input"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, } from "@/components/ui/input-group"; // Common web form fields: Input for one icon or unit, InputGroup when a field // holds more (a prefix and a button, a select, a labeled action). function Glyph({ children }: { children: React.ReactNode }) { return ( ); } const CopyIcon = () => ( ); const MailIcon = () => ( ); const InfoIcon = () => ( ); function Required() { return ( ); } function Optional() { return (optional); } /** An info glyph beside a label. A native title stands in until Tooltip exists. */ function Hint({ children }: { children: string }) { return ( {children} ); } /** A native select that sits inside the field: transparent, our chevron, no box of its own. */ function InlineSelect({ label, options, autoComplete, }: { label: string; options: { label: string; value: string }[]; autoComplete?: string; }) { return ( ); } function CopyButton({ label }: { label: string }) { return ( { const field = event.currentTarget.closest("[data-slot=input-group]")?.querySelector("input"); void navigator.clipboard?.writeText(field?.value || field?.placeholder || ""); }} > ); } export default function InputForm() { return (
Website URL https:// {/* The prefix supplies the scheme, so this is text: type="url" would reject "example.com". inputMode still brings up the URL keyboard. */} Website URL Email Email We won’t spam you, we promise :) Email Used for sign-in and receipts } /> We won’t spam you, we promise :) Email Used for sign-in and receipts } /> That’s not a valid email address ID number } /> Phone number {/* The code and the number autofill separately, so each field gets its own token. */} Quick search ⌘K Password At least 12 characters {/* A rule like "at least 12 characters" means a new password, so managers offer to generate one. */}
); } ``` ### File Our own translatable text over the native input: pick, drop a file on it, or remove it. Text, sizes, shape and right to left are props. ```tsx "use client"; import * as React from "react"; import { Button } from "@/components/ui/button"; import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"; import { FileInput } from "@/components/ui/input"; // FileInput in the cases a page meets: sizes and shapes, disabled, translated, // controlled from outside, and right to left. function ControlledFileInput() { const [files, setFiles] = React.useState([]); return ( Controlled
{files.length === 1 ? "1 file" : `${files.length} files`} in state
); } export default function InputFile() { return (
Attachment Images only, several xs lg, pill Disabled Документ (на български) `${count} файла`} clearLabel="Премахни файловете" dropLabel="Пусни файловете тук" /> מסמך (right to left)
); } ``` ## API Reference Input is Base UI's Input; PasswordInput, SearchInput and FileInput are ours. | Prop | On | Values | Default | | --- | --- | --- | --- | | size | `Input` · `PasswordInput` · `SearchInput` · `FileInput` | `xs` · `sm` · `default` · `lg` | `default` | | shape | `Input` · `PasswordInput` · `SearchInput` · `FileInput` | `default` · `pill` | `default` | | leading · trailing | `Input` | an icon or unit inside the field | — | | toggleLabel | `PasswordInput` | the show/hide button's name | `"Show password"` | | onValueChange | `SearchInput` | `(value) => void`, also on clear | — | | clearLabel | `SearchInput` · `FileInput` | the clear button's name | `"Clear search"` on SearchInput | | value · onValueChange | `FileInput` | `File[]`; pick or drag files in | — | | buttonLabel · placeholder | `FileInput` | the button's text and the empty text | placeholder `"No file chosen"` | ## Accessibility A native input, named by a FieldLabel or an aria-label. - Text is 16px on phones, so iOS does not zoom the page on focus. - Disabled is native disabled: the reason goes in a FieldDescription. - aria-invalid draws the error ring; inside a Field, FieldError says why. - The show-password and clear buttons have names and keep focus in the field. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the field, then to its buttons. | | Escape | In a SearchInput, clears the text. | --- # Input Group The field surface: an input with text, icons or buttons at either end. ```tsx "use client"; import * as React from "react"; import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field"; import { Input, PasswordInput } from "@/components/ui/input"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, } from "@/components/ui/input-group"; // Common web form fields: Input for one icon or unit, InputGroup when a field // holds more (a prefix and a button, a select, a labeled action). function Glyph({ children }: { children: React.ReactNode }) { return ( ); } const CopyIcon = () => ( ); const MailIcon = () => ( ); const InfoIcon = () => ( ); function Required() { return ( ); } function Optional() { return (optional); } /** An info glyph beside a label. A native title stands in until Tooltip exists. */ function Hint({ children }: { children: string }) { return ( {children} ); } /** A native select that sits inside the field: transparent, our chevron, no box of its own. */ function InlineSelect({ label, options, autoComplete, }: { label: string; options: { label: string; value: string }[]; autoComplete?: string; }) { return ( ); } function CopyButton({ label }: { label: string }) { return ( { const field = event.currentTarget.closest("[data-slot=input-group]")?.querySelector("input"); void navigator.clipboard?.writeText(field?.value || field?.placeholder || ""); }} > ); } export default function InputForm() { return (
Website URL https:// {/* The prefix supplies the scheme, so this is text: type="url" would reject "example.com". inputMode still brings up the URL keyboard. */} Website URL Email Email We won’t spam you, we promise :) Email Used for sign-in and receipts } /> We won’t spam you, we promise :) Email Used for sign-in and receipts } /> That’s not a valid email address ID number } /> Phone number {/* The code and the number autofill separately, so each field gets its own token. */} Quick search ⌘K Password At least 12 characters {/* A rule like "at least 12 characters" means a new password, so managers offer to generate one. */}
); } ``` ## Installation ```bash npx @yolkui/cli add input-group ``` Manual: install @base-ui/react@^1.8.0, class-variance-authority@^0.7.1, then copy components/ui/input-group.tsx. ## Usage A text field with icons, text or buttons inside the same shape: a URL prefix, a copy button, a search icon. For one icon or unit, Input's leading and trailing are enough. ```tsx import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group" ``` ## Composition ```text InputGroup ├── InputGroupInput └── InputGroupAddon ├── InputGroupText └── InputGroupButton ``` ## Examples ### Text, icons and buttons InputGroupAddon holds an icon, InputGroupText or an InputGroupButton, at the start or (align="inline-end") at the end. ```tsx import { Copy, Search } from "lucide-react" import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText } from "@/components/ui/input-group" /** Text, icons and buttons inside one field: a prefix, a search icon, a copy button. */ export default function InputGroupAddons() { return (
https:// .app
) } ``` ### Sizes Four sizes, as Button: 28 · 32 · 36 · 40, and shape="pill". ```tsx import { Search } from "lucide-react" import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group" /** Four sizes, as Button: 28 · 32 · 36 · 40, and a pill. */ export default function InputGroupSizes() { return (
{(["xs", "sm", "default", "lg"] as const).map((size) => ( ))}
) } ``` ## API Reference The group is the surface and owns layout; each part styles itself. | Prop | On | Values | Default | | --- | --- | --- | --- | | size | `InputGroup` | `xs` · `sm` · `default` · `lg` | `default` | | shape | `InputGroup` | `default` · `pill` | `default` | | align | `InputGroupAddon` | `inline-start` · `inline-end` | `inline-start` | ## Accessibility InputGroupInput is the field and needs the name; the addons are not part of it. - An icon in an addon is decorative; an InputGroupButton with only an icon needs an aria-label. - Focus on the input outlines the whole group; a focused button shows only its own outline. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the input, then to each button in the group. | --- # Label A plain label for a control outside a Field. ```tsx import { Label } from "@/components/ui/label" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" /** Outside a Field, a Label after the control points at it with htmlFor. */ export default function LabelDemo() { return (
) } ``` ## Installation ```bash npx @yolkui/cli add label ``` ## Usage Names a control that is not in a Field, pointed at with htmlFor. Inside a Field use FieldLabel, which also wires the description and error. Inside a Field, use FieldLabel: it also wires the description and error. Label is for a control on its own, pointed at with htmlFor. Placed after a Checkbox or radio, it fades with a disabled one and shows the not-allowed cursor. ```tsx import { Label } from "@/components/ui/label" ``` ## Examples ### After a checkbox After a Checkbox or radio, Label fades with a disabled one and shows the not-allowed cursor. ```tsx import { Checkbox } from "@/components/ui/checkbox" import { Label } from "@/components/ui/label" /** After a Checkbox, a Label fades with a disabled one and shows the not-allowed cursor. */ export default function LabelCheckbox() { return (
) } ``` ## API Reference A label element with our type role; every native label attribute passes through. | Prop | On | Values | Default | | --- | --- | --- | --- | | htmlFor | `Label` | the id of the control it names | — | ## Accessibility A real label: clicking it focuses or toggles its control, and screen readers read it as the control's name. - Always point it at its control with htmlFor; a label beside a control without it names nothing. --- # Native Select The browser's own select, styled: the system's list on every device. ```tsx import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" /** A select in a form: the browser's own list, on Input's surface. */ export default function NativeSelectDemo() { return ( Country Austria Bulgaria Germany Greece Romania Used for tax and invoices. ) } ``` ## Installation ```bash npx @yolkui/cli add native-select ``` Manual: install @base-ui/react@^1.8.0, class-variance-authority@^0.7.1, then copy components/ui/native-select.tsx. ## Usage The browser's own select, styled: on phones it opens the system's list. Choose it for long or plain lists in forms that must work everywhere; for icons, groups with styling or search, use a Select or Combobox. ```tsx import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" Bulgaria Germany ``` ### When to use it Only the closed control is styled; the open list is the system's: a wheel on iOS, a sheet on Android, a menu on the desktop. That list is large, familiar and fast on every device, it handles hundreds of options, and the select works before JavaScript loads and submits with the form like any other field. Use it when the options are plain text; options with icons, descriptions or a search need a custom select. - Options are NativeSelectOption and NativeSelectOptGroup: with a data-slot, so plain ones work too. - className styles the select's surface, which owns the layout. It is as wide as its longest option; className="w-full" fills the container. - Keep it out of a Toolbar: a toolbar moves focus with the arrow keys, and on a closed select the same keys change the value. ## Composition ```text NativeSelect ├── NativeSelectOptGroup │ └── NativeSelectOption └── NativeSelectOption ``` ## Examples ### Variants soft, the default, is Input's surface, so a select in a form matches the fields around it. variant="outline" and variant="secondary" are the outline and secondary Buttons' surfaces, for a select on its own: a sort, a filter, a table's page size. Beside an Input in a form they would not match. ```tsx import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" /** soft (the default) for forms; outline and secondary for a select on its own, a filter or a sort. */ export default function NativeSelectVariants() { return (
Newest first Oldest first Name Newest first Oldest first Name Newest first Oldest first Name
) } ``` ### Sizes Button's and Input's four heights, 28 · 32 · 36 · 40, so a select lines up with a button or a field of the same size. shape="pill" rounds both ends. ```tsx import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" const sizes = [ { size: "xs", label: "xs · 28" }, { size: "sm", label: "sm · 32" }, { size: "default", label: "default · 36" }, { size: "lg", label: "lg · 40" }, ] as const /** Button's and Input's heights, and the pill shape. */ export default function NativeSelectSizes() { return (
{sizes.map(({ size, label }) => (
{label} 10 rows 25 rows 50 rows 10 rows 25 rows 50 rows
))}
) } ``` ### Placeholder and groups A first option with value="" and disabled is a placeholder: it shows in the muted color until a choice is made, and cannot be picked back. An empty option that is not disabled ("All countries") is a real choice and keeps the full color. With required, the form will not submit while it is chosen. NativeSelectOptGroup labels a group of options in the open list. ```tsx import { Field, FieldLabel } from "@/components/ui/field" import { NativeSelect, NativeSelectOptGroup, NativeSelectOption } from "@/components/ui/native-select" /** A placeholder (an empty, disabled first option) and options in groups. */ export default function NativeSelectGroups() { return ( Timezone Select a timezone London Berlin Sofia New York Chicago Los Angeles Tokyo Singapore ) } ``` ### In a group In a ButtonGroup a select joins its neighbors like a field: one shape, square corners where they meet and one line at each seam. Beside an Input it keeps its width and the Input takes the rest; give the group a width (w-full). An outline select shares its border with outline buttons. ```tsx import { Button } from "@/components/ui/button" import { ButtonGroup } from "@/components/ui/button-group" import { Input } from "@/components/ui/input" import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" /** In a ButtonGroup a select joins its neighbors: one shape, one line at each seam. */ export default function NativeSelectGroup() { return (
EUR USD GBP CSV Excel JSON
) } ``` ### Invalid In an invalid Field the edge and the focus outline turn red, and FieldError says why, with an icon and words. ```tsx import { Field, FieldError, FieldLabel } from "@/components/ui/field" import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" /** Field invalid turns the edge and the focus outline red; FieldError says why. */ export default function NativeSelectInvalid() { return ( Plan Select a plan Free Pro Business Choose a plan to continue. ) } ``` ### Disabled A disabled select fades, cannot be opened and is left out of the form, as a native one is. It is skipped by Tab, so a tooltip could never say why: put the reason in a FieldDescription under it, where everyone sees it, phones included. ```tsx import { Field, FieldDescription, FieldLabel } from "@/components/ui/field" import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select" /** A disabled select fades and is left out of the form, as a native one is. */ export default function NativeSelectDisabled() { return ( Region Europe (Frankfurt) United States (Virginia) The region is set when the project is created. ) } ``` ## API Reference A native select element; every select attribute passes through. Our additions: | Prop | On | Values | Default | | --- | --- | --- | --- | | variant | `NativeSelect` | `soft` · `outline` · `secondary` | `soft` | | size | `NativeSelect` | `xs` · `sm` · `default` · `lg` | `default` | | shape | `NativeSelect` | `default` · `pill` | `default` | | onValueChange | `NativeSelect` | `(value: string) => void` | — | ## Accessibility It is the browser's own select, so every screen reader, keyboard and switch device already knows it: Space or Alt+Down opens it, arrows move, typing jumps to an option. Screen readers hear the label, "pop-up button" or "combo box", and the chosen option. - Give it a label: a FieldLabel in a Field, or aria-label when it stands alone ("Sort by"). - Text is 16px on phones, so iOS does not zoom the page in when it opens. - Options cannot be styled in the open list, so never rely on color or icons there; the text carries the meaning. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves to the select. | | Arrow Down · Arrow Up | Changes the value (on some systems, opens the list). | | Space · Alt + Arrow Down | Opens the system's list. | | A letter | Jumps to the next option starting with it. | --- # Navigation Menu The row of links at the top of a site; some items open a panel of more links. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" const product = [ { title: "Analytics", description: "See who visits and what they do.", href: "#analytics" }, { title: "Automations", description: "Run the repeated work by itself.", href: "#automations" }, { title: "Integrations", description: "Connect the tools you already use.", href: "#integrations" }, { title: "Security", description: "Sign-in, roles and an audit log.", href: "#security" }, ] const solutions = [ { title: "For startups", description: "Start free, grow when you do.", href: "#startups" }, { title: "For enterprise", description: "Security and support at scale.", href: "#enterprise" }, ] /** * Two items that open a panel and two plain links. One panel serves both items: it * moves and resizes as the pointer goes from one to the other. `active` marks the * page you are on. */ export default function NavigationMenuDemo() { return ( Product
    {product.map((link) => (
  • {link.title} {link.description}
  • ))}
Solutions
    {solutions.map((link) => (
  • {link.title} {link.description}
  • ))}
Pricing Docs
) } ``` ## Installation ```bash npx @yolkui/cli add navigation-menu ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/navigation-menu.tsx. ## Usage The row of links at the top of a site, where some items open a panel of more links. For actions use a Dropdown Menu; for sections of one page, Tabs. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" Products … Pricing ``` ### The current page active on a link marks the page you are on: it keeps the gray fill and is read as the current page. An open item has the same fill; its chevron turned up tells them apart. The menu does not know your routes, so compare the address yourself. ```tsx const pathname = usePathname() } active={pathname === "/pricing"}> Pricing ``` ### Search engines A panel's links are added to the page only when it opens, so they are not in the HTML the server sends. keepMounted on NavigationMenuContent keeps them there, hidden, for a crawler to follow. Use it on a public site's main menu. ```tsx … ``` ### In a header that stays in place A panel is placed in the page, so under a fixed or sticky header it would scroll away from its item. positionMethod="fixed" keeps it with the header. A panel taller than the room under the row scrolls inside itself. ```tsx … ``` ## Composition ```text NavigationMenu ├── NavigationMenuList │ └── NavigationMenuItem │ ├── NavigationMenuTrigger │ ├── NavigationMenuContent > NavigationMenuLink … │ └── NavigationMenuLink ├── NavigationMenuPanel (inline) └── NavigationMenuPositioner > NavigationMenuIndicator ``` ## Examples ### Items and their panel An item is either a link or a trigger that opens a panel of more links. There is one panel for the whole menu: it sits under the open item and moves and resizes as the pointer goes along the row. Give the list inside each NavigationMenuContent a width; the panel takes it. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" const product = [ { title: "Analytics", description: "See who visits and what they do.", href: "#analytics" }, { title: "Automations", description: "Run the repeated work by itself.", href: "#automations" }, { title: "Integrations", description: "Connect the tools you already use.", href: "#integrations" }, { title: "Security", description: "Sign-in, roles and an audit log.", href: "#security" }, ] const solutions = [ { title: "For startups", description: "Start free, grow when you do.", href: "#startups" }, { title: "For enterprise", description: "Security and support at scale.", href: "#enterprise" }, ] /** * Two items that open a panel and two plain links. One panel serves both items: it * moves and resizes as the pointer goes from one to the other. `active` marks the * page you are on. */ export default function NavigationMenuDemo() { return ( Product
    {product.map((link) => (
  • {link.title} {link.description}
  • ))}
Solutions
    {solutions.map((link) => (
  • {link.title} {link.description}
  • ))}
Pricing Docs
) } ``` ### Links with icons A link in a panel stacks its children, which suits a title over a description. For one line with an icon, give it flex-row items-center gap-2. ```tsx import { BookOpen, LifeBuoy, Newspaper, Terminal } from "lucide-react" import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" /** * Short links with an icon: one line each. A link in a panel stacks its children, * so `flex-row items-center gap-2` puts the icon beside the text. */ export default function NavigationMenuIcons() { return ( Resources
  • Guides
  • API reference
  • Changelog
  • Support
Blog
) } ``` ### Sizes size takes Button's four sizes: xs, sm, default and lg, 28 to 40 high, so the row lines up with buttons beside it in a header. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" const sizes = ["xs", "sm", "default", "lg"] as const /** Button's four sizes, 28 to 40 high, so the row lines up with buttons beside it. */ export default function NavigationMenuSizes() { return (
{sizes.map((size) => ( Product
  • Analytics
  • Automations
Pricing Docs
))}
) } ``` ### With a router render takes your router's link, so a page changes without a reload. A link in a panel closes the menu when it is clicked; closeOnClick={false} keeps it open. ```tsx import Link from "next/link" import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" /** * A router's link through render, so a page changes without a reload. A link in a * panel closes the menu on a click, so it is not left open over the next page. */ export default function NavigationMenuRouter() { return ( Get started
  • }> Installation Add YolkUI to a project.
  • }> CLI Add components from the terminal.
}>Components
) } ``` ### Vertical orientation="vertical" makes a column for a sidebar. The panel opens beside the item and the chevrons point that way. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" /** * A column, for a sidebar: the panel opens beside the item, the chevrons point * there, and the arrow keys go up and down. */ export default function NavigationMenuVertical() { return ( Overview Projects
  • Atlas
  • Beacon
  • All projects
Team
  • Members
  • Roles
) } ``` ### A second level Put a NavigationMenu inside a panel for a second level. Its items become rows of the panel, and a trigger among them opens its own panel beside it. Keep it to two levels; deeper menus are hard to steer with a pointer and to follow with a screen reader. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" /** * A second level: a NavigationMenu inside a panel. Its items are rows of the panel, * and a trigger among them opens its own panel beside it. */ export default function NavigationMenuNested() { return ( Handbook Welcome Styling
  • Tokens
  • Dark mode
  • Radius
Accessibility
  • Keyboard
  • Screen readers
Changelog
) } ``` ### A second level in the same panel For a large menu, the second level can stay in the panel instead of opening another one: rows at the start, and the links of the chosen row beside them. Put inline on the nested NavigationMenu, a NavigationMenuPanel after its list, and a defaultValue so one row is always chosen. On a phone the rows sit above their links. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuPanel, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" const audiences = [ { value: "developers", label: "Developers", links: [ { title: "API reference", description: "Every endpoint, with examples.", href: "#api-reference" }, { title: "Docs", description: "Guides to build your first project.", href: "#guides-inline" }, { title: "Changelog", description: "What shipped this week.", href: "#changelog-inline" }, ], }, { value: "design", label: "Design systems", links: [ { title: "Tokens", description: "One source for color, type and space.", href: "#tokens-inline" }, { title: "Theming", description: "Your brand on every component.", href: "#theming-inline" }, ], }, { value: "startups", label: "Startups", links: [ { title: "Pricing", description: "Start free, grow when you do.", href: "#pricing-inline" }, { title: "Templates", description: "A head start for common pages.", href: "#templates-inline" }, ], }, ] /** * A second level that stays in the same panel: inline on the nested menu, a * NavigationMenuPanel after its list, and a defaultValue so one row is always chosen. * The rows sit beside their links from the md breakpoint up, and above them on a phone. */ export default function NavigationMenuInline() { return ( Product {audiences.map((audience) => ( {audience.label}
    {audience.links.map((link) => (
  • {link.title} {link.description}
  • ))}
))}
Pricing
) } ``` ### Disabled disabled on a trigger fades it and stops it opening, but it stays in the Tab order, so a Tooltip around it can say why. ```tsx import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" /** * A disabled trigger fades to 60% and opens nothing, but stays focusable, so a * tooltip can say why, on hover and on focus. Phones never see a tooltip, so keep * the reason short and not essential. */ export default function NavigationMenuDisabled() { return ( Projects }>Reports Available on the Business plan
  • Usage
Settings
) } ``` ### On a phone A tap opens the panel and a tap outside closes it. The panel is never wider than the screen, and a row too long for its place wraps. A row of many items still does not suit a phone: below your breakpoint, hide the row and show a menu button that opens the same links in a Dialog, each link closing it. Narrow the window to see the button here. ```tsx "use client" import * as React from "react" import { Menu } from "lucide-react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, navigationMenuTriggerStyle, } from "@/components/ui/navigation-menu" import { cn } from "@/lib/utils" const product = [ { title: "Analytics", href: "#analytics-phone" }, { title: "Automations", href: "#automations-phone" }, { title: "Integrations", href: "#integrations-phone" }, ] const pages = [ { title: "Pricing", href: "#pricing-phone" }, { title: "Docs", href: "#docs-phone" }, ] /** * One list of links, shown two ways: the row from the md breakpoint up, and below it * a menu button that opens the same links in a dialog, each one closing it. Narrow * the window to see the button. */ export default function NavigationMenuPhone() { const [open, setOpen] = React.useState(false) return ( <> Product
    {product.map((link) => (
  • {link.title}
  • ))}
{pages.map((link) => ( {link.title} ))}
}>
Menu ) } ``` ### Right to left Under dir="rtl" the row starts at the right and the panel opens from the item's right edge. Wrap the app in Base UI's DirectionProvider as well, so the arrow keys turn around too. ```tsx "use client" import { DirectionProvider } from "@base-ui/react/direction-provider" import { NavigationMenu, NavigationMenuContent, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, } from "@/components/ui/navigation-menu" /** * In a right-to-left page the row starts at the right, the panel opens from the * item's right edge and the arrow keys turn around. The app sets dir="rtl" and * wraps its root in DirectionProvider, which also turns the panel (it is drawn * outside this box). The text is Arabic; lang is repeated on the panel's list. */ export default function NavigationMenuRtl() { return (
{/* Main: Product (Analytics, Automations), Pricing, Docs */} المنتج
  • التحليلات اعرف من يزور موقعك وماذا يفعل.
  • الأتمتة دع العمل المتكرر يعمل وحده.
الأسعار المستندات
) } ``` ## API Reference NavigationMenu draws the panel itself, so the placement props go on it. | Prop | Type | What it does | | --- | --- | --- | | size | `xs` · `sm` · `default` · `lg` | On NavigationMenu: the height of the items in the row. `default` (36). | | orientation | `horizontal` · `vertical` | On NavigationMenu: a row or a column. `horizontal` by default. | | align | `start` · `center` · `end` | On NavigationMenu: which edge of the open item the panel lines up with. `start` by default. | | side | `bottom` · `top` · `inline-end` · `inline-start` | On NavigationMenu: where the panel opens. `bottom`, or `inline-end` in a vertical menu. | | sideOffset | `number` | On NavigationMenu: the gap between the row and the panel. 6 by default. | | inline | `boolean` | On a NavigationMenu inside a panel: its second level stays in that panel. Needs a `NavigationMenuPanel` after the list and a `defaultValue`. | | positionMethod | `absolute` · `fixed` | On NavigationMenu: `fixed` for a menu in a header that does not scroll. `absolute` by default. | | keepMounted | `boolean` | On NavigationMenuContent: keep the panel's links in the HTML while it is closed, for search engines. | | value | any | On NavigationMenu: the open item, when you control it; `defaultValue` and `onValueChange` go with it. Give each NavigationMenuItem a `value`. | | delay | `number` | On NavigationMenu: milliseconds before a panel opens under the pointer. 50 by default; `closeDelay` is the same for closing. | | aria-label | `string` | On NavigationMenu: the landmark's name. "Main" by default. | | active | `boolean` | On NavigationMenuLink: this is the current page. | | closeOnClick | `boolean` | On NavigationMenuLink: close the menu when the link is clicked. On for a link in a panel. | | render | element | On NavigationMenuLink: your router's link. | | disabled | `boolean` | On NavigationMenuTrigger: it fades, stays in the Tab order and opens nothing. | | navigationMenuTriggerStyle | `({ size }) => string` | The classes of an item in the row, for a link outside the menu that should match. | ## Accessibility The menu is a nav landmark named "Main" holding a list of links and buttons. It is site navigation, not an application menu, so it uses no menu roles and a screen reader reads it as ordinary links. - Tab moves through the items. The arrow keys move along the row too, and Home and End jump to its ends. - Enter, Space or the down arrow opens a panel; Tab then goes into its links, and Escape closes it and returns focus to the item. - A trigger says whether its panel is expanded or collapsed. The pointer opens a panel on hover, but nothing depends on hover: a click or the keyboard does the same. - The current page carries aria-current="page". It is shown by a fill, a shape, not by a text color. - With several nav landmarks on a page (this one, a breadcrumb, a footer), give each its own name with aria-label. - An open panel is a landmark too, named by the item that opened it. So give the menu a name that none of its items has: a menu named "Product" with an item "Product" would be read as two landmarks with one name. - Under reduced motion the panel appears and changes size at once. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves between the top-level items. | | Enter · Space · Arrow Down | Opens the focused item's panel. | | Tab (in a panel) | Moves through its links. | | Escape | Closes the panel; focus goes back to its item. | --- # Pagination Links to the pages of a long list: Previous, the page numbers, Next. ```tsx import { Pagination } from "@/components/ui/pagination" /** Give it how many pages there are; it draws the row and keeps its width. */ export default function PaginationDemo() { return } ``` ## Installation ```bash npx @yolkui/cli add pagination ``` ## Usage Links to the pages of a long list or results: Previous, the numbers, Next. For a feed that loads as you scroll, a Load more button is kinder; for steps in a process, a progress of steps. ```tsx import { Pagination } from "@/components/ui/pagination" ``` ### Many pages The first and last page always stay, and three dots stand for the pages left out. The row takes the same seven places on every page, so it never changes width and Next stays under the pointer while you click through. Below the sm breakpoint it shows five places and Previous and Next keep only their arrows, so it fits a 320px phone. ## Composition ```text Pagination └── PaginationContent └── PaginationItem ├── PaginationPrevious ├── PaginationLink ├── PaginationEllipsis └── PaginationNext ``` ## Examples ### Pages in the address When the page number lives in the URL, pass href with {page} standing for the number. Every page is then a real link: it opens in a new tab, can be shared, and a search engine can follow it. Without href the pages are buttons and onPageChange tells you which one was chosen. ```tsx import { Pagination } from "@/components/ui/pagination" /** * Pages that live in the address: each number is a real link, so it opens in a new * tab and a search engine can follow it. {page} stands for the number. */ export default function PaginationLinks() { return } ``` ### Sizes size takes Button's four sizes: xs, sm, default and lg, 28 to 40 high. A row of buttons beside it at the same size lines up. ```tsx "use client" import * as React from "react" import { Pagination } from "@/components/ui/pagination" /** Button's four sizes: 28, 32, 36 and 40 high. */ export default function PaginationSizes() { const [page, setPage] = React.useState(3) return (
) } ``` ### Under a table Say what is shown at the start and put the pages at the end. The row centers itself in the space it is given; className="mx-0 w-auto" lets it sit at one side. ```tsx "use client" import * as React from "react" import { Pagination } from "@/components/ui/pagination" const perPage = 20 const rows = 187 /** Under a table: what is shown at the start, the pages at the end. */ export default function PaginationSummary() { const [page, setPage] = React.useState(2) const total = Math.ceil(rows / perPage) const first = (page - 1) * perPage + 1 const last = Math.min(page * perPage, rows) return (

Showing {first}–{last} of {rows} invoices

) } ``` ### In a narrow place The row reads the width of the screen, not of the box it sits in. In a card or a side panel on a wide screen, compact gives the five places and the arrows without words at every width. ```tsx import { Pagination } from "@/components/ui/pagination" /** In a narrow place on a wide screen: five places and arrows without words. */ export default function PaginationCompact() { return (
) } ``` ### With a router renderLink takes your router's link, so a page changes without a reload. It reads its address from href, so this works in a server page too. A function that returns the link works from a client component. ```tsx import Link from "next/link" import { Pagination } from "@/components/ui/pagination" /** * A router's link for every page, so a page changes without a reload. The link * takes its address from href, so this works in a server page too. */ export default function PaginationRouter() { return ( } /> ) } ``` ### The parts Leave out page and total and write the items yourself. PaginationLink is a link; isActive marks the current page, and disabled draws one that goes nowhere. ```tsx import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "@/components/ui/pagination" /** The parts on their own, when you want to decide every item yourself. */ export default function PaginationParts() { return ( 1 2 3 ) } ``` ### Right to left Under dir="rtl" the row starts at the right and the chevrons turn around. The words and the names a screen reader hears are props, so they can be translated. ```tsx "use client" import * as React from "react" import { Pagination } from "@/components/ui/pagination" /** * In a right-to-left page the row starts at the right and the chevrons turn * around on their own. The text is Arabic (lang="ar"), as in a real RTL app. */ export default function PaginationRtl() { const [page, setPage] = React.useState(3) return ( `الصفحة ${n}`} page={page} total={9} onPageChange={setPage} /> ) } ``` ## API Reference Pagination draws the whole row from these props. Every part also takes className and the props of its element. | Prop | Type | What it does | | --- | --- | --- | | page | `number` | The current page, from 1, when you hold it yourself. | | defaultPage | `number` | The page to start on when the row holds it. 1 by default. | | total | `number` | How many pages there are. With it, the row is drawn for you. | | onPageChange | `(page) => void` | Called with the page that was chosen. | | href | `string` or `(page) => string` | The address of a page; `{page}` in the text stands for the number. Makes every page a link. | | renderLink | element or `(page) => element` | Your router's link. An element takes its address from `href`. | | compact | `boolean` | Five places and arrows without words at every width. | | siblings | `number` | Pages shown on each side of the current one. 1 by default. | | size | `xs` · `sm` · `default` · `lg` | Button's sizes. | | previousText · nextText | `string` | The words on the two ends. "Previous" and "Next". | | previousLabel · nextLabel · getPageLabel | `string` · `(page) => string` | What a screen reader hears: "Go to previous page", "Go to next page", "Page 3". | | PaginationLink | `a` | One page. `isActive`, `disabled`, `size`, and `render` for a router's link or a button. | | PaginationPrevious · PaginationNext | `a` | The two ends: a chevron and `text`. | | PaginationEllipsis | `span` | Three dots where pages are left out. | | getPaginationRange | `(page, total, siblings?)` | The list of pages and "ellipsis" the row shows, for a row you build yourself. Call it from a client component. | ## Accessibility The row is a nav landmark named "Pagination" holding a list, so a screen reader can jump to it and hears how many items there are. - The current page carries aria-current="page" and wears a border, so color is never its only sign. - A page number is read as "Page 3", and the two ends as "Go to previous page" and "Go to next page", also on a phone where only their arrows show. - On the first page Previous has nowhere to go: it fades, is read as dimmed, stays in the Tab order and does nothing. The same for Next on the last page. Keyboard focus stays on it when it turns inactive. - The three dots are decoration and are hidden from screen readers. - With several nav landmarks on a page, each needs its own name: translate or change it with aria-label. - After a page changes, move focus or the scroll position to the top of the new results yourself; the row cannot know where they start. ### Keyboard | Key | What it does | | --- | --- | | Tab | Moves through Previous, the page numbers and Next. | | Enter | Goes to the focused page. | --- # Popover A small panel opened from a button: a short form, settings or a date picker, with the page usable around it. ```tsx "use client" import { Button } from "@/components/ui/button" import { Field, FieldLabel } from "@/components/ui/field" import { Input } from "@/components/ui/input" import { Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger } from "@/components/ui/popover" const fields = [ { id: "width", label: "Width", value: "100%" }, { id: "max-width", label: "Max. width", value: "300px" }, { id: "height", label: "Height", value: "25px" }, ] /** * A short form in a popover. The title names it for screen readers; focus moves to * the first field and returns to the button on Escape or a click outside. */ export default function PopoverDemo() { return ( }>Dimensions Dimensions Set the size of the layer.
{fields.map((field) => ( {field.label} ))}
) } ``` ## Installation ```bash npx @yolkui/cli add popover ``` Manual: install @base-ui/react@^1.8.0, then copy components/ui/popover.tsx. ## Usage A small panel opened from a button that holds anything: a short form, settings, a date picker. The page stays usable around it. For a short text on hover use a Tooltip; for something that needs full attention, a Dialog. Pass the button that opens it through render: render={