Sortable List
Preview
In the studio
Make room for what matters.
Drag a handle to reorder. With a handle focused, use Up and Down to move, Home and End to move to the edges. Space lifts a row and drops it again, and Escape cancels the lift.
- 01
Collect references
Find the right direction
- 02
Explore the visual system
Type, color, and composition
- 03
Build the first prototype
Make the interaction tangible
- 04
Ship something useful
Polish the details and release
<script setup lang="ts">
import { SortableList, SortableListGroup, SortableListHandle, SortableListItem, SortableListItemContent, SortableListUndo } from 'beui-vue'
import { defineComponent, h, type PropType } from 'vue'
/** Inline Lucide glyphs for the layout demos (generated from lucide-react, ISC). Inner markup of 24x24 stroked icons. */
const ICONS: Record<string, string> = {
"ArrowRight": "<path d=\"M5 12h14\"></path><path d=\"m12 5 7 7-7 7\"></path>",
"ArrowUp": "<path d=\"m5 12 7-7 7 7\"></path><path d=\"M12 19V5\"></path>",
"ArrowUpRight": "<path d=\"M7 7h10v10\"></path><path d=\"M7 17 17 7\"></path>",
"BarChart3": "<path d=\"M3 3v16a2 2 0 0 0 2 2h16\"></path><path d=\"M18 17V9\"></path><path d=\"M13 17V5\"></path><path d=\"M8 17v-3\"></path>",
"Bell": "<path d=\"M10.268 21a2 2 0 0 0 3.464 0\"></path><path d=\"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326\"></path>",
"Braces": "<path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1\"></path>",
"Building2": "<path d=\"M10 12h4\"></path><path d=\"M10 8h4\"></path><path d=\"M14 21v-3a2 2 0 0 0-4 0v3\"></path><path d=\"M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2\"></path><path d=\"M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16\"></path>",
"Calendar": "<path d=\"M8 2v3\"></path><path d=\"M16 2v3\"></path><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"></rect><path d=\"M3 9h18\"></path>",
"CalendarClock": "<path d=\"M16 14v2.2l1.6 1\"></path><path d=\"M16 2v3\"></path><path d=\"M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338\"></path><path d=\"M3 9h5.859\"></path><path d=\"M8 2v3\"></path><circle cx=\"16\" cy=\"16\" r=\"6\"></circle>",
"Check": "<path d=\"M20 6 9 17l-5-5\"></path>",
"CheckCircle2": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m9 12 2 2 4-4\"></path>",
"ChevronDown": "<path d=\"m6 9 6 6 6-6\"></path>",
"ChevronLeft": "<path d=\"m15 18-6-6 6-6\"></path>",
"ChevronRight": "<path d=\"m9 18 6-6-6-6\"></path>",
"ChevronUp": "<path d=\"m18 15-6-6-6 6\"></path>",
"ChevronsUpDown": "<path d=\"m7 15 5 5 5-5\"></path><path d=\"m7 9 5-5 5 5\"></path>",
"Circle": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle>",
"CircleUserRound": "<path d=\"M17.925 20.056a6 6 0 0 0-11.851.001\"></path><circle cx=\"12\" cy=\"11\" r=\"4\"></circle><circle cx=\"12\" cy=\"12\" r=\"10\"></circle>",
"Command": "<path d=\"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3\"></path>",
"File": "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path>",
"FileCode2": "<path d=\"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"m5 16-3 3 3 3\"></path><path d=\"m9 22 3-3-3-3\"></path>",
"FileJson2": "<path d=\"M14 22h4a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v6\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M5 14a1 1 0 0 0-1 1v2a1 1 0 0 1-1 1 1 1 0 0 1 1 1v2a1 1 0 0 0 1 1\"></path><path d=\"M9 22a1 1 0 0 0 1-1v-2a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-2a1 1 0 0 0-1-1\"></path>",
"FileText": "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path>",
"Folder": "<path d=\"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z\"></path>",
"FolderKanban": "<path d=\"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z\"></path><path d=\"M8 10v4\"></path><path d=\"M12 10v2\"></path><path d=\"M16 10v6\"></path>",
"FolderOpen": "<path d=\"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2\"></path>",
"GitPullRequest": "<circle cx=\"18\" cy=\"18\" r=\"3\"></circle><circle cx=\"6\" cy=\"6\" r=\"3\"></circle><path d=\"M13 6h3a2 2 0 0 1 2 2v7\"></path><line x1=\"6\" x2=\"6\" y1=\"9\" y2=\"21\"></line>",
"GripVertical": "<circle cx=\"9\" cy=\"12\" r=\"1\"></circle><circle cx=\"9\" cy=\"5\" r=\"1\"></circle><circle cx=\"9\" cy=\"19\" r=\"1\"></circle><circle cx=\"15\" cy=\"12\" r=\"1\"></circle><circle cx=\"15\" cy=\"5\" r=\"1\"></circle><circle cx=\"15\" cy=\"19\" r=\"1\"></circle>",
"Heart": "<path d=\"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5\"></path>",
"Home": "<path d=\"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8\"></path><path d=\"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z\"></path>",
"House": "<path d=\"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8\"></path><path d=\"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z\"></path>",
"Inbox": "<polyline points=\"22 12 16 12 14 15 10 15 8 12 2 12\"></polyline><path d=\"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z\"></path>",
"Layers": "<path d=\"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z\"></path><path d=\"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12\"></path><path d=\"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17\"></path>",
"LayoutGrid": "<rect width=\"7\" height=\"7\" x=\"3\" y=\"3\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"14\" y=\"3\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"14\" y=\"14\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"3\" y=\"14\" rx=\"1\"></rect>",
"ListTodo": "<path d=\"M13 5h8\"></path><path d=\"M13 12h8\"></path><path d=\"M13 19h8\"></path><path d=\"m3 17 2 2 4-4\"></path><rect x=\"3\" y=\"4\" width=\"6\" height=\"6\" rx=\"1\"></rect>",
"LoaderCircle": "<path d=\"M21 12a9 9 0 1 1-6.219-8.56\"></path>",
"Mail": "<path d=\"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7\"></path><rect x=\"2\" y=\"4\" width=\"20\" height=\"16\" rx=\"2\"></rect>",
"MessageCircle": "<path d=\"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719\"></path>",
"Minus": "<path d=\"M5 12h14\"></path>",
"Music": "<path d=\"M9 18V5l12-2v13\"></path><circle cx=\"6\" cy=\"18\" r=\"3\"></circle><circle cx=\"18\" cy=\"16\" r=\"3\"></circle>",
"NotebookTabs": "<path d=\"M2 6h4\"></path><path d=\"M2 10h4\"></path><path d=\"M2 14h4\"></path><path d=\"M2 18h4\"></path><rect width=\"16\" height=\"20\" x=\"4\" y=\"2\" rx=\"2\"></rect><path d=\"M15 2v20\"></path><path d=\"M15 7h5\"></path><path d=\"M15 12h5\"></path><path d=\"M15 17h5\"></path>",
"PackageCheck": "<path d=\"M12 22V12\"></path><path d=\"m16 17 2 2 4-4\"></path><path d=\"M21 11.127V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.32-.753\"></path><path d=\"M3.29 7 12 12l8.71-5\"></path><path d=\"m7.5 4.27 8.997 5.148\"></path>",
"Palette": "<path d=\"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z\"></path><circle cx=\"13.5\" cy=\"6.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"17.5\" cy=\"10.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"6.5\" cy=\"12.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"8.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"></circle>",
"PanelLeft": "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\"></rect><path d=\"M9 3v18\"></path>",
"Plus": "<path d=\"M5 12h14\"></path><path d=\"M12 5v14\"></path>",
"RadioTower": "<path d=\"M4.9 16.1C1 12.2 1 5.8 4.9 1.9\"></path><path d=\"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5\"></path><circle cx=\"12\" cy=\"9\" r=\"2\"></circle><path d=\"M16.2 4.8c2 2 2.26 5.11.8 7.47\"></path><path d=\"M19.1 1.9a9.96 9.96 0 0 1 0 14.1\"></path><path d=\"M9.5 18h5\"></path><path d=\"m8 22 4-11 4 11\"></path>",
"Rocket": "<path d=\"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5\"></path><path d=\"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09\"></path><path d=\"M9 12a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.4 22.4 0 0 1-4 2z\"></path><path d=\"M9 12H4s.55-3.03 2-4c1.62-1.08 5 .05 5 .05\"></path>",
"Search": "<path d=\"m21 21-4.34-4.34\"></path><circle cx=\"11\" cy=\"11\" r=\"8\"></circle>",
"Settings": "<path d=\"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915\"></path><circle cx=\"12\" cy=\"12\" r=\"3\"></circle>",
"ShieldCheck": "<path d=\"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z\"></path><path d=\"m9 12 2 2 4-4\"></path>",
"Sparkles": "<path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"></path><path d=\"M20 2v4\"></path><path d=\"M22 4h-4\"></path><circle cx=\"4\" cy=\"20\" r=\"2\"></circle>",
"Target": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><circle cx=\"12\" cy=\"12\" r=\"6\"></circle><circle cx=\"12\" cy=\"12\" r=\"2\"></circle>",
"Undo2": "<path d=\"M9 14 4 9l5-5\"></path><path d=\"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11\"></path>",
"Workflow": "<rect width=\"8\" height=\"8\" x=\"3\" y=\"3\" rx=\"2\"></rect><path d=\"M7 11v4a2 2 0 0 0 2 2h4\"></path><rect width=\"8\" height=\"8\" x=\"13\" y=\"13\" rx=\"2\"></rect>",
"X": "<path d=\"M18 6 6 18\"></path><path d=\"m6 6 12 12\"></path>"
}
export type LucideName = string
export const LucideIcon = defineComponent({
name: 'LucideIcon',
props: { name: { type: String as PropType<LucideName>, required: true }, size: { type: Number, default: 16 }, strokeWidth: { type: Number, default: 2 } },
setup: props => () => h('svg', {
xmlns: 'http://www.w3.org/2000/svg', width: props.size, height: props.size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
'stroke-width': props.strokeWidth, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true', innerHTML: ICONS[props.name] ?? '',
}),
})
const tasks = [
{ id: 'research', title: 'Collect references', detail: 'Find the right direction', icon: 'FileText', tone: 'amber' },
{ id: 'design', title: 'Explore the visual system', detail: 'Type, color, and composition', icon: 'Palette', tone: 'rose' },
{ id: 'build', title: 'Build the first prototype', detail: 'Make the interaction tangible', icon: 'Layers', tone: 'blue' },
{ id: 'ship', title: 'Ship something useful', detail: 'Polish the details and release', icon: 'Rocket', tone: 'emerald' },
]
</script>
<template>
<div class="studio">
<div class="head">
<div>
<p class="eyebrow">In the studio</p>
<h3 class="title">Make room for what matters.</h3>
</div>
<span class="count">04 tasks</span>
</div>
<SortableList :default-items="tasks" label="Studio priorities" :get-item-label="item => item.title">
<template #default="{ items }">
<SortableListGroup>
<SortableListItem v-for="(item, index) in items" :id="item.id" :key="item.id">
<SortableListHandle />
<SortableListItemContent>
<div class="row">
<span class="tile" :class="`tone-${item.tone}`"><LucideIcon :name="item.icon" :size="18" /></span>
<div class="copy">
<p class="name">{{ item.title }}</p>
<p class="detail">{{ item.detail }}</p>
</div>
<span class="index">{{ String(index + 1).padStart(2, '0') }}</span>
<LucideIcon name="Circle" :size="14" class="circle" />
</div>
</SortableListItemContent>
</SortableListItem>
</SortableListGroup>
<SortableListUndo />
</template>
</SortableList>
</div>
</template>
<style scoped>
.studio { width: 100%; max-width: 28rem; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; padding: 0 .25rem; }
.eyebrow { margin: 0 0 .25rem; font-size: 10px; font-weight: 500; letter-spacing: .18em; line-height: 1.5; text-transform: uppercase; color: var(--beui-muted-foreground); }
.title { margin: 0; padding: 0; border: 0; color: var(--beui-foreground); font-size: 1.125rem; font-weight: 500; line-height: 1.75rem; letter-spacing: -.025em; }
.count { flex: none; font-size: .75rem; line-height: 1rem; font-variant-numeric: tabular-nums; color: var(--beui-muted-foreground); }
.row { display: flex; width: 100%; align-items: center; gap: .75rem; }
.tile { display: flex; width: 2.5rem; height: 2.5rem; flex: none; align-items: center; justify-content: center; border-radius: .75rem; }
.copy { min-width: 0; flex: 1; }
.name { margin: 0; color: var(--beui-foreground); font-size: .875rem; font-weight: 500; line-height: 1.25rem; }
.detail { margin: .125rem 0 0; font-size: .75rem; line-height: 1rem; color: var(--beui-muted-foreground); }
.index { font-size: 10px; line-height: 1.5; font-variant-numeric: tabular-nums; color: var(--beui-muted-foreground); }
.circle { color: var(--beui-border); flex: none; }
.tone-amber { background: color-mix(in oklab, oklch(76.9% .188 70.08) 10%, transparent); color: oklch(66.6% .179 58.318); }
.tone-rose { background: color-mix(in oklab, oklch(64.5% .246 16.439) 10%, transparent); color: oklch(58.6% .253 17.585); }
.tone-blue { background: color-mix(in oklab, oklch(62.3% .214 259.815) 10%, transparent); color: oklch(54.6% .245 262.881); }
.tone-emerald { background: color-mix(in oklab, oklch(69.6% .17 162.48) 10%, transparent); color: oklch(59.6% .145 163.225); }
:global(.dark .tone-amber) { color: #fbbf24; }
:global(.dark .tone-rose) { color: #fb7185; }
:global(.dark .tone-blue) { color: #60a5fa; }
:global(.dark .tone-emerald) { color: #34d399; }
</style><script lang="ts">
/** English defaults. Override per instance with `labels`. */
export const sortableStackMessages = {
label: 'Sortable items',
instructions:
'Drag a handle to reorder. With a handle focused, use Up and Down to move, Home and End to move to the edges. Space lifts a row and drops it again, and Escape cancels the lift.',
moved: '{item} moved to position {position} of {total}.',
restored: 'Previous order restored.',
reorder: 'Reorder {item}',
undo: 'Undo reorder',
}
export type SortableStackMessages = typeof sortableStackMessages
</script>
<script setup lang="ts" generic="Row extends { id: string; title: string; detail?: string }">
import { ReorderGroup, ReorderItem, useDragControls } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, nextTick, shallowRef, useId, useTemplateRef, watch } from 'vue'
import { layoutSpring } from '../core/motion'
type MoveDirection = -1 | 1 | 'first' | 'last'
const props = withDefaults(defineProps<{
/** Accessible name of the list. */
label?: string
/** Width/box helpers for the root wrapper. */
className?: string
/** Extra classes for every row. */
itemClassName?: string
disabled?: boolean
/** Show the automatic undo button under the list. */
showUndo?: boolean
/** Screen-reader label of a row; the visible row is up to the slot. */
getItemLabel?: (item: Row) => string
labels?: Partial<SortableStackMessages>
}>(), { showUndo: true })
const items = defineModel<Row[]>({ required: true })
const emit = defineEmits<{ itemsChange: [items: Row[]] }>()
defineSlots<{
default?: (props: { item: Row; index: number; dragging: boolean }) => unknown
handle?: (props: { item: Row; index: number }) => unknown
undo?: () => unknown
}>()
const reduce = useReducedMotion()
const t = computed(() => ({ ...sortableStackMessages, ...props.labels }))
const ariaLabel = computed(() => props.label ?? t.value.label)
const instructionsId = useId()
const root = useTemplateRef<HTMLDivElement>('root')
// Drag lift and the frozen transition under reduced motion, straight from the
// original `whileDrag` / `{ duration: 0 }` pair.
const DRAG_LIFT = { scale: 1.025 } as const
const INSTANT = { duration: 0 } as const
// `items` is the parent's value; `live` is the array every action reads from,
// so a reorder still resolves correctly before the parent's prop round-trips.
const live = shallowRef<Row[]>(items.value)
const ids = computed(() => live.value.map(item => item.id))
const announcement = shallowRef('')
const previous = shallowRef<string[] | null>(null)
const dragging = shallowRef<string | null>(null)
const lifted = shallowRef<string | null>(null)
let dragStart: string[] | null = null
let liftStart: string[] | null = null
watch(items, next => { live.value = next })
function labelOf(item: Row) {
return props.getItemLabel?.(item) ?? item.title
}
function fill(template: string, values: Record<string, string | number>) {
return template.replace(/\{(\w+)\}/g, (_, key: string) => String(values[key] ?? ''))
}
function announceMove(item: Row, index: number, total: number) {
announcement.value = fill(t.value.moved, { item: labelOf(item), position: index + 1, total })
}
function change(next: Row[]) {
live.value = next
items.value = next
emit('itemsChange', next)
}
// Consumers can remove rows during a drag. Only publish a full permutation.
function reorder(nextIds: string[]) {
if (props.disabled) return
const byId = new Map(live.value.map(item => [item.id, item] as const))
const next = nextIds.flatMap(id => {
const item = byId.get(id)
return item ? [item] : []
})
if (next.length === live.value.length && new Set(nextIds).size === next.length) change(next)
}
function move(id: string, direction: MoveDirection) {
const current = live.value
const from = current.findIndex(item => item.id === id)
const to = direction === 'first'
? 0
: direction === 'last'
? current.length - 1
: from + direction
if (props.disabled || from < 0 || to < 0 || to >= current.length || from === to) return
const next = [...current]
const [item] = next.splice(from, 1)
next.splice(to, 0, item!)
previous.value = current.map(row => row.id)
change(next)
announceMove(item!, to, current.length)
}
// A removed row makes the stored order meaningless; drop it rather than let
// rows that come back revive it. A lift on a row that went away also ends.
watch(ids, list => {
const before = previous.value
if (before && (before.length !== list.length || before.some(id => !list.includes(id))))
previous.value = null
if (lifted.value !== null && !list.includes(lifted.value)) {
lifted.value = null
liftStart = null
}
})
const canUndo = computed(() => {
const before = previous.value
if (!before || before.length !== ids.value.length) return false
return before.every(id => ids.value.includes(id)) && before.some((id, index) => id !== ids.value[index])
})
function focusHandle(id: string) {
nextTick(() => {
root.value
?.querySelector<HTMLButtonElement>(`button[data-sortable-id="${CSS.escape(id)}"]`)
?.focus({ preventScroll: true })
})
}
function undo() {
const before = previous.value
if (props.disabled || !before || !canUndo.value) return
const target = before.find((id, index) => id !== ids.value[index]) ?? before[0]
previous.value = null
reorder(before)
announcement.value = t.value.restored
if (target) focusHandle(target)
}
function beginDrag(id: string) {
dragging.value = id
dragStart = live.value.map(item => item.id)
}
function finishDrag(id: string) {
const before = dragStart
dragStart = null
dragging.value = null
const current = live.value
const index = current.findIndex(item => item.id === id)
const item = current[index]
if (item && before?.some((oldId, at) => oldId !== current[at]?.id)) {
previous.value = before
announceMove(item, index, current.length)
}
}
// motion-v's `useDragControls` is a plain factory (one instance per handle),
// so an id-keyed cache is enough; it is stable for the row's lifetime.
const controlsById = new Map<string, ReturnType<typeof useDragControls>>()
function controlsFor(id: string) {
let controls = controlsById.get(id)
if (!controls) {
controls = useDragControls()
controlsById.set(id, controls)
}
return controls
}
watch(ids, list => {
for (const id of controlsById.keys()) if (!list.includes(id)) controlsById.delete(id)
})
function onHandlePointerDown(event: PointerEvent, id: string) {
if (event.defaultPrevented || props.disabled || event.button !== 0) return
;(event.currentTarget as HTMLButtonElement | null)?.focus({ preventScroll: true })
controlsFor(id).start(event)
}
// Space lifts a row and Escape puts it back where it started (the documented
// Vue behaviour); arrows, Home and End move immediately like the original.
function lift(id: string) {
if (lifted.value === id) {
lifted.value = null
liftStart = null
return
}
lifted.value = id
liftStart = live.value.map(item => item.id)
}
function cancelLift() {
const before = liftStart
const id = lifted.value
lifted.value = null
liftStart = null
if (!before || !id) return
reorder(before)
announcement.value = t.value.restored
focusHandle(id)
}
function onHandleKeydown(event: KeyboardEvent, id: string) {
if (event.defaultPrevented || props.disabled || event.altKey || event.ctrlKey || event.metaKey) return
if (event.key === ' ') {
event.preventDefault()
if (!event.repeat) lift(id)
return
}
if (event.key === 'Escape' && lifted.value === id) {
event.preventDefault()
cancelLift()
return
}
const direction: MoveDirection | null =
event.key === 'ArrowUp'
? -1
: event.key === 'ArrowDown'
? 1
: event.key === 'Home'
? 'first'
: event.key === 'End'
? 'last'
: null
if (direction === null) return
event.preventDefault()
move(id, direction)
// Reordering detaches and reattaches the row, which blurs its handle in a
// real browser; the row keeps the focus it had before the key.
focusHandle(id)
}
</script>
<template>
<div ref="root" class="be-sortable" :class="className">
<p :id="instructionsId" class="be-sortable-sr">{{ t.instructions }}</p>
<ReorderGroup
axis="y" :values="ids" :aria-label="ariaLabel" class="be-sortable-group"
@update:values="reorder">
<ReorderItem
v-for="(item, index) in live" :key="item.id" :value="item.id" tabindex="-1"
layout="position" :drag-listener="false" :drag-controls="controlsFor(item.id)"
:animate="reduce ? undefined : { scale: lifted === item.id ? DRAG_LIFT.scale : 1 }"
:transition="reduce ? INSTANT : layoutSpring" :while-drag="reduce ? undefined : DRAG_LIFT"
:aria-posinset="index + 1" :aria-setsize="live.length"
class="be-sortable-item"
:class="[itemClassName, (dragging === item.id || lifted === item.id) && 'be-sortable-dragging']"
@drag-start="beginDrag(item.id)"
@drag-end="finishDrag(item.id)">
<button
type="button" class="be-sortable-handle" :disabled="disabled" :data-sortable-id="item.id"
:aria-label="fill(t.reorder, { item: labelOf(item) })" :aria-describedby="instructionsId"
:aria-pressed="lifted === item.id ? true : undefined"
:style="{ cursor: disabled ? undefined : dragging === item.id ? 'grabbing' : 'grab' }"
@pointerdown="onHandlePointerDown($event, item.id)"
@keydown="onHandleKeydown($event, item.id)">
<slot name="handle" :item="item" :index="index">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="9" cy="12" r="1" /><circle cx="9" cy="5" r="1" /><circle cx="9" cy="19" r="1" />
<circle cx="15" cy="12" r="1" /><circle cx="15" cy="5" r="1" /><circle cx="15" cy="19" r="1" />
</svg>
</slot>
</button>
<div class="be-sortable-content">
<slot :item="item" :index="index" :dragging="dragging === item.id || lifted === item.id">
<div class="be-sortable-default">
<div class="be-sortable-copy">
<strong class="be-sortable-title">{{ item.title }}</strong>
<small v-if="item.detail" class="be-sortable-detail">{{ item.detail }}</small>
</div>
<span class="be-sortable-position" aria-hidden="true">{{ String(index + 1).padStart(2, '0') }}</span>
</div>
</slot>
</div>
</ReorderItem>
</ReorderGroup>
<button
v-if="showUndo" type="button" class="be-sortable-undo" :disabled="disabled || !canUndo"
@click="undo">
<slot name="undo">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9 14 4 9l5-5" /><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11" />
</svg>
{{ t.undo }}
</slot>
</button>
<span role="status" aria-live="polite" class="be-sortable-sr">{{ announcement }}</span>
</div>
</template>
<style scoped>
.be-sortable { width: 100%; max-width: 28rem; color: var(--beui-foreground); }
.be-sortable-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.be-sortable-group { margin: 0; padding: 0; list-style: none; }
.be-sortable-item { position: relative; display: flex; align-items: center; gap: .75rem; margin: 0; padding: .75rem; border: 1px solid var(--beui-border); border-radius: 1rem; background: var(--beui-background); list-style: none; }
/* Tailwind `space-y-2`: siblings only, so the first row keeps no top margin. */
.be-sortable-item + .be-sortable-item { margin-top: .5rem; }
.be-sortable-dragging { box-shadow: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1); }
.be-sortable-handle { display: flex; width: 2.25rem; height: 2.25rem; flex: none; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: .5rem; background: transparent; color: var(--beui-muted-foreground); font: inherit; touch-action: none; }
.be-sortable-handle:hover { background: var(--beui-muted); color: var(--beui-foreground); }
.be-sortable-handle:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--beui-ring); }
.be-sortable-handle:disabled { cursor: not-allowed; opacity: .4; }
.be-sortable-handle svg { width: 18px; height: 18px; }
.be-sortable-content { display: flex; min-width: 0; flex: 1; align-items: center; gap: .75rem; }
.be-sortable-default { display: flex; width: 100%; min-width: 0; align-items: center; gap: .75rem; }
.be-sortable-copy { min-width: 0; flex: 1; }
.be-sortable-title { display: block; font-size: .875rem; font-weight: 500; }
.be-sortable-detail { display: block; margin-top: .125rem; color: var(--beui-muted-foreground); font-size: .75rem; }
.be-sortable-position { margin-inline-start: auto; color: var(--beui-muted-foreground); font-size: .625rem; font-variant-numeric: tabular-nums; }
.be-sortable-undo { display: inline-flex; align-items: center; gap: .375rem; margin-top: 1rem; padding: .25rem .5rem; border: 0; border-radius: .375rem; background: transparent; color: var(--beui-muted-foreground); font: inherit; font-size: .75rem; transition: color .15s ease; }
.be-sortable-undo:hover { color: var(--beui-foreground); }
.be-sortable-undo:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--beui-ring); }
.be-sortable-undo:disabled { opacity: .4; }
.be-sortable-undo svg { width: 13px; height: 13px; }
</style>Install
Add it with your package manager, or copy the source manually.
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/sortable-stack$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import SortableStack from '@/components/beui/layout/SortableStack.vue'
import '@/components/beui/styles.css'API Reference
SortableList
v-model:items?Row[]Rows in their current order, `v-model:items`.
—defaultItems?Row[]Starting rows when `v-model:items` is not bound.
[]#renderItem?slotRow contents for the convenience composition when the default slot is omitted.
—getItemLabel(item: Row) => stringScreen-reader label of a row; the visible row is up to the slot.
—#default?slotCompose the parts; receives the items in their current order. Omit it to use `renderItem`.
—label?stringAccessible name of the list.
—disabled?booleanfalseshowUndo?booleanShow the automatic undo button in the convenience composition.
trueclass?string—itemClassName?stringExtra classes for every row.
—labels?Partial<SortableListMessages>Override any built-in string.
—SortableListGroup
class?string—#default?slot—SortableListItem
idstringIdentity of an item supplied to the root. Use it as the `v-for` key too.
—class?string—#default?slot—SortableListHandle
class?string—disabled?boolean—#default?slotReplaces the grip icon.
—SortableListItemContent
class?string—#default?slot—SortableListUndo
class?string—disabled?boolean—#default?slotReplaces the icon and label.
—Related components
Date Range Picker
Composable date range picker with root, trigger, popover content, calendar, header, grid, summary, footer, clear and preset parts, plus a shared state hook. Compact inline and dropdown compositions, direct month and year selection, and full keyboard navigation.
Animated Color Selector
Composable color swatches with a spring-gliding selection ring, press feedback, native radio keyboard navigation, and controlled or uncontrolled state.
Image Viewer
A composable Vue image viewer for galleries and attachment previews, with animated lightbox variants, custom thumbnails and controls, swipe and keyboard navigation, zoom and pan, accessible focus management, and controlled or uncontrolled selection.
Updated