mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-11 09:51:40 +00:00
docs: add composition section
This commit is contained in:
@@ -337,6 +337,33 @@
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/*
|
||||
* ```text composition trees use box-drawing characters; per-line padding makes
|
||||
* vertical connectors look broken. rehype-pretty-code sets `data-language` on
|
||||
* `pre`/`code` (not `language-*` classes). It also sets `code { display: grid }`,
|
||||
* which can add visible row separation — reset to a normal pre stack for text.
|
||||
*/
|
||||
[data-rehype-pretty-code-figure] pre[data-language="text"] code,
|
||||
[data-rehype-pretty-code-figure] pre[data-language="plaintext"] code,
|
||||
[data-slot="docs"] pre[data-language="text"] code,
|
||||
[data-slot="docs"] pre[data-language="plaintext"] code {
|
||||
display: block !important;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
[data-rehype-pretty-code-figure] pre[data-language="text"] [data-line],
|
||||
[data-rehype-pretty-code-figure] pre[data-language="plaintext"] [data-line],
|
||||
[data-rehype-pretty-code-figure] code[data-language="text"] [data-line],
|
||||
[data-rehype-pretty-code-figure] code[data-language="plaintext"] [data-line],
|
||||
[data-slot="docs"] pre[data-language="text"] [data-line],
|
||||
[data-slot="docs"] pre[data-language="plaintext"] [data-line] {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
min-height: unset;
|
||||
line-height: 1;
|
||||
display: block;
|
||||
}
|
||||
|
||||
[data-line] span {
|
||||
color: var(--shiki-light);
|
||||
|
||||
|
||||
@@ -80,6 +80,20 @@ import {
|
||||
</Accordion>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Accordion`:
|
||||
|
||||
```text
|
||||
Accordion
|
||||
├── AccordionItem
|
||||
│ ├── AccordionTrigger
|
||||
│ └── AccordionContent
|
||||
└── AccordionItem
|
||||
├── AccordionTrigger
|
||||
└── AccordionContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -94,6 +94,23 @@ import {
|
||||
</AlertDialog>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `AlertDialog`:
|
||||
|
||||
```text
|
||||
AlertDialog
|
||||
├── AlertDialogTrigger
|
||||
└── AlertDialogContent
|
||||
├── AlertDialogHeader
|
||||
│ ├── AlertDialogMedia
|
||||
│ ├── AlertDialogTitle
|
||||
│ └── AlertDialogDescription
|
||||
└── AlertDialogFooter
|
||||
├── AlertDialogCancel
|
||||
└── AlertDialogAction
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -67,6 +67,18 @@ import {
|
||||
</Alert>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Alert`:
|
||||
|
||||
```text
|
||||
Alert
|
||||
├── Icon
|
||||
├── AlertTitle
|
||||
├── AlertDescription
|
||||
└── AlertAction
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -69,6 +69,32 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
</Avatar>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Avatar`:
|
||||
|
||||
```text
|
||||
Avatar
|
||||
├── AvatarImage
|
||||
├── AvatarFallback
|
||||
└── AvatarBadge
|
||||
```
|
||||
|
||||
Use the following composition to build an `AvatarGroup`:
|
||||
|
||||
```text
|
||||
AvatarGroup
|
||||
├── Avatar
|
||||
│ ├── AvatarImage
|
||||
│ ├── AvatarFallback
|
||||
│ └── AvatarBadge
|
||||
├── Avatar
|
||||
│ ├── AvatarImage
|
||||
│ ├── AvatarFallback
|
||||
│ └── AvatarBadge
|
||||
└── AvatarGroupCount
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -80,6 +80,23 @@ import {
|
||||
</Breadcrumb>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Breadcrumb`:
|
||||
|
||||
```text
|
||||
Breadcrumb
|
||||
└── BreadcrumbList
|
||||
├── BreadcrumbItem
|
||||
│ └── BreadcrumbLink
|
||||
├── BreadcrumbSeparator
|
||||
├── BreadcrumbItem
|
||||
│ └── BreadcrumbLink
|
||||
├── BreadcrumbSeparator
|
||||
└── BreadcrumbItem
|
||||
└── BreadcrumbPage
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -66,6 +66,17 @@ import {
|
||||
</ButtonGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ButtonGroup`:
|
||||
|
||||
```text
|
||||
ButtonGroup
|
||||
├── Button or Input
|
||||
├── ButtonGroupSeparator
|
||||
└── ButtonGroupText
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
- The `ButtonGroup` component has the `role` attribute set to `group`.
|
||||
|
||||
@@ -77,6 +77,20 @@ import {
|
||||
</Card>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Card`:
|
||||
|
||||
```text
|
||||
Card
|
||||
├── CardHeader
|
||||
│ ├── CardTitle
|
||||
│ ├── CardDescription
|
||||
│ └── CardAction
|
||||
├── CardContent
|
||||
└── CardFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Size
|
||||
|
||||
@@ -85,6 +85,19 @@ import {
|
||||
</Carousel>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Carousel`:
|
||||
|
||||
```text
|
||||
Carousel
|
||||
├── CarouselContent
|
||||
│ ├── CarouselItem
|
||||
│ └── CarouselItem
|
||||
├── CarouselPrevious
|
||||
└── CarouselNext
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Sizes
|
||||
|
||||
@@ -73,6 +73,16 @@ import {
|
||||
</Collapsible>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Collapsible`:
|
||||
|
||||
```text
|
||||
Collapsible
|
||||
├── CollapsibleTrigger
|
||||
└── CollapsibleContent
|
||||
```
|
||||
|
||||
## Controlled State
|
||||
|
||||
Use the `open` and `onOpenChange` props to control the state.
|
||||
|
||||
@@ -90,6 +90,62 @@ export function ExampleCombobox() {
|
||||
}
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Simple
|
||||
|
||||
A single-line input and a flat list (see [Basic](#basic)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
### With chips
|
||||
|
||||
Multi-select with `multiple`, chips, and a chips input (see [Multiple](#multiple)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxChips
|
||||
│ ├── ComboboxValue
|
||||
│ │ └── ComboboxChip
|
||||
│ └── ComboboxChipsInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
### With groups and collection
|
||||
|
||||
Nested items per group using `ComboboxCollection` inside each `ComboboxGroup`, with a separator between groups (see [Groups](#groups)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxGroup
|
||||
│ ├── ComboboxLabel
|
||||
│ └── ComboboxCollection
|
||||
│ ├── ComboboxItem
|
||||
│ └── ComboboxItem
|
||||
├── ComboboxSeparator
|
||||
└── ComboboxGroup
|
||||
├── ComboboxLabel
|
||||
└── ComboboxCollection
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
## Custom Items
|
||||
|
||||
Use `itemToStringValue` when your items are objects.
|
||||
|
||||
@@ -96,6 +96,24 @@ import {
|
||||
</Command>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Command`:
|
||||
|
||||
```text
|
||||
Command
|
||||
├── CommandInput
|
||||
└── CommandList
|
||||
├── CommandEmpty
|
||||
├── CommandGroup
|
||||
│ ├── CommandItem
|
||||
│ └── CommandItem
|
||||
├── CommandSeparator
|
||||
└── CommandGroup
|
||||
├── CommandItem
|
||||
└── CommandItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -79,6 +79,37 @@ import {
|
||||
</ContextMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ContextMenu`:
|
||||
|
||||
```text
|
||||
ContextMenu
|
||||
├── ContextMenuTrigger
|
||||
└── ContextMenuContent
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ ├── ContextMenuItem
|
||||
│ └── ContextMenuItem
|
||||
├── ContextMenuSeparator
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ ├── ContextMenuCheckboxItem
|
||||
│ └── ContextMenuCheckboxItem
|
||||
├── ContextMenuSeparator
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ └── ContextMenuRadioGroup
|
||||
│ ├── ContextMenuRadioItem
|
||||
│ └── ContextMenuRadioItem
|
||||
└── ContextMenuSub
|
||||
├── ContextMenuSubTrigger
|
||||
└── ContextMenuSubContent
|
||||
└── ContextMenuGroup
|
||||
├── ContextMenuItem
|
||||
└── ContextMenuItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -58,6 +58,17 @@ export function DatePickerDemo() {
|
||||
|
||||
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
|
||||
|
||||
## Composition
|
||||
|
||||
A date picker is built from `Popover` and `Calendar` (there is no `DatePicker` root component):
|
||||
|
||||
```text
|
||||
Popover
|
||||
├── PopoverTrigger
|
||||
└── PopoverContent
|
||||
└── Calendar
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -85,6 +85,20 @@ import {
|
||||
</Dialog>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Dialog`:
|
||||
|
||||
```text
|
||||
Dialog
|
||||
├── DialogTrigger
|
||||
└── DialogContent
|
||||
├── DialogHeader
|
||||
│ ├── DialogTitle
|
||||
│ └── DialogDescription
|
||||
└── DialogFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Close Button
|
||||
|
||||
@@ -88,6 +88,20 @@ import {
|
||||
</Drawer>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Drawer`:
|
||||
|
||||
```text
|
||||
Drawer
|
||||
├── DrawerTrigger
|
||||
└── DrawerContent
|
||||
├── DrawerHeader
|
||||
│ ├── DrawerTitle
|
||||
│ └── DrawerDescription
|
||||
└── DrawerFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Scrollable Content
|
||||
|
||||
@@ -92,6 +92,38 @@ import {
|
||||
</DropdownMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `DropdownMenu`:
|
||||
|
||||
```text
|
||||
DropdownMenu
|
||||
├── DropdownMenuTrigger
|
||||
└── DropdownMenuContent
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ ├── DropdownMenuItem
|
||||
│ └── DropdownMenuItem
|
||||
├── DropdownMenuSeparator
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ ├── DropdownMenuCheckboxItem
|
||||
│ └── DropdownMenuCheckboxItem
|
||||
├── DropdownMenuSeparator
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ └── DropdownMenuRadioGroup
|
||||
│ ├── DropdownMenuRadioItem
|
||||
│ └── DropdownMenuRadioItem
|
||||
└── DropdownMenuSub
|
||||
├── DropdownMenuSubTrigger
|
||||
└── DropdownMenuSubContent
|
||||
└── DropdownMenuGroup
|
||||
├── DropdownMenuLabel
|
||||
├── DropdownMenuItem
|
||||
└── DropdownMenuItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -75,6 +75,19 @@ import {
|
||||
</Empty>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Empty` state:
|
||||
|
||||
```text
|
||||
Empty
|
||||
├── EmptyHeader
|
||||
│ ├── EmptyMedia
|
||||
│ ├── EmptyTitle
|
||||
│ └── EmptyDescription
|
||||
└── EmptyContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Outline
|
||||
|
||||
@@ -87,6 +87,56 @@ import {
|
||||
</FieldSet>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Field
|
||||
|
||||
A single control with label, helper text, and validation.
|
||||
|
||||
```text
|
||||
Field
|
||||
├── FieldLabel
|
||||
├── Input / Textarea / Switch / Select
|
||||
├── FieldDescription
|
||||
└── FieldError
|
||||
```
|
||||
|
||||
### FieldGroup
|
||||
|
||||
Related fields in one group. Use `FieldSeparator` between sections when needed.
|
||||
|
||||
```text
|
||||
FieldGroup
|
||||
├── Field
|
||||
│ ├── FieldLabel
|
||||
│ ├── Input / Textarea / Switch / Select
|
||||
│ ├── FieldDescription
|
||||
│ └── FieldError
|
||||
├── FieldSeparator
|
||||
└── Field
|
||||
├── FieldLabel
|
||||
└── Input / Textarea / Switch / Select
|
||||
```
|
||||
|
||||
### FieldSet
|
||||
|
||||
Semantic grouping with a legend and description, usually containing a `FieldGroup`.
|
||||
|
||||
```text
|
||||
FieldSet
|
||||
├── FieldLegend
|
||||
├── FieldDescription
|
||||
└── FieldGroup
|
||||
├── Field
|
||||
│ ├── FieldLabel
|
||||
│ ├── Input / Textarea / Switch / Select
|
||||
│ ├── FieldDescription
|
||||
│ └── FieldError
|
||||
└── Field
|
||||
├── FieldLabel
|
||||
└── Input / Textarea / Switch / Select
|
||||
```
|
||||
|
||||
## Anatomy
|
||||
|
||||
The `Field` family is designed for composing accessible forms. A typical field is structured as follows:
|
||||
|
||||
@@ -75,6 +75,16 @@ import {
|
||||
</HoverCard>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `HoverCard`:
|
||||
|
||||
```text
|
||||
HoverCard
|
||||
├── HoverCardTrigger
|
||||
└── HoverCardContent
|
||||
```
|
||||
|
||||
## Trigger Delays
|
||||
|
||||
Use `delay` and `closeDelay` on the trigger to control when the card opens and
|
||||
|
||||
@@ -71,6 +71,18 @@ import {
|
||||
</InputGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `InputGroup`:
|
||||
|
||||
```text
|
||||
InputGroup
|
||||
├── InputGroupInput or InputGroupTextarea
|
||||
├── InputGroupAddon
|
||||
├── InputGroupButton
|
||||
└── InputGroupText
|
||||
```
|
||||
|
||||
## Align
|
||||
|
||||
Use the `align` prop on `InputGroupAddon` to position the addon relative to the input.
|
||||
|
||||
@@ -82,6 +82,27 @@ import {
|
||||
</InputOTP>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `InputOTP`:
|
||||
|
||||
```text
|
||||
InputOTP
|
||||
├── InputOTPGroup
|
||||
│ ├── InputOTPSlot
|
||||
│ ├── InputOTPSlot
|
||||
│ └── InputOTPSlot
|
||||
├── InputOTPSeparator
|
||||
├── InputOTPGroup
|
||||
│ ├── InputOTPSlot
|
||||
│ ├── InputOTPSlot
|
||||
│ └── InputOTPSlot
|
||||
├── InputOTPSeparator
|
||||
└── InputOTPGroup
|
||||
├── InputOTPSlot
|
||||
└── InputOTPSlot
|
||||
```
|
||||
|
||||
## Pattern
|
||||
|
||||
Use the `pattern` prop to define a custom pattern for the OTP input.
|
||||
|
||||
@@ -73,6 +73,22 @@ import {
|
||||
</Item>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Item`:
|
||||
|
||||
```text
|
||||
ItemGroup
|
||||
└── Item
|
||||
├── ItemHeader
|
||||
├── ItemMedia
|
||||
├── ItemContent
|
||||
│ ├── ItemTitle
|
||||
│ └── ItemDescription
|
||||
├── ItemActions
|
||||
└── ItemFooter
|
||||
```
|
||||
|
||||
## Item vs Field
|
||||
|
||||
Use `Field` if you need to display a form input such as a checkbox, input, radio, or select.
|
||||
|
||||
@@ -53,6 +53,17 @@ import { Kbd } from "@/components/ui/kbd"
|
||||
<Kbd>Ctrl</Kbd>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build `Kbd` and `KbdGroup`:
|
||||
|
||||
```text
|
||||
Kbd
|
||||
KbdGroup
|
||||
├── Kbd
|
||||
└── Kbd
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Group
|
||||
|
||||
@@ -88,6 +88,46 @@ import {
|
||||
</Menubar>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Menubar`:
|
||||
|
||||
```text
|
||||
Menubar
|
||||
├── MenubarMenu
|
||||
│ ├── MenubarTrigger
|
||||
│ └── MenubarContent
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ ├── MenubarItem
|
||||
│ │ └── MenubarItem
|
||||
│ ├── MenubarSeparator
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ ├── MenubarCheckboxItem
|
||||
│ │ └── MenubarCheckboxItem
|
||||
│ ├── MenubarSeparator
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ └── MenubarRadioGroup
|
||||
│ │ ├── MenubarRadioItem
|
||||
│ │ └── MenubarRadioItem
|
||||
│ └── MenubarSub
|
||||
│ ├── MenubarSubTrigger
|
||||
│ └── MenubarSubContent
|
||||
│ └── MenubarGroup
|
||||
│ ├── MenubarLabel
|
||||
│ ├── MenubarItem
|
||||
│ └── MenubarItem
|
||||
└── MenubarMenu
|
||||
├── MenubarTrigger
|
||||
└── MenubarContent
|
||||
└── MenubarGroup
|
||||
├── MenubarLabel
|
||||
├── MenubarItem
|
||||
└── MenubarItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Checkbox
|
||||
|
||||
@@ -70,6 +70,34 @@ import {
|
||||
</NativeSelect>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Simple
|
||||
|
||||
Options placed directly under `NativeSelect` (no `NativeSelectOptGroup`).
|
||||
|
||||
```text
|
||||
NativeSelect
|
||||
├── NativeSelectOption
|
||||
├── NativeSelectOption
|
||||
├── NativeSelectOption
|
||||
└── NativeSelectOption
|
||||
```
|
||||
|
||||
### With groups
|
||||
|
||||
Use `NativeSelectOptGroup` to organize options into categories.
|
||||
|
||||
```text
|
||||
NativeSelect
|
||||
├── NativeSelectOptGroup
|
||||
│ ├── NativeSelectOption
|
||||
│ └── NativeSelectOption
|
||||
└── NativeSelectOptGroup
|
||||
├── NativeSelectOption
|
||||
└── NativeSelectOption
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Groups
|
||||
|
||||
@@ -82,6 +82,23 @@ import {
|
||||
</NavigationMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `NavigationMenu`:
|
||||
|
||||
```text
|
||||
NavigationMenu
|
||||
├── NavigationMenuList
|
||||
│ ├── NavigationMenuItem
|
||||
│ │ ├── NavigationMenuTrigger
|
||||
│ │ └── NavigationMenuContent
|
||||
│ │ ├── NavigationMenuLink
|
||||
│ │ └── NavigationMenuLink
|
||||
│ └── NavigationMenuItem
|
||||
│ └── NavigationMenuLink
|
||||
└── NavigationMenuIndicator
|
||||
```
|
||||
|
||||
## Link Component
|
||||
|
||||
Use the `render` prop to compose a custom link component such as Next.js `Link`.
|
||||
|
||||
@@ -84,6 +84,23 @@ import {
|
||||
</Pagination>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Pagination`:
|
||||
|
||||
```text
|
||||
Pagination
|
||||
└── PaginationContent
|
||||
├── PaginationItem
|
||||
│ └── PaginationPrevious
|
||||
├── PaginationItem
|
||||
│ └── PaginationLink
|
||||
├── PaginationItem
|
||||
│ └── PaginationEllipsis
|
||||
└── PaginationItem
|
||||
└── PaginationNext
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Simple
|
||||
|
||||
@@ -79,6 +79,16 @@ import {
|
||||
</Popover>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Popover`:
|
||||
|
||||
```text
|
||||
Popover
|
||||
├── PopoverTrigger
|
||||
└── PopoverContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -62,6 +62,33 @@ import { Progress } from "@/components/ui/progress"
|
||||
<Progress value={33} />
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### With label and value
|
||||
|
||||
Use `ProgressLabel` and `ProgressValue` to add a label and value display.
|
||||
|
||||
```tsx showLineNumbers
|
||||
import {
|
||||
Progress,
|
||||
ProgressLabel,
|
||||
ProgressValue,
|
||||
} from "@/components/ui/progress"
|
||||
|
||||
<Progress value={56} className="w-full max-w-sm">
|
||||
<ProgressLabel>Upload progress</ProgressLabel>
|
||||
<ProgressValue />
|
||||
</Progress>
|
||||
```
|
||||
|
||||
```text
|
||||
Progress
|
||||
├── ProgressLabel
|
||||
├── ProgressValue
|
||||
└── ProgressTrack
|
||||
└── ProgressIndicator
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Label
|
||||
|
||||
@@ -72,6 +72,16 @@ import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
|
||||
</RadioGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `RadioGroup`:
|
||||
|
||||
```text
|
||||
RadioGroup
|
||||
├── RadioGroupItem
|
||||
└── RadioGroupItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Description
|
||||
|
||||
@@ -78,6 +78,17 @@ import {
|
||||
</ResizablePanelGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ResizablePanelGroup`:
|
||||
|
||||
```text
|
||||
ResizablePanelGroup
|
||||
├── ResizablePanel
|
||||
├── ResizableHandle
|
||||
└── ResizablePanel
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Vertical
|
||||
|
||||
@@ -68,6 +68,15 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"
|
||||
</ScrollArea>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ScrollArea`:
|
||||
|
||||
```text
|
||||
ScrollArea
|
||||
└── ScrollBar
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Horizontal
|
||||
|
||||
@@ -89,6 +89,26 @@ const items = [
|
||||
</Select>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Select`:
|
||||
|
||||
```text
|
||||
Select
|
||||
├── SelectTrigger
|
||||
│ └── SelectValue
|
||||
└── SelectContent
|
||||
├── SelectGroup
|
||||
│ ├── SelectLabel
|
||||
│ ├── SelectItem
|
||||
│ └── SelectItem
|
||||
├── SelectSeparator
|
||||
└── SelectGroup
|
||||
├── SelectLabel
|
||||
├── SelectItem
|
||||
└── SelectItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Align Item With Trigger
|
||||
|
||||
@@ -79,6 +79,20 @@ import {
|
||||
</Sheet>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Sheet`:
|
||||
|
||||
```text
|
||||
Sheet
|
||||
├── SheetTrigger
|
||||
└── SheetContent
|
||||
├── SheetHeader
|
||||
│ ├── SheetTitle
|
||||
│ └── SheetDescription
|
||||
└── SheetFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Side
|
||||
|
||||
@@ -55,32 +55,6 @@ npx shadcn@latest add sidebar
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
## Structure
|
||||
|
||||
A `Sidebar` component is composed of the following parts:
|
||||
|
||||
- `SidebarProvider` - Handles collapsible state.
|
||||
- `Sidebar` - The sidebar container.
|
||||
- `SidebarHeader` and `SidebarFooter` - Sticky at the top and bottom of the sidebar.
|
||||
- `SidebarContent` - Scrollable content.
|
||||
- `SidebarGroup` - Section within the `SidebarContent`.
|
||||
- `SidebarTrigger` - Trigger for the `Sidebar`.
|
||||
|
||||
<Image
|
||||
src="/images/sidebar-structure.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 w-full overflow-hidden rounded-lg border dark:hidden"
|
||||
/>
|
||||
<Image
|
||||
src="/images/sidebar-structure-dark.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 hidden w-full overflow-hidden rounded-lg border dark:block"
|
||||
/>
|
||||
|
||||
## Usage
|
||||
|
||||
```tsx showLineNumbers title="app/layout.tsx"
|
||||
@@ -123,6 +97,67 @@ export function AppSidebar() {
|
||||
}
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Sidebar` layout:
|
||||
|
||||
```text
|
||||
SidebarProvider
|
||||
├── Sidebar
|
||||
│ ├── SidebarHeader
|
||||
│ ├── SidebarContent
|
||||
│ │ ├── SidebarGroup
|
||||
│ │ │ ├── SidebarGroupLabel
|
||||
│ │ │ ├── SidebarGroupAction
|
||||
│ │ │ ├── SidebarGroupContent
|
||||
│ │ │ └── SidebarMenu
|
||||
│ │ │ ├── SidebarMenuItem
|
||||
│ │ │ │ ├── SidebarMenuButton
|
||||
│ │ │ │ ├── SidebarMenuAction
|
||||
│ │ │ │ └── SidebarMenuBadge
|
||||
│ │ │ └── SidebarMenuItem
|
||||
│ │ │ ├── SidebarMenuButton
|
||||
│ │ │ └── SidebarMenuSub
|
||||
│ │ │ ├── SidebarMenuSubItem
|
||||
│ │ │ └── SidebarMenuSubItem
|
||||
│ │ └── SidebarGroup
|
||||
│ │ └── SidebarMenu
|
||||
│ │ ├── SidebarMenuItem
|
||||
│ │ └── SidebarMenuItem
|
||||
│ ├── SidebarFooter
|
||||
│ └── SidebarRail
|
||||
├── SidebarInset
|
||||
└── SidebarTrigger
|
||||
```
|
||||
|
||||
## Structure
|
||||
|
||||
- **SidebarProvider** — Handles collapsible state and provides sidebar context to child components.
|
||||
- **Sidebar** — The main collapsible sidebar panel.
|
||||
- **SidebarHeader** — Sticky at the top; use for branding, titles, or workspace switchers.
|
||||
- **SidebarFooter** — Sticky at the bottom; use for user menus, settings, or actions.
|
||||
- **SidebarContent** — Scrollable region between the header and footer.
|
||||
- **SidebarGroup** — Groups related navigation with optional label, action, and content areas.
|
||||
- **SidebarMenu** / **SidebarMenuItem** — Menu structure for links, badges, actions, and nested submenus.
|
||||
- **SidebarRail** — Resize handle for adjusting sidebar width when applicable.
|
||||
- **SidebarInset** — Wraps main content when using the `inset` variant.
|
||||
- **SidebarTrigger** — Control that toggles the sidebar open or collapsed.
|
||||
|
||||
<Image
|
||||
src="/images/sidebar-structure.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 w-full overflow-hidden rounded-lg border dark:hidden"
|
||||
/>
|
||||
<Image
|
||||
src="/images/sidebar-structure-dark.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 hidden w-full overflow-hidden rounded-lg border dark:block"
|
||||
/>
|
||||
|
||||
## SidebarProvider
|
||||
|
||||
The `SidebarProvider` component is used to provide the sidebar context to the `Sidebar` component. You should always wrap your application in a `SidebarProvider` component.
|
||||
|
||||
@@ -83,6 +83,33 @@ import {
|
||||
</Table>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Table`:
|
||||
|
||||
```text
|
||||
Table
|
||||
├── TableCaption
|
||||
├── TableHeader
|
||||
│ └── TableRow
|
||||
│ ├── TableHead
|
||||
│ ├── TableHead
|
||||
│ ├── TableHead
|
||||
│ └── TableHead
|
||||
├── TableBody
|
||||
│ ├── TableRow
|
||||
│ │ ├── TableCell
|
||||
│ │ ├── TableCell
|
||||
│ │ ├── TableCell
|
||||
│ │ └── TableCell
|
||||
│ └── TableRow
|
||||
│ ├── TableCell
|
||||
│ ├── TableCell
|
||||
│ ├── TableCell
|
||||
│ └── TableCell
|
||||
└── TableFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Footer
|
||||
|
||||
@@ -73,6 +73,19 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build `Tabs`:
|
||||
|
||||
```text
|
||||
Tabs
|
||||
├── TabsList
|
||||
│ ├── TabsTrigger
|
||||
│ └── TabsTrigger
|
||||
├── TabsContent
|
||||
└── TabsContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Line
|
||||
|
||||
@@ -66,6 +66,16 @@ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
|
||||
</ToggleGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ToggleGroup`:
|
||||
|
||||
```text
|
||||
ToggleGroup
|
||||
├── ToggleGroupItem
|
||||
└── ToggleGroupItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Outline
|
||||
|
||||
@@ -109,6 +109,16 @@ import {
|
||||
</Tooltip>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Tooltip`:
|
||||
|
||||
```text
|
||||
Tooltip
|
||||
├── TooltipTrigger
|
||||
└── TooltipContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Side
|
||||
|
||||
@@ -80,6 +80,20 @@ import {
|
||||
</Accordion>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Accordion`:
|
||||
|
||||
```text
|
||||
Accordion
|
||||
├── AccordionItem
|
||||
│ ├── AccordionTrigger
|
||||
│ └── AccordionContent
|
||||
└── AccordionItem
|
||||
├── AccordionTrigger
|
||||
└── AccordionContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -94,6 +94,23 @@ import {
|
||||
</AlertDialog>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `AlertDialog`:
|
||||
|
||||
```text
|
||||
AlertDialog
|
||||
├── AlertDialogTrigger
|
||||
└── AlertDialogContent
|
||||
├── AlertDialogHeader
|
||||
│ ├── AlertDialogMedia
|
||||
│ ├── AlertDialogTitle
|
||||
│ └── AlertDialogDescription
|
||||
└── AlertDialogFooter
|
||||
├── AlertDialogCancel
|
||||
└── AlertDialogAction
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -71,6 +71,18 @@ import {
|
||||
</Alert>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Alert`:
|
||||
|
||||
```text
|
||||
Alert
|
||||
├── Icon
|
||||
├── AlertTitle
|
||||
├── AlertDescription
|
||||
└── AlertAction
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -65,6 +65,32 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
</Avatar>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Avatar`:
|
||||
|
||||
```text
|
||||
Avatar
|
||||
├── AvatarImage
|
||||
├── AvatarFallback
|
||||
└── AvatarBadge
|
||||
```
|
||||
|
||||
Use the following composition to build an `AvatarGroup`:
|
||||
|
||||
```text
|
||||
AvatarGroup
|
||||
├── Avatar
|
||||
│ ├── AvatarImage
|
||||
│ ├── AvatarFallback
|
||||
│ └── AvatarBadge
|
||||
├── Avatar
|
||||
│ ├── AvatarImage
|
||||
│ ├── AvatarFallback
|
||||
│ └── AvatarBadge
|
||||
└── AvatarGroupCount
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -74,6 +74,23 @@ import {
|
||||
</Breadcrumb>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Breadcrumb`:
|
||||
|
||||
```text
|
||||
Breadcrumb
|
||||
└── BreadcrumbList
|
||||
├── BreadcrumbItem
|
||||
│ └── BreadcrumbLink
|
||||
├── BreadcrumbSeparator
|
||||
├── BreadcrumbItem
|
||||
│ └── BreadcrumbLink
|
||||
├── BreadcrumbSeparator
|
||||
└── BreadcrumbItem
|
||||
└── BreadcrumbPage
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -66,6 +66,17 @@ import {
|
||||
</ButtonGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ButtonGroup`:
|
||||
|
||||
```text
|
||||
ButtonGroup
|
||||
├── Button or Input
|
||||
├── ButtonGroupSeparator
|
||||
└── ButtonGroupText
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
- The `ButtonGroup` component has the `role` attribute set to `group`.
|
||||
|
||||
@@ -77,6 +77,20 @@ import {
|
||||
</Card>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Card`:
|
||||
|
||||
```text
|
||||
Card
|
||||
├── CardHeader
|
||||
│ ├── CardTitle
|
||||
│ ├── CardDescription
|
||||
│ └── CardAction
|
||||
├── CardContent
|
||||
└── CardFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Size
|
||||
|
||||
@@ -85,6 +85,19 @@ import {
|
||||
</Carousel>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Carousel`:
|
||||
|
||||
```text
|
||||
Carousel
|
||||
├── CarouselContent
|
||||
│ ├── CarouselItem
|
||||
│ └── CarouselItem
|
||||
├── CarouselPrevious
|
||||
└── CarouselNext
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Sizes
|
||||
|
||||
@@ -77,6 +77,16 @@ import {
|
||||
</Collapsible>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Collapsible`:
|
||||
|
||||
```text
|
||||
Collapsible
|
||||
├── CollapsibleTrigger
|
||||
└── CollapsibleContent
|
||||
```
|
||||
|
||||
## Controlled State
|
||||
|
||||
Use the `open` and `onOpenChange` props to control the state.
|
||||
|
||||
@@ -90,6 +90,62 @@ export function ExampleCombobox() {
|
||||
}
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Simple
|
||||
|
||||
A single-line input and a flat list (see [Basic](#basic)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
### With chips
|
||||
|
||||
Multi-select with `multiple`, chips, and a chips input (see [Multiple](#multiple)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxChips
|
||||
│ ├── ComboboxValue
|
||||
│ │ └── ComboboxChip
|
||||
│ └── ComboboxChipsInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
### With groups and collection
|
||||
|
||||
Nested items per group using `ComboboxCollection` inside each `ComboboxGroup`, with a separator between groups (see [Groups](#groups)).
|
||||
|
||||
```text
|
||||
Combobox
|
||||
├── ComboboxInput
|
||||
└── ComboboxContent
|
||||
├── ComboboxEmpty
|
||||
└── ComboboxList
|
||||
├── ComboboxGroup
|
||||
│ ├── ComboboxLabel
|
||||
│ └── ComboboxCollection
|
||||
│ ├── ComboboxItem
|
||||
│ └── ComboboxItem
|
||||
├── ComboboxSeparator
|
||||
└── ComboboxGroup
|
||||
├── ComboboxLabel
|
||||
└── ComboboxCollection
|
||||
├── ComboboxItem
|
||||
└── ComboboxItem
|
||||
```
|
||||
|
||||
## Custom Items
|
||||
|
||||
Use `itemToStringValue` when your items are objects.
|
||||
|
||||
@@ -96,6 +96,24 @@ import {
|
||||
</Command>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Command`:
|
||||
|
||||
```text
|
||||
Command
|
||||
├── CommandInput
|
||||
└── CommandList
|
||||
├── CommandEmpty
|
||||
├── CommandGroup
|
||||
│ ├── CommandItem
|
||||
│ └── CommandItem
|
||||
├── CommandSeparator
|
||||
└── CommandGroup
|
||||
├── CommandItem
|
||||
└── CommandItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -79,6 +79,37 @@ import {
|
||||
</ContextMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ContextMenu`:
|
||||
|
||||
```text
|
||||
ContextMenu
|
||||
├── ContextMenuTrigger
|
||||
└── ContextMenuContent
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ ├── ContextMenuItem
|
||||
│ └── ContextMenuItem
|
||||
├── ContextMenuSeparator
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ ├── ContextMenuCheckboxItem
|
||||
│ └── ContextMenuCheckboxItem
|
||||
├── ContextMenuSeparator
|
||||
├── ContextMenuGroup
|
||||
│ ├── ContextMenuLabel
|
||||
│ └── ContextMenuRadioGroup
|
||||
│ ├── ContextMenuRadioItem
|
||||
│ └── ContextMenuRadioItem
|
||||
└── ContextMenuSub
|
||||
├── ContextMenuSubTrigger
|
||||
└── ContextMenuSubContent
|
||||
└── ContextMenuGroup
|
||||
├── ContextMenuItem
|
||||
└── ContextMenuItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -56,6 +56,17 @@ export function DatePickerDemo() {
|
||||
|
||||
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
|
||||
|
||||
## Composition
|
||||
|
||||
A date picker is built from `Popover` and `Calendar` (there is no `DatePicker` root component):
|
||||
|
||||
```text
|
||||
Popover
|
||||
├── PopoverTrigger
|
||||
└── PopoverContent
|
||||
└── Calendar
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -85,6 +85,20 @@ import {
|
||||
</Dialog>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Dialog`:
|
||||
|
||||
```text
|
||||
Dialog
|
||||
├── DialogTrigger
|
||||
└── DialogContent
|
||||
├── DialogHeader
|
||||
│ ├── DialogTitle
|
||||
│ └── DialogDescription
|
||||
└── DialogFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Custom Close Button
|
||||
|
||||
@@ -88,6 +88,20 @@ import {
|
||||
</Drawer>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Drawer`:
|
||||
|
||||
```text
|
||||
Drawer
|
||||
├── DrawerTrigger
|
||||
└── DrawerContent
|
||||
├── DrawerHeader
|
||||
│ ├── DrawerTitle
|
||||
│ └── DrawerDescription
|
||||
└── DrawerFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Scrollable Content
|
||||
|
||||
@@ -92,6 +92,38 @@ import {
|
||||
</DropdownMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `DropdownMenu`:
|
||||
|
||||
```text
|
||||
DropdownMenu
|
||||
├── DropdownMenuTrigger
|
||||
└── DropdownMenuContent
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ ├── DropdownMenuItem
|
||||
│ └── DropdownMenuItem
|
||||
├── DropdownMenuSeparator
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ ├── DropdownMenuCheckboxItem
|
||||
│ └── DropdownMenuCheckboxItem
|
||||
├── DropdownMenuSeparator
|
||||
├── DropdownMenuGroup
|
||||
│ ├── DropdownMenuLabel
|
||||
│ └── DropdownMenuRadioGroup
|
||||
│ ├── DropdownMenuRadioItem
|
||||
│ └── DropdownMenuRadioItem
|
||||
└── DropdownMenuSub
|
||||
├── DropdownMenuSubTrigger
|
||||
└── DropdownMenuSubContent
|
||||
└── DropdownMenuGroup
|
||||
├── DropdownMenuLabel
|
||||
├── DropdownMenuItem
|
||||
└── DropdownMenuItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -75,6 +75,19 @@ import {
|
||||
</Empty>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Empty` state:
|
||||
|
||||
```text
|
||||
Empty
|
||||
├── EmptyHeader
|
||||
│ ├── EmptyMedia
|
||||
│ ├── EmptyTitle
|
||||
│ └── EmptyDescription
|
||||
└── EmptyContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Outline
|
||||
|
||||
@@ -87,6 +87,56 @@ import {
|
||||
</FieldSet>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Field
|
||||
|
||||
A single control with label, helper text, and validation.
|
||||
|
||||
```text
|
||||
Field
|
||||
├── FieldLabel
|
||||
├── Input / Textarea / Switch / Select
|
||||
├── FieldDescription
|
||||
└── FieldError
|
||||
```
|
||||
|
||||
### FieldGroup
|
||||
|
||||
Related fields in one group. Use `FieldSeparator` between sections when needed.
|
||||
|
||||
```text
|
||||
FieldGroup
|
||||
├── Field
|
||||
│ ├── FieldLabel
|
||||
│ ├── Input / Textarea / Switch / Select
|
||||
│ ├── FieldDescription
|
||||
│ └── FieldError
|
||||
├── FieldSeparator
|
||||
└── Field
|
||||
├── FieldLabel
|
||||
└── Input / Textarea / Switch / Select
|
||||
```
|
||||
|
||||
### FieldSet
|
||||
|
||||
Semantic grouping with a legend and description, usually containing a `FieldGroup`.
|
||||
|
||||
```text
|
||||
FieldSet
|
||||
├── FieldLegend
|
||||
├── FieldDescription
|
||||
└── FieldGroup
|
||||
├── Field
|
||||
│ ├── FieldLabel
|
||||
│ ├── Input / Textarea / Switch / Select
|
||||
│ ├── FieldDescription
|
||||
│ └── FieldError
|
||||
└── Field
|
||||
├── FieldLabel
|
||||
└── Input / Textarea / Switch / Select
|
||||
```
|
||||
|
||||
## Anatomy
|
||||
|
||||
The `Field` family is designed for composing accessible forms. A typical field is structured as follows:
|
||||
|
||||
@@ -75,6 +75,16 @@ import {
|
||||
</HoverCard>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `HoverCard`:
|
||||
|
||||
```text
|
||||
HoverCard
|
||||
├── HoverCardTrigger
|
||||
└── HoverCardContent
|
||||
```
|
||||
|
||||
## Trigger Delays
|
||||
|
||||
Use `openDelay` and `closeDelay` on the `HoverCard` to control when the card opens and
|
||||
|
||||
@@ -71,6 +71,18 @@ import {
|
||||
</InputGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `InputGroup`:
|
||||
|
||||
```text
|
||||
InputGroup
|
||||
├── InputGroupInput or InputGroupTextarea
|
||||
├── InputGroupAddon
|
||||
├── InputGroupButton
|
||||
└── InputGroupText
|
||||
```
|
||||
|
||||
## Align
|
||||
|
||||
Use the `align` prop on `InputGroupAddon` to position the addon relative to the input.
|
||||
|
||||
@@ -82,6 +82,27 @@ import {
|
||||
</InputOTP>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `InputOTP`:
|
||||
|
||||
```text
|
||||
InputOTP
|
||||
├── InputOTPGroup
|
||||
│ ├── InputOTPSlot
|
||||
│ ├── InputOTPSlot
|
||||
│ └── InputOTPSlot
|
||||
├── InputOTPSeparator
|
||||
├── InputOTPGroup
|
||||
│ ├── InputOTPSlot
|
||||
│ ├── InputOTPSlot
|
||||
│ └── InputOTPSlot
|
||||
├── InputOTPSeparator
|
||||
└── InputOTPGroup
|
||||
├── InputOTPSlot
|
||||
└── InputOTPSlot
|
||||
```
|
||||
|
||||
## Pattern
|
||||
|
||||
Use the `pattern` prop to define a custom pattern for the OTP input.
|
||||
|
||||
@@ -73,6 +73,22 @@ import {
|
||||
</Item>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build an `Item`:
|
||||
|
||||
```text
|
||||
ItemGroup
|
||||
└── Item
|
||||
├── ItemHeader
|
||||
├── ItemMedia
|
||||
├── ItemContent
|
||||
│ ├── ItemTitle
|
||||
│ └── ItemDescription
|
||||
├── ItemActions
|
||||
└── ItemFooter
|
||||
```
|
||||
|
||||
## Item vs Field
|
||||
|
||||
Use `Field` if you need to display a form input such as a checkbox, input, radio, or select.
|
||||
|
||||
@@ -53,6 +53,17 @@ import { Kbd } from "@/components/ui/kbd"
|
||||
<Kbd>Ctrl</Kbd>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build `Kbd` and `KbdGroup`:
|
||||
|
||||
```text
|
||||
Kbd
|
||||
KbdGroup
|
||||
├── Kbd
|
||||
└── Kbd
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Group
|
||||
|
||||
@@ -88,6 +88,46 @@ import {
|
||||
</Menubar>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Menubar`:
|
||||
|
||||
```text
|
||||
Menubar
|
||||
├── MenubarMenu
|
||||
│ ├── MenubarTrigger
|
||||
│ └── MenubarContent
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ ├── MenubarItem
|
||||
│ │ └── MenubarItem
|
||||
│ ├── MenubarSeparator
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ ├── MenubarCheckboxItem
|
||||
│ │ └── MenubarCheckboxItem
|
||||
│ ├── MenubarSeparator
|
||||
│ ├── MenubarGroup
|
||||
│ │ ├── MenubarLabel
|
||||
│ │ └── MenubarRadioGroup
|
||||
│ │ ├── MenubarRadioItem
|
||||
│ │ └── MenubarRadioItem
|
||||
│ └── MenubarSub
|
||||
│ ├── MenubarSubTrigger
|
||||
│ └── MenubarSubContent
|
||||
│ └── MenubarGroup
|
||||
│ ├── MenubarLabel
|
||||
│ ├── MenubarItem
|
||||
│ └── MenubarItem
|
||||
└── MenubarMenu
|
||||
├── MenubarTrigger
|
||||
└── MenubarContent
|
||||
└── MenubarGroup
|
||||
├── MenubarLabel
|
||||
├── MenubarItem
|
||||
└── MenubarItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Checkbox
|
||||
|
||||
@@ -70,6 +70,34 @@ import {
|
||||
</NativeSelect>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
### Simple
|
||||
|
||||
Options placed directly under `NativeSelect` (no `NativeSelectOptGroup`).
|
||||
|
||||
```text
|
||||
NativeSelect
|
||||
├── NativeSelectOption
|
||||
├── NativeSelectOption
|
||||
├── NativeSelectOption
|
||||
└── NativeSelectOption
|
||||
```
|
||||
|
||||
### With groups
|
||||
|
||||
Use `NativeSelectOptGroup` to organize options into categories.
|
||||
|
||||
```text
|
||||
NativeSelect
|
||||
├── NativeSelectOptGroup
|
||||
│ ├── NativeSelectOption
|
||||
│ └── NativeSelectOption
|
||||
└── NativeSelectOptGroup
|
||||
├── NativeSelectOption
|
||||
└── NativeSelectOption
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Groups
|
||||
|
||||
@@ -82,6 +82,23 @@ import {
|
||||
</NavigationMenu>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `NavigationMenu`:
|
||||
|
||||
```text
|
||||
NavigationMenu
|
||||
├── NavigationMenuList
|
||||
│ ├── NavigationMenuItem
|
||||
│ │ ├── NavigationMenuTrigger
|
||||
│ │ └── NavigationMenuContent
|
||||
│ │ ├── NavigationMenuLink
|
||||
│ │ └── NavigationMenuLink
|
||||
│ └── NavigationMenuItem
|
||||
│ └── NavigationMenuLink
|
||||
└── NavigationMenuIndicator
|
||||
```
|
||||
|
||||
## Link Component
|
||||
|
||||
Use the `asChild` prop to compose a custom link component such as Next.js `Link`.
|
||||
|
||||
@@ -84,6 +84,23 @@ import {
|
||||
</Pagination>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Pagination`:
|
||||
|
||||
```text
|
||||
Pagination
|
||||
└── PaginationContent
|
||||
├── PaginationItem
|
||||
│ └── PaginationPrevious
|
||||
├── PaginationItem
|
||||
│ └── PaginationLink
|
||||
├── PaginationItem
|
||||
│ └── PaginationEllipsis
|
||||
└── PaginationItem
|
||||
└── PaginationNext
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Simple
|
||||
|
||||
@@ -79,6 +79,16 @@ import {
|
||||
</Popover>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Popover`:
|
||||
|
||||
```text
|
||||
Popover
|
||||
├── PopoverTrigger
|
||||
└── PopoverContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic
|
||||
|
||||
@@ -72,6 +72,16 @@ import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
|
||||
</RadioGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `RadioGroup`:
|
||||
|
||||
```text
|
||||
RadioGroup
|
||||
├── RadioGroupItem
|
||||
└── RadioGroupItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Description
|
||||
|
||||
@@ -78,6 +78,17 @@ import {
|
||||
</ResizablePanelGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ResizablePanelGroup`:
|
||||
|
||||
```text
|
||||
ResizablePanelGroup
|
||||
├── ResizablePanel
|
||||
├── ResizableHandle
|
||||
└── ResizablePanel
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Vertical
|
||||
|
||||
@@ -68,6 +68,15 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"
|
||||
</ScrollArea>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ScrollArea`:
|
||||
|
||||
```text
|
||||
ScrollArea
|
||||
└── ScrollBar
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Horizontal
|
||||
|
||||
@@ -81,6 +81,26 @@ import {
|
||||
</Select>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Select`:
|
||||
|
||||
```text
|
||||
Select
|
||||
├── SelectTrigger
|
||||
│ └── SelectValue
|
||||
└── SelectContent
|
||||
├── SelectGroup
|
||||
│ ├── SelectLabel
|
||||
│ ├── SelectItem
|
||||
│ └── SelectItem
|
||||
├── SelectSeparator
|
||||
└── SelectGroup
|
||||
├── SelectLabel
|
||||
├── SelectItem
|
||||
└── SelectItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Align Item With Trigger
|
||||
|
||||
@@ -79,6 +79,20 @@ import {
|
||||
</Sheet>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Sheet`:
|
||||
|
||||
```text
|
||||
Sheet
|
||||
├── SheetTrigger
|
||||
└── SheetContent
|
||||
├── SheetHeader
|
||||
│ ├── SheetTitle
|
||||
│ └── SheetDescription
|
||||
└── SheetFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Side
|
||||
|
||||
@@ -55,32 +55,6 @@ npx shadcn@latest add sidebar
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
## Structure
|
||||
|
||||
A `Sidebar` component is composed of the following parts:
|
||||
|
||||
- `SidebarProvider` - Handles collapsible state.
|
||||
- `Sidebar` - The sidebar container.
|
||||
- `SidebarHeader` and `SidebarFooter` - Sticky at the top and bottom of the sidebar.
|
||||
- `SidebarContent` - Scrollable content.
|
||||
- `SidebarGroup` - Section within the `SidebarContent`.
|
||||
- `SidebarTrigger` - Trigger for the `Sidebar`.
|
||||
|
||||
<Image
|
||||
src="/images/sidebar-structure.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 w-full overflow-hidden rounded-lg border dark:hidden"
|
||||
/>
|
||||
<Image
|
||||
src="/images/sidebar-structure-dark.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 hidden w-full overflow-hidden rounded-lg border dark:block"
|
||||
/>
|
||||
|
||||
## Usage
|
||||
|
||||
```tsx showLineNumbers title="app/layout.tsx"
|
||||
@@ -123,6 +97,67 @@ export function AppSidebar() {
|
||||
}
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Sidebar` layout:
|
||||
|
||||
```text
|
||||
SidebarProvider
|
||||
├── Sidebar
|
||||
│ ├── SidebarHeader
|
||||
│ ├── SidebarContent
|
||||
│ │ ├── SidebarGroup
|
||||
│ │ │ ├── SidebarGroupLabel
|
||||
│ │ │ ├── SidebarGroupAction
|
||||
│ │ │ ├── SidebarGroupContent
|
||||
│ │ │ └── SidebarMenu
|
||||
│ │ │ ├── SidebarMenuItem
|
||||
│ │ │ │ ├── SidebarMenuButton
|
||||
│ │ │ │ ├── SidebarMenuAction
|
||||
│ │ │ │ └── SidebarMenuBadge
|
||||
│ │ │ └── SidebarMenuItem
|
||||
│ │ │ ├── SidebarMenuButton
|
||||
│ │ │ └── SidebarMenuSub
|
||||
│ │ │ ├── SidebarMenuSubItem
|
||||
│ │ │ └── SidebarMenuSubItem
|
||||
│ │ └── SidebarGroup
|
||||
│ │ └── SidebarMenu
|
||||
│ │ ├── SidebarMenuItem
|
||||
│ │ └── SidebarMenuItem
|
||||
│ ├── SidebarFooter
|
||||
│ └── SidebarRail
|
||||
├── SidebarInset
|
||||
└── SidebarTrigger
|
||||
```
|
||||
|
||||
## Structure
|
||||
|
||||
- **SidebarProvider** — Handles collapsible state and provides sidebar context to child components.
|
||||
- **Sidebar** — The main collapsible sidebar panel.
|
||||
- **SidebarHeader** — Sticky at the top; use for branding, titles, or workspace switchers.
|
||||
- **SidebarFooter** — Sticky at the bottom; use for user menus, settings, or actions.
|
||||
- **SidebarContent** — Scrollable region between the header and footer.
|
||||
- **SidebarGroup** — Groups related navigation with optional label, action, and content areas.
|
||||
- **SidebarMenu** / **SidebarMenuItem** — Menu structure for links, badges, actions, and nested submenus.
|
||||
- **SidebarRail** — Resize handle for adjusting sidebar width when applicable.
|
||||
- **SidebarInset** — Wraps main content when using the `inset` variant.
|
||||
- **SidebarTrigger** — Control that toggles the sidebar open or collapsed.
|
||||
|
||||
<Image
|
||||
src="/images/sidebar-structure.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 w-full overflow-hidden rounded-lg border dark:hidden"
|
||||
/>
|
||||
<Image
|
||||
src="/images/sidebar-structure-dark.png"
|
||||
width="716"
|
||||
height="420"
|
||||
alt="Sidebar Structure"
|
||||
className="mt-6 hidden w-full overflow-hidden rounded-lg border dark:block"
|
||||
/>
|
||||
|
||||
## SidebarProvider
|
||||
|
||||
The `SidebarProvider` component is used to provide the sidebar context to the `Sidebar` component. You should always wrap your application in a `SidebarProvider` component.
|
||||
|
||||
@@ -83,6 +83,33 @@ import {
|
||||
</Table>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Table`:
|
||||
|
||||
```text
|
||||
Table
|
||||
├── TableCaption
|
||||
├── TableHeader
|
||||
│ └── TableRow
|
||||
│ ├── TableHead
|
||||
│ ├── TableHead
|
||||
│ ├── TableHead
|
||||
│ └── TableHead
|
||||
├── TableBody
|
||||
│ ├── TableRow
|
||||
│ │ ├── TableCell
|
||||
│ │ ├── TableCell
|
||||
│ │ ├── TableCell
|
||||
│ │ └── TableCell
|
||||
│ └── TableRow
|
||||
│ ├── TableCell
|
||||
│ ├── TableCell
|
||||
│ ├── TableCell
|
||||
│ └── TableCell
|
||||
└── TableFooter
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Footer
|
||||
|
||||
@@ -73,6 +73,19 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
</Tabs>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build `Tabs`:
|
||||
|
||||
```text
|
||||
Tabs
|
||||
├── TabsList
|
||||
│ ├── TabsTrigger
|
||||
│ └── TabsTrigger
|
||||
├── TabsContent
|
||||
└── TabsContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Line
|
||||
|
||||
@@ -66,6 +66,16 @@ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
|
||||
</ToggleGroup>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `ToggleGroup`:
|
||||
|
||||
```text
|
||||
ToggleGroup
|
||||
├── ToggleGroupItem
|
||||
└── ToggleGroupItem
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Outline
|
||||
|
||||
@@ -109,6 +109,16 @@ import {
|
||||
</Tooltip>
|
||||
```
|
||||
|
||||
## Composition
|
||||
|
||||
Use the following composition to build a `Tooltip`:
|
||||
|
||||
```text
|
||||
Tooltip
|
||||
├── TooltipTrigger
|
||||
└── TooltipContent
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Side
|
||||
|
||||
Reference in New Issue
Block a user