# Accordion (/docs/components/accordion)
## Usage [#usage]
Click any question to reveal its answer. Use `defaultValue` to specify items expanded by default; each `AccordionItem` has its own `value`.
```tsx
"use client";
import {
Accordion,
AccordionHeader,
AccordionItem,
AccordionPanel,
AccordionTrigger,
} from "@/components/ui/hacline/components/accordion";
export const Example = () => (
How do I invite collaborators?
Send invites from the Members page in project settings.
Where are archived projects?
Switch to "Archived" in the project list to view them.
);
```
### Expanding Multiple Items [#expanding-multiple-items]
Enable `multiple` to keep several panels open at once, using a controlled array to expand and collapse all items together.
```tsx
"use client";
import { useState } from "react";
import {
Accordion,
AccordionHeader,
AccordionItem,
AccordionPanel,
AccordionTrigger,
} from "@/components/ui/hacline/components/accordion";
import { Button } from "@/components/ui/hacline/components/button";
const sections = [
{
content: "Three review rounds completed.",
id: "review",
label: "Review progress",
},
{
content: "Artifacts will be packaged on Friday.",
id: "delivery",
label: "Delivery schedule",
},
];
export const Example = () => {
const [open, setOpen] = useState(["review"]);
return (
);
};
```
## Parts [#parts]
## Props [#props]
### AccordionOptions
The options `accordion` takes. A component takes them as props on its root.
| Prop | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value?` | `T[] \| undefined` | The open items' values. Pass it to control the accordion. |
| `defaultValue?` | `T[] \| undefined` | The items open at first, when uncontrolled. Default: `[]` |
| `onValueChange?` | `((value: T[], details: ChangeDetails) => void) \| undefined` | Runs when items want to open or close. `details.reason` says why, and `details.cancel()` stops it. |
| `multiple?` | `boolean \| undefined` | Whether several items can be open at once. Otherwise opening one closes the others. Default: `false` |
| `collapsible?` | `boolean \| undefined` | Whether the open item can close when only one may be open. With `false`, one item always stays open and its trigger reports it can't be pressed. Default: `true` |
| `disabled?` | `boolean \| undefined` | Stops every item from opening or closing. Triggers stay focusable. Default: `false` |
| `keepMounted?` | `boolean \| undefined` | Whether closed panels stay in the page, hidden. Default: `false` |
| `hiddenUntilFound?` | `boolean \| undefined` | Keeps closed panels in the page as `hidden="until-found"`, so the browser's find in page can match their text and open them. Default: `false` |
| `controller?` | `{ getValue: () => T[]; setValue: (value: T[], options?: AccordionChangeOptions) => boolean; isOpen: (value: T) => boolean; open: (value: T, options?: AccordionChangeOptions) => boolean; close: (value: T, options?: AccordionChangeOptions) => boolean; toggle: (value: T, options?: AccordionChangeOptions) => boolean; openAll: (options?: AccordionChangeOptions) => boolean; closeAll: (options?: AccordionChangeOptions) => boolean; focus: (value?: T \| undefined) => void; } \| undefined` | Opens and closes items from anywhere. Create one with `createAccordionController()`. |
| `debug?` | `boolean \| undefined` | Logs every state change with its reason to the console, in development builds. |
[View UI SDK parts and state attributes](https://ui-sdk.dev/docs/react/components/accordion).
# AlertDialog (/docs/components/alert-dialog)
## Usage [#usage]
"Keep draft" and "Confirm clear" each update the demo state. A close button's `value` is passed as `returnValue` to the open state callback.
```tsx
"use client";
import { useState } from "react";
import {
AlertDialog,
AlertDialogBackdrop,
AlertDialogClose,
AlertDialogContent,
AlertDialogDescription,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/hacline/components/alert-dialog";
export const Example = () => {
const [status, setStatus] = useState("Draft saved");
return (
Discard draftClear current draft?
The draft in this example will be cleared.
);
};
```
### Async Confirmation [#async-confirmation]
Return a Promise from the confirm button's `action`. The button displays a pending state while archiving, and the dialog closes once the operation completes.
```tsx
"use client";
import { useState } from "react";
import {
AlertDialog,
AlertDialogBackdrop,
AlertDialogClose,
AlertDialogContent,
AlertDialogDescription,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/hacline/components/alert-dialog";
const ARCHIVE_DELAY = 700;
export const Example = () => {
const [archived, setArchived] = useState(false);
return (
{archived ? "Archived" : "Archive sample record"}
Archive this record?
You can still find it in history after archiving.
Not now {
// oxlint-disable-next-line promise/avoid-new -- Browser timers use a callback.
await new Promise((resolve) => {
setTimeout(resolve, ARCHIVE_DELAY);
});
setArchived(true);
}}
value="confirm"
>
{({ pending }) => (pending ? "Archiving…" : "Confirm archive")}
);
};
```
## Parts [#parts]
## Props [#props]
### AlertDialogOptions
The options `alertDialog` takes. A component takes them as props on its
root.
| Prop | Type | Description |
| ----------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `container?` | `DocumentFragment \| Element \| null \| undefined` | Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent. |
| `open?` | `boolean \| undefined` | Whether the dialog is open. Pass it to control the dialog. |
| `defaultOpen?` | `boolean \| undefined` | Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page. Default: `false` |
| `onOpenChangeComplete?` | `((open: boolean) => void) \| undefined` | Runs once the dialog has finished opening or closing, after any animation. |
| `dismissible?` | `boolean \| undefined` | Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass `false` while a form has unsaved changes, and ask in `onDismissAttempt`. Default: `true` |
| `onDismissAttempt?` | `((details: DialogDismissAttemptDetails) => void) \| undefined` | Runs when a dismissal was refused, because `dismissible` is false, an outside press doesn't close it, or a Close part's action is running. Ask "Discard changes?" here. |
| `persistentElements?` | `(string \| Element)[] \| (() => Element[]) \| undefined` | Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it. |
| `pendingAnnouncement?` | `string \| undefined` | What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing. Default: `"Loading"` |
| `debug?` | `boolean \| undefined` | Logs every state change with its reason to the console, in development builds. |
| `onOpenChange?` | `((open: boolean, details: DialogOpenChangeDetails) => void) \| undefined` | Runs when the alert dialog wants to open or close. `details.reason` says why, `details.cancel()` stops it, and `details.returnValue` is the `value` of the Close part that closed it. |
| `onPayloadChange?` | `((payload: unknown, details: ChangeDetails) => void) \| undefined` | Runs when a trigger or a controller with another payload opens the alert dialog, before `onOpenChange`, or a controller's `open({ payload })` gives the open one another payload. `details.cancel()` keeps the previous payload. |
| `controller?` | `PopupController \| undefined` | Opens, closes and inspects the alert dialog from anywhere. Create one with `createAlertDialogController()` or `createConfirm()`. |
[View UI SDK parts and state attributes](https://ui-sdk.dev/docs/react/components/alert-dialog).
# Autocomplete (/docs/components/autocomplete)
## Usage [#usage]
Typing "Design" shows matching tags, while new terms can be kept directly as entered. When `items` is provided, an empty `AutocompleteList` renders the current suggestions.
```tsx
"use client";
import {
Autocomplete,
AutocompleteContent,
AutocompleteEmpty,
AutocompleteInput,
AutocompleteLabel,
AutocompleteList,
} from "@/components/ui/hacline/components/autocomplete";
const tags = [
"Design review",
"Design system",
"Project plan",
"Release notes",
];
export const Example = () => (
Document tagUse your typed tag directly
);
```
### Controlled Input and Clearing [#controlled-input-and-clearing]
Synchronize application state with `value` and clear the input with `AutocompleteClear`. This example matches only cities starting with the entered text.
```tsx
"use client";
import { useState } from "react";
import {
Autocomplete,
AutocompleteClear,
AutocompleteContent,
AutocompleteInput,
AutocompleteLabel,
AutocompleteList,
} from "@/components/ui/hacline/components/autocomplete";
export const Example = () => {
const [value, setValue] = useState("Seattle");
return (
Shipping city
);
};
```
## Parts [#parts]
## Props [#props]
### AutocompleteOptions
The options `autocomplete` takes. A component takes them as props on its
root.
| Prop | Type | Description |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `container?` | `DocumentFragment \| Element \| null \| undefined` | Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent. |
| `value?` | `string \| undefined` | The text. Pass it to control it. |
| `defaultValue?` | `string \| undefined` | The text at first, when uncontrolled. A form reset returns to it. |
| `onValueChange?` | `((value: string, details: AutocompleteValueChangeDetails) => void) \| undefined` | Runs when the text wants to change: typing, choosing a suggestion, a Clear part, a form reset or a controller. `details.cancel()` keeps it as it was. |
| `open?` | `boolean \| undefined` | Whether the suggestions are open. Pass it to control them. |
| `defaultOpen?` | `boolean \| undefined` | Whether the suggestions start open, when uncontrolled. Default: `false` |
| `onOpenChange?` | `((open: boolean, details: ChangeDetails) => void) \| undefined` | Runs when the suggestions want to open or close. `details.reason` says why, and `details.cancel()` stops it. |
| `onOpenChangeComplete?` | `((open: boolean) => void) \| undefined` | Runs once the suggestions have finished opening or closing, after any animation. |
| `onSubmit?` | `((value: string, details: AutocompleteSubmitDetails) => void) \| undefined` | Runs with the text when Enter is pressed with no suggestion highlighted, or after choosing one with `submitOnSelect`. The surrounding form submits next, unless the event's `preventDefault()` is called. |
| `items?` | `ListData \| undefined` | The suggestions as data. Renders them for you, and filters them without rendering every one. |
| `emptyItems?` | `ListData \| undefined` | Suggestions shown instead of `items` while the field is empty, like recent searches, with `openOnFocus`. Groups work, like `{ type: "group", label: "Recent", items }`. Needs `items`. |
| `filter?` | `SearchFilter \| undefined` | How typing narrows the suggestions: `"contains"`, `"startsWith"`, `"fuzzy"`, a function of the item and the text, or `false` to keep every one, for results a server already filtered. Default: `"contains"` |
| `inlineComplete?` | `boolean \| undefined` | Whether typing completes the text with the first suggestion that starts with it, with the rest selected after the caret: ArrowRight or End accepts it, Backspace and Escape take it back out, and arrow keys fill in the suggestion they highlight. Default: `false` |
| `autoHighlight?` | `boolean \| undefined` | Whether the first suggestion is highlighted while typing, so Enter chooses it. Default: `false` |
| `openOnFocus?` | `boolean \| undefined` | Whether the suggestions open when the field gets focus, like recent searches, even before anything is typed. Default: `false` |
| `submitOnSelect?` | `boolean \| undefined` | Whether choosing a suggestion submits, like a search box: `onSubmit` runs, then the form submits. Default: `false` |
| `status?` | `AsyncOptionsStatus \| undefined` | Whether results are loading or failed, for the empty and status parts. Sets `aria-busy` on the list while loading. Default: `"idle"` |
| `onHighlight?` | `((value: string \| null, details: ListHighlightDetails) => void) \| undefined` | Runs when the highlight moves, with the suggestion's index among the visible ones, so a virtualized list can scroll to it. |
| `onLoadMore?` | `(() => void) \| undefined` | Runs when the highlight or scrolling reaches the last suggestion, so the next page can load, like `createAsyncOptions`'s `loadMore`. Not again for the same suggestions, unless the last load failed. |
| `announcement?` | `((change: ListAnnouncement) => string \| null \| undefined) \| undefined` | What screen readers hear after typing pauses, when no `AutocompleteStatus` is rendered. Return null for nothing. Default: `"3 results", "No results" or "Loading"` |
| `loop?` | `boolean \| undefined` | Whether arrow keys wrap from the last suggestion to the first. Default: `true` |
| `modal?` | `"pointer" \| boolean \| undefined` | `false`: the page stays usable while the suggestions are open. `"pointer"`: an outside press only closes them. `true`: also locks scroll and makes the rest of the page inert. Default: `false, or true while it presents as a sheet` |
| `presentation?` | `PresentationSetting<"popover"> \| undefined` | How the suggestions present. `"sheet"` slides them up from the bottom of the screen with the field in its header, where they can be swiped away, and `"auto"` does that on small touch screens. A tap that opens a sheet leaves the keyboard closed until the field in the header is tapped. Decided each time they open; the server renders `"popover"` for `"auto"`. Default: `"popover"` |
| `disabled?` | `boolean \| undefined` | Disables the field like a native input: it can't be focused or changed, and its text isn't submitted. |
| `readOnly?` | `boolean \| undefined` | Keeps the field focusable and its text submitted, but stops changes. |
| `required?` | `boolean \| undefined` | Blocks form submission while the field is empty, with the browser's own message. |
| `name?` | `string \| undefined` | The name the text submits under. |
| `form?` | `string \| undefined` | The id of a form to belong to, when the field isn't inside that form. |
| `controller?` | `{ isOpen: () => boolean; setOpen: (open: boolean, options?: AutocompleteChangeOptions) => boolean; open: (options?: AutocompleteChangeOptions & { signal?: AbortSignal; }) => Promise>; close: (options?: AutocompleteChangeOptions) => boolean; toggle: (options?: AutocompleteChangeOptions) => boolean; getValue: () => string; setValue: (value: string, options?: AutocompleteChangeOptions) => boolean; clear: (options?: AutocompleteChangeOptions) => boolean; getHighlighted: () => string \| null; highlight: (value: string \| null) => boolean; focus: () => void; } \| undefined` | Opens, closes, reads and sets the autocomplete from anywhere. Create one with `createAutocompleteController()`. |
| `dismissible?` | `boolean \| undefined` | Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass `false` while it holds unsaved work, and ask in `onDismissAttempt`. Default: `true` |
| `onDismissAttempt?` | `((details: { reason: "back"; event?: Event \| undefined; } \| { reason: "escape-key"; event?: KeyboardEvent \| undefined; } \| { reason: "outside-press"; event?: MouseEvent \| undefined; } \| { reason: "swipe"; event?: PointerEvent \| TouchEvent \| undefined; }) => void) \| undefined` | Runs when `dismissible` refused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here. |
| `debug?` | `boolean \| undefined` | Logs every state change with its reason to the console, in development builds. |
[View UI SDK parts and state attributes](https://ui-sdk.dev/docs/react/components/autocomplete).
# Avatar (/docs/components/avatar)
## Usage [#usage]
Provide each avatar with an accessible name. `AvatarImage` is shown once the image loads, and `AvatarFallback` appears when no image is available. This example uses a local docs asset that you can replace with your own.
```tsx
"use client";
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/hacline/components/avatar";
/* oxlint-disable jsx-a11y/prefer-tag-over-role -- The wrapper names both the photo and its text fallback. */
export const Example = () => (
LKMT
);
```
### Stacked Collaborator Avatars [#stacked-collaborator-avatars]
Place each avatar inside a member list. Even when displaying only initials, accessible names distinguish every collaborator.
```tsx
"use client";
import {
Avatar,
AvatarFallback,
} from "@/components/ui/hacline/components/avatar";
const team = [
{ initials: "AL", name: "Alice Lin" },
{ initials: "NZ", name: "Noah Zhou" },
{ initials: "MC", name: "Maya Chen" },
];
/* oxlint-disable jsx-a11y/prefer-tag-over-role -- The initials are a text alternative to a photo. */
export const Example = () => (
{team.map(({ initials, name }) => (
{initials}
))}
);
```
## Parts [#parts]
## Props [#props]
### AvatarOptions
The options `avatar` takes. A component takes them as props on its root.
| Prop | Type | Description |
| ------------------------ | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onLoadingStatusChange?` | `((status: AvatarLoadingStatus, details: ChangeDetails) => void) \| undefined` | Runs when the image's loading status changes: `"loading"` when it gets a source, `"loaded"`, `"error"`, and `"idle"` when it leaves the page. `details.reason` says why, and `details.event` is the image's `load` or `error` event, or undefined when the status was known at once, like for a cached image. |
| `debug?` | `boolean \| undefined` | Logs every state change with its reason to the console, in development builds. |
[View UI SDK parts and state attributes](https://ui-sdk.dev/docs/react/components/avatar).
# Button (/docs/components/button)
## Import [#import]
```tsx
import { Button } from "@/components/ui/hacline/components/button";
```
## Variants [#variants]
Switch the visual hierarchy of the button with `variant`. Defaults to `primary`.
```tsx
import { Button } from "@/components/ui/hacline/components/button";
export function ButtonVariants() {
return (
);
}
```
## Sizes [#sizes]
Adjust the button size using `size`, supporting `sm`, `md`, `lg`, and icon sizes `icon-sm`, `icon`, and `icon-lg`. Always provide an `aria-label` when rendering an icon-only button.
```tsx
import { Button } from "@/components/ui/hacline/components/button";
import { PlusIcon } from "lucide-react";
export function ButtonSizes() {
return (
);
}
```
## Async Loading State [#async-loading-state]
When `onClick` returns a `Promise`, the button automatically enters the `data-pending` state, retains focus, blocks duplicate clicks, and announces `pendingAnnouncement` to screen readers if the operation exceeds 1 second. Use `data-show="idle"` and `data-show="pending"` to swap icons or content automatically.
```tsx
"use client";
import { Button } from "@/components/ui/hacline/components/button";
import { ArrowDownToLineIcon, LoaderCircleIcon } from "lucide-react";
export function ButtonPending() {
return (
);
}
```
## Disabled and Focusable State [#disabled-and-focusable-state]
Setting `disabled` blocks activation and removes the button from the Tab order. Combine with `focusableWhenDisabled` to use `aria-disabled` and keep keyboard focusability, making it easy to pair with helper text or a Tooltip explaining why the action is unavailable.
```tsx
import { Button } from "@/components/ui/hacline/components/button";
export function ButtonDisabled() {
return (