content/docs/components/base/sortable.mdx
<ComponentPreview styleName="base-nova" name="c-sortable-1" className="**:[.preview]:h-auto" align="start" />
npx shadcn@latest add @reui/sortable
<Step>Install the following dependencies:</Step>
npm install @dnd-kit/core @dnd-kit/sortable @base-ui/react
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource styleName="base-nova" name="sortable" title="components/reui/sortable.tsx" />
</Steps> </TabsContent> </CodeTabs>import {
Sortable,
SortableItem,
SortableItemHandle,
} from "@/components/reui/sortable"
<Sortable
value={items}
onValueChange={setItems}
getItemValue={(item) => item.id}
>
{items.map((item) => (
<SortableItem key={item.id} value={item.id}>
<SortableItemHandle>
<GripVertical />
</SortableItemHandle>
{item.content}
</SortableItem>
))}
</Sortable>
<ComponentPreview styleName="base-nova" name="c-sortable-2" className="**:[.preview]:h-auto" align="start" />
<ComponentPreview styleName="base-nova" name="c-sortable-3" className="**:[.preview]:h-auto" align="start" />
The root component that manages the sortable state and drag-and-drop context.
| Prop | Type | Default | Description |
|---|---|---|---|
value | T[] | - | Required. The array of items to sort. |
onValueChange | (value: T[]) => void | - | Required. Callback fired when items are reordered. |
getItemValue | (item: T) => string | - | Required. Function to extract a unique ID from an item. |
layout | "vertical" | "grid" | "nested" | "vertical" | The visual layout of the sortable list. |
className | string | - | Additional CSS classes for the container. |
An individual draggable item within the sortable list.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | Required. The unique identifier for the item. |
disabled | boolean | false | Whether the item is draggable. |
className | string | - | Additional CSS classes for the item. |
The drag handle for an individual sortable item.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the handle. |