=============== LIBRARY RULES =============== From library maintainers: - Import components from 'chunks-ui'. In React Server Components import the React-free helpers (cn, cnState, *Variants, DEFAULT_*_LABELS, mergeLabels) from 'chunks-ui/utils', because 'chunks-ui' is a client bundle. - Load the theme with @import 'chunks-ui/theme.css' right after @import 'tailwindcss'. No Tailwind plugin or config file is needed. - chunks-ui needs React 19.2+ and Tailwind CSS v4. Motion is optional: without the motion package the components fall back to CSS transitions. - Compose with the Base UI render prop. chunks-ui components do not support asChild. - Use the color prop (primary, secondary, destructive, success, warning) and the variant prop where a component offers them, before adding custom classes. - Change built-in English text with the labels prop and pass only the keys that change. - Wrap a subtree in to render its popups inside that element instead of document.body. ### Install chunks-ui and motion with bun Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx Install the chunks-ui package and the optional motion peer dependency. The install command does not add tailwindcss; the app is expected to have Tailwind v4 set up already. Node 24.22.1 or newer is required. ```bash bun add chunks-ui motion ``` -------------------------------- ### Import components from chunks-ui Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx Import components as needed in your application code. This example imports Button, Input, and Tabs from the chunks-ui package. ```tsx import { Button, Input, Tabs } from "chunks-ui"; ``` -------------------------------- ### Development commands Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/README.md Run these commands in order to install dependencies, build, test, and lint the project. ```bash bun install bun run build bun run test bun run lint ``` -------------------------------- ### Import only used components' CSS Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/README.md Replace theme.css with theme.core.css and import one CSS file per component to generate only the CSS for the components you use. A component rendered without its file gets no styles (or only shared ones) and no warning is given. ```css @import "tailwindcss"; @import "chunks-ui/theme.core.css"; @import "chunks-ui/sources/button.css"; @import "chunks-ui/sources/dialog.css"; ``` -------------------------------- ### Install chunks-ui and motion with bun Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/README.md Install the chunks-ui component library and the optional motion package. The command does not add tailwindcss; the app is expected to have Tailwind v4 set up already. Requires Node 24.22.1 or newer. ```bash bun add chunks-ui motion ``` -------------------------------- ### Import only used components with theme.core.css Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx To generate only the CSS of the components you use, import theme.core.css in place of theme.css, then one file for each component the app renders. Import theme.core.css before every chunks-ui/sources/ file; otherwise the components get no classes and nothing warns you. ```css @import "tailwindcss"; @import "chunks-ui/theme.core.css"; @import "chunks-ui/sources/button.css"; @import "chunks-ui/sources/dialog.css"; ``` -------------------------------- ### Input with startAdornment Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/input.mdx Adds a search icon at the start of the input using the startAdornment prop. ```tsx } placeholder="Search..." aria-label="Search" /> ``` -------------------------------- ### Setup Toast.Provider and Toast.Viewport Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Wrap your app or relevant subtree with Toast.Provider and place Toast.Viewport where toasts should render. ```tsx export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {children} ) } ``` -------------------------------- ### Install @tanstack/react-table with bun Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/data-table.mdx Adds the TanStack Table dependency required for building data tables with chunks-ui's Table component. ```bash bun add @tanstack/react-table ``` -------------------------------- ### Basic Usage with Toast.useToast() Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Use Toast.useToast() to get the add function and trigger notifications. ```tsx function SaveButton() { const { add } = Toast.useToast() return ( ) } ``` -------------------------------- ### Import Tooltip and Button from chunks-ui Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/tooltip.mdx Import the Tooltip and Button components from the chunks-ui package before using them in your application. ```tsx import { Button, Tooltip } from "chunks-ui"; ``` -------------------------------- ### Basic Drawer Usage with Trigger, Portal, Backdrop, Popup, Title, Description, and Close Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/drawer.mdx Basic drawer structure using Drawer.Root, Drawer.Trigger, Drawer.Portal, Drawer.Backdrop, Drawer.Popup, Drawer.Title, Drawer.Description, and Drawer.Close. The example includes a navigation menu with links and a close button. ```tsx Open Drawer Navigation Browse the app sections. Close ``` -------------------------------- ### Basic Tooltip Usage Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/tooltip.mdx Basic tooltip structure using Tooltip.Root, Trigger, Portal, Positioner, and Popup. The trigger renders a Button with an outlined variant and the popup displays the tooltip text. ```tsx }>Hover me Helpful tip ``` -------------------------------- ### Import components from chunks-ui Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/README.md Import the Button, Tabs, and Input components from the chunks-ui package. chunks-ui is a client bundle ("use client"); for server components, import utilities like cn, cnState, or buttonVariants from chunks-ui/utils. ```tsx import { Button, Tabs, Input } from 'chunks-ui' ``` -------------------------------- ### Minimal Card with Content Only Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/card.mdx Shows a minimal card using only Card.Root and Card.Content. Each part gets the same padding from the edges. ```tsx

Simple card with content only.

``` -------------------------------- ### Toast.promise with loading, success, and error options Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Wires a single toast through an async operation's lifecycle. Starts with loading options, then swaps to success or error when the promise settles. success and error can be functions receiving the resolved value or rejection reason. Returns the original promise so you can still await or .catch() it downstream. ```tsx import { CheckCircle2, XCircle } from 'lucide-react' const { promise } = Toast.useToast() promise(uploadFile(), { loading: { title: "Uploading file…", description: "Hold tight." }, success: (result) => ({ title: "Upload complete", description: `Saved ${result.name} to your workspace.`, icon: CheckCircle2, iconClassName: "text-success-text", }), error: (err) => ({ title: "Upload failed", description: err.message, icon: XCircle, iconClassName: "text-destructive-text", }), }) ``` -------------------------------- ### Custom fallback examples Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/avatar.mdx Override auto-generated initials with the fallback prop. The fallback can be a simple string or combined with alt and src. ```tsx ``` ```tsx ``` ```tsx ``` -------------------------------- ### Default Open Items Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/accordion.mdx Pass an array of item values to `defaultValue` to start with those items expanded. ```tsx {/* items */} ``` -------------------------------- ### Menu.Content positioning props Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/menu.mdx Menu.Content accepts positioning props forwarded to Base UI's positioner. The example sets side, align, and sideOffset. ```tsx ... ``` -------------------------------- ### Import helpers from chunks-ui/utils in a server component Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/utilities.mdx In a React Server Component, import helpers like `buttonVariants` and `cn` from `chunks-ui/utils` instead of the main bundle. This entry has no `"use client"` and no React code, so its functions run on the server. The example shows a server component rendering a link with merged class names. ```tsx import { buttonVariants, cn } from "chunks-ui/utils"; export function ButtonDocsLink() { return ( Button docs ); } ``` -------------------------------- ### Tooltip Provider with Shared Delay Settings Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/tooltip.mdx Wraps multiple Tooltip.Root components in a Tooltip.Provider to share delay settings. All triggers inside open after the Provider's delay, and moving between nearby tooltips opens them instantly. A delay on a Tooltip.Trigger overrides the Provider's delay for that trigger. Use the chunks-ui Provider, not the one from @base-ui/react/tooltip, as chunks-ui triggers ignore a Base UI Provider's delay. A nested Tooltip.Provider without a delay uses 50ms, not the outer Provider's delay, so repeat the outer delay on it. ```tsx }>A Tooltip A }>B Tooltip B ``` -------------------------------- ### Tabs.Animate with initial/animate/transition props Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/tabs.mdx Use when only one panel is mounted at a time (e.g., router-driven setup). Pass initial, animate, and transition props to control the animation of the active panel content. ```tsx Home Profile Settings

Content for the {tab} tab

``` -------------------------------- ### toast.promise(promise, { loading, success, error }) Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Wires a single toast through the lifecycle of an async operation. It starts with the loading options, then swaps to success or error once the promise settles. The method returns the original promise, so you can still await or .catch() it downstream. ```APIDOC ## toast.promise(promise, { loading, success, error }) ### Description Wires a single toast through the lifecycle of an async operation. It starts with the `loading` options, then swaps to `success` or `error` once the promise settles. `success` and `error` can be static options or functions that receive the resolved value / rejection reason. The method returns the original promise, so you can still `await` or `.catch()` it downstream — the toast is a side effect, not a replacement for your own error handling. ### Method `toast.promise` ### Parameters - **promise** (Promise) - Required - The async operation to track. - **loading** (object) - Required - Toast options for the loading state. - **success** (object | function) - Required - Toast options for success, or a function receiving the resolved value. - **error** (object | function) - Required - Toast options for error, or a function receiving the rejection reason. ### Request Example ```tsx const { promise } = Toast.useToast() promise(uploadFile(), { loading: { title: "Uploading file…", description: "Hold tight." }, success: (result) => ({ title: "Upload complete", description: `Saved ${result.name} to your workspace.`, icon: CheckCircle2, iconClassName: "text-success-text", }), error: (err) => ({ title: "Upload failed", description: err.message, icon: XCircle, iconClassName: "text-destructive-text", }), }) ``` ### Response Returns the original promise, so you can still `await` or `.catch()` it downstream. ``` -------------------------------- ### Import Tailwind and chunks-ui theme Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/README.md Add the theme to the CSS file that imports Tailwind. The theme.css registers CSS variables with Tailwind CSS v4 via @theme and uses @source to generate the classes the components use, so no plugin is needed. ```css @import "tailwindcss"; @import "chunks-ui/theme.css"; ``` -------------------------------- ### Override default font with @theme Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx Importing the theme sets the page's default font to Manrope via Tailwind's preflight (--font-sans), or to the browser's generic sans-serif when Manrope is not loaded. To keep your app's font, set the token after the import as shown. ```css @import "tailwindcss"; @import "chunks-ui/theme.css"; @theme { --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif; } ``` -------------------------------- ### Import theme CSS in Tailwind CSS file Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx Add these imports to the CSS file that imports Tailwind (e.g., app/globals.css). The theme CSS exposes OKLCH color tokens as CSS variables and registers them with Tailwind CSS v4 through @theme; its @source tells Tailwind to scan the package for component classes, so no plugin is needed. ```css @import "tailwindcss"; @import "chunks-ui/theme.css"; ``` -------------------------------- ### Use useReducedMotion hook in a BackToTop button Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/getting-started.mdx The useReducedMotion hook returns true when the user has requested reduced motion (prefers-reduced-motion: reduce) and false otherwise. It follows the setting if the user changes it while the page is open. On the server and while hydrating, it returns false; for animations that must be off from the first paint, use the CSS motion-reduce: variant instead. ```tsx import { Button, useReducedMotion } from "chunks-ui"; export function BackToTop() { const reduced = useReducedMotion(); return ( ); } ``` -------------------------------- ### Minimal Empty state with title and description only Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/empty.mdx All parts except Root are optional. Use just a title and description for simple cases. ```tsx No results There are no items to display yet. ``` -------------------------------- ### Removable Chip Example Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/chip.mdx Demonstrates a removable chip with an onRemove callback. The remove button reads its label and then the chip's text, for example "Remove React". To put the chip's text first, mark its place with {chip}. ```tsx function TagList() { const [tags, setTags] = useState(["React", "TypeScript", "Tailwind"]); return (
{tags.map((tag) => ( setTags((prev) => prev.filter((t) => t !== tag))} > {tag} ))}
); } ``` -------------------------------- ### With Field: Label, Description, and Input Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/input.mdx Wraps `Input` in a `Field.Root` to provide a label, description, and input. The description gives additional guidance for the input. ```tsx Username Choose a unique username ``` -------------------------------- ### Import Resizable and sanitizeLayout Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/resizable.mdx Import the Resizable component and the sanitizeLayout utility from chunks-ui. ```tsx import { Resizable, sanitizeLayout } from "chunks-ui"; ``` -------------------------------- ### Tooltip with Arrow Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/tooltip.mdx Adds a Tooltip.Arrow inside the Tooltip.Popup to display an arrow pointing to the trigger element. ```tsx }>Info This is a tooltip with an arrow. ``` -------------------------------- ### Create the table instance with useTable Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/data-table.mdx Initializes the table with features, data, columns, and controlled state for sorting, filtering, and row selection. Sets page size to 5 rows per page, overriding TanStack's default of 10. ```tsx import { useTable } from "@tanstack/react-table"; const table = useTable({ features, data, columns, state: { sorting, columnFilters, rowSelection }, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, onRowSelectionChange: setRowSelection, // TanStack shows 10 rows per page by default initialState: { pagination: { pageIndex: 0, pageSize: 5 } }, }); ``` -------------------------------- ### sanitizeLayout Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/resizable.mdx Makes a layout that came from storage safe to use. It never throws and handles invalid input gracefully. ```APIDOC ## Function: sanitizeLayout ### Description Makes a layout that came from storage safe to use. `panels` is a list of `{ id, defaultSize?, minSize?, maxSize? }`, the same fields as the panels' props. It never throws. ### Signature ```ts function sanitizeLayout(raw: unknown, panels: readonly ResizablePanelConfig[]): ResizableLayout; ``` ### Parameters - **raw** (unknown) - Required - The raw layout data from storage. - **panels** (readonly ResizablePanelConfig[]) - Required - List of panel configurations with `id`, optional `defaultSize`, `minSize`, `maxSize`. ### Behavior - Input that is not a plain object (`null`, a string, an array, `undefined`) gives the defaults. - Ids that match no panel are dropped. - A panel whose `id` is empty or `__proto__`, or that repeats the `id` of an earlier panel, is skipped. - A missing value, or one that is not a finite, non-negative number, is filled from the panel's default. Missing % panels take what the others leave of 100. - A px panel is clamped to its px `minSize` and `maxSize`. - The % shares are scaled to add up to 100. In a group of % panels only, they are also clamped to the panels' % `minSize` and `maxSize`, and the difference goes to the panels that have room, so the result is inside the limits and still adds up to 100 (`{ side: 99, main: 1 }` with `side` at most `60%` gives `{ side: 60, main: 40 }`). - When the group has a px panel, a % limit is a percent of the measured size, which the server doesn't have. `sanitizeLayout` then leaves % limits out, and the group applies them once it has measured. So does a limit in the other unit of a panel. ### Returns - **ResizableLayout** - The sanitized layout. ``` -------------------------------- ### Toast.useToast().add() Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Adds a new toast to the viewport. Accepts options for title, description, action, priority, dismissibility, and close handling. ```APIDOC ## Toast.useToast().add() ### Description Adds a new toast to the viewport. Accepts options for title, description, action, priority, dismissibility, and close handling. ### Method `add(options)` ### Parameters - **title** (string) - Required - The toast's title. - **description** (string) - Optional - The toast's description. - **actionProps** (object) - Optional - Props for an action button, including `children` and `onClick`. - **priority** (string) - Optional - `"high"` or `"low"` (default). High priority interrupts screen readers. - **dismissible** (boolean) - Optional - If `true`, renders a close button and allows manual dismissal. - **closeProps** (object) - Optional - Props for the close button, including `className` and `aria-label`. - **onClose** (function) - Optional - Callback fired once per close, regardless of method. Implicitly enables the close button. - **timeout** (number) - Optional - Duration in ms before auto-dismiss. `0` disables auto-dismiss. ### Returns - **id** (string) - The unique identifier of the added toast. ### Example ```tsx const { add } = Toast.useToast() add({ title: "Message deleted", description: "The message has been removed from your inbox.", actionProps: { children: "Undo", onClick: () => restoreMessage(), }, }) ``` ``` -------------------------------- ### Drawer.Description Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/drawer.mdx Supporting description text. ```APIDOC ## Drawer.Description ### Description Supporting description text. ``` -------------------------------- ### localStorage persistence with sanitizeLayout Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/resizable.mdx For client-only apps (e.g., Vite). Reads and writes the layout via localStorage, always wrapping in try/catch and running values through sanitizeLayout. Version the KEY when a panel changes between px and %. ```tsx import { type ResizablePanelConfig, type ResizableLayout, Resizable, sanitizeLayout } from "chunks-ui"; import { useState } from "react"; const PANELS = [ { id: "list", defaultSize: "30%", minSize: "15%" }, { id: "detail", defaultSize: "70%" }, ] satisfies ResizablePanelConfig[]; // Version the key when a panel changes between px and % const KEY = "panels-v1"; function readLayout(): ResizableLayout { try { return sanitizeLayout(JSON.parse(localStorage.getItem(KEY) ?? "null"), PANELS); } catch { return sanitizeLayout(null, PANELS); } } function writeLayout(layout: ResizableLayout) { try { localStorage.setItem(KEY, JSON.stringify(layout)); } catch { // Storage is blocked or full: the layout is simply not remembered } } function MasterDetail() { const [initial] = useState(readLayout); return ( List Detail ); } ``` -------------------------------- ### Basic determinate progress bar Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/progress.mdx Pass value and max to show a determinate progress bar. The example uses value={65} and max={100}. ```tsx ``` -------------------------------- ### Basic Resizable.Group layout Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/resizable.mdx Create a split-pane layout with Resizable.Group, Resizable.Panel, and Resizable.Handle. Each panel needs a stable id; the group must have a size. Handles resize adjacent panels. ```tsx Sidebar Content ``` -------------------------------- ### Basic Empty state with icon, title, description, and action Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/empty.mdx Shows a structured empty state with an icon, title, description, and an action button. The Empty.Media auto-sizes SVGs to 48px. ```tsx No paints found Try adjusting your search or filter criteria. ``` -------------------------------- ### IconButton accessibility example Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/icon-button.mdx Because the button has no visible text, you must provide an aria-label describing the action. Screen readers will announce this label; without it the button is anonymous. ```tsx ``` -------------------------------- ### Compound parts Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toast.mdx Thin style wrappers for Toast.Provider, Toast.Root, Toast.Title, Toast.Description, Toast.Close, and Toast.Action that forward props to Base UI primitives, with special tabIndex handling. ```APIDOC ## Compound parts ### Description All other compound parts (`Toast.Provider`, `Toast.Root`, `Toast.Title`, `Toast.Description`, `Toast.Close`, `Toast.Action`) are thin style wrappers and forward their props to the corresponding Base UI primitive, except that `Toast.Root`, `Toast.Close` and `Toast.Action` set `tabIndex` to `-1` while Base UI hides them from screen readers, replacing a `tabIndex` you pass. A `tabIndex` on the element you pass to `render` still wins. On a `Toast.Action` with a `render`, so does a `tabIndex` in `actionProps`. ### Props - **tabIndex** (number) - Optional - Set to `-1` by default on `Toast.Root`, `Toast.Close`, and `Toast.Action` while hidden from screen readers; your own `tabIndex` overrides it. - **render** (function) - Optional - Custom render prop for `Toast.Action`; a `tabIndex` on the element passed to `render` wins. - **actionProps** (object) - Optional - Props for `Toast.Action`; a `tabIndex` in `actionProps` wins on a `Toast.Action` with a `render`. ### Notes - Base UI gives the action `role="button"`. A `role` on the link wins over it. Without `role={undefined}`, screen readers announce the link as a button. - In a `render` function, put `role={undefined}` after `{...props}`: `props` already holds `role: "button"`, and nothing merges after your element. - Biome's `useValidAriaRole` flags `role={undefined}`. Suppress it there: its fix removes the attribute, and the link is a button again. ### See Also - [Base UI Toast reference](https://base-ui.com/react/components/toast#api-reference) for the full prop surface. ``` -------------------------------- ### Menu.RadioGroup with RadioItem children Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/menu.mdx Enforces single selection among Menu.RadioItem children. The example shows a controlled RadioGroup with value and onValueChange props, and each RadioItem includes a RadioItemIndicator. ```tsx • Light • Dark ``` -------------------------------- ### Multiple selection with ToggleGroup.Root Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/toggle-group.mdx Set `multiple` to allow pressing more than one item at a time. Each pressed item gets its own background highlight instead of a shared sliding indicator. ```tsx import { BoldIcon, ItalicIcon, UnderlineIcon } from 'lucide-react' ``` -------------------------------- ### Basic Textarea Usage Source: https://github.com/pawelkrystkiewicz/chunks-ui/blob/master/apps/docs/content/components/textarea.mdx Renders a multi-line text input with a placeholder. ```tsx