Display
Sortable List
A sortable list: native drag and drop plus arrow buttons — the only route available from a keyboard.
- sortable
- drag
- list
- a11y
Preview
1440pxHost theme
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/sortable-001?lang=en
Section order
Перетащите строку или используйте кнопки со стрелками
- 1Hero с одним действием
- 2Три преимущества
- 3Тарифы
- 4Отзывы
- 5Форма заявки
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "sortable-001" (Sortable List) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/sortable-001.json
Registry item: https://vibeui.ru/r/sortable-001.json
Installs to: components/vibeui/sortable-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A sortable list: native drag and drop plus arrow buttons — the only route available from a keyboard.
A drag-to-reorder list: row numbers, a grip, move buttons and an insertion line. Zero dependencies, one file.
## 3. How to use it
import { Sortable001 } from "@/components/vibeui/sortable-001"
<Sortable001 items={["Hero", "Pricing"]} onChange={save} />
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-sortable-001-* palette — do not swap it for your theme tokens
- the move buttons: dragging is fundamentally unavailable from a keyboard
- the position inside the button label — "now 3 of 5" is audible, order is not
- the insertion line instead of highlighting the whole row
- native HTML5 drag and drop: no library is needed here
- the row numbering — after a move it confirms the result
## 6. You may change
- the items array and the title
- the onChange handler
- the accent through the accent prop
- the block width
## 7. Rules
- Dragging does not work on touch screens without emulation — the buttons cover that case.
- Order lives inside the component: persisting it is the caller's job.
- For moving between columns use kanban-001: this is a single column.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/sortable-001.jsonhttps://vibeui.ru/r/sortable-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-sortable-001-*. Клиентский: "use client" ради порядка. Перенос сделан на HTML5 drag and drop, поэтому библиотека не нужна; кнопки «выше» и «ниже» дают тот же результат с клавиатуры и называют текущую позицию строки вслух.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties, DragEvent } from "react"
export type Sortable001Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
title?: string
hint?: string
items?: string[]
onChange?: (items: string[]) => void
accent?: string
}
// Идея компонента: список с ручной сортировкой. Перетаскивание сделано на
// нативном HTML5 drag and drop, поэтому библиотека не нужна. Но мышью владеют
// не все, а drag с клавиатуры не работает в принципе — поэтому у каждой строки
// есть кнопки «выше» и «ниже», и они не дублирующая роскошь, а единственный
// доступный путь. Порядок объявляется вслух: строка называет свой номер из N.
const STYLES = `
:where([data-vibeui-block="sortable-001"]){
--vibeui-sortable-001-bg:oklch(1 0 0);
--vibeui-sortable-001-fg:oklch(0.24 0.014 265);
--vibeui-sortable-001-muted:oklch(0.56 0.014 265);
--vibeui-sortable-001-border:oklch(0.9 0.006 265);
--vibeui-sortable-001-hover:oklch(0.55 0.02 265 / 7%);
--vibeui-sortable-001-accent:oklch(0.55 0.2 262);
--vibeui-sortable-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="sortable-001"]{
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-sortable-001-bg);
border:1px solid var(--vibeui-sortable-001-border);border-radius:0.875rem;
font-family:var(--vibeui-sortable-001-font);color:var(--vibeui-sortable-001-fg);
}
[data-vibeui-block="sortable-001"] *{box-sizing:border-box}
[data-vibeui-block="sortable-001"] h3{margin:0 0 0.125rem;font-size:0.875rem;font-weight:650}
[data-vibeui-block="sortable-001"] [data-part="hint"]{margin:0 0 0.625rem;font-size:0.75rem;color:var(--vibeui-sortable-001-muted)}
[data-vibeui-block="sortable-001"] ol{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:0.375rem}
[data-vibeui-block="sortable-001"] li{
display:flex;align-items:center;gap:0.5rem;
padding:0.4375rem 0.5rem;border-radius:0.625rem;
border:1px solid var(--vibeui-sortable-001-border);
background:var(--vibeui-sortable-001-bg);font-size:0.8125rem;
}
[data-vibeui-block="sortable-001"] li[data-dragging="true"]{opacity:.45}
/* Место вставки — линия сверху строки, а не подсветка всей строки целиком. */
[data-vibeui-block="sortable-001"] li[data-over="true"]{box-shadow:inset 0 2px 0 var(--vibeui-sortable-001-accent)}
[data-vibeui-block="sortable-001"] [data-part="grip"]{
flex:none;cursor:grab;display:flex;flex-direction:column;gap:2px;padding:0.25rem;
}
[data-vibeui-block="sortable-001"] [data-part="grip"] span{
display:block;width:0.75rem;height:2px;border-radius:1px;
background:var(--vibeui-sortable-001-muted);opacity:.6;
}
[data-vibeui-block="sortable-001"] [data-part="index"]{
flex:none;width:1.25rem;text-align:right;
font-size:0.75rem;color:var(--vibeui-sortable-001-muted);font-variant-numeric:tabular-nums;
}
[data-vibeui-block="sortable-001"] [data-part="text"]{flex:1 1 auto;min-width:0}
/* Кнопки — не дубль перетаскивания, а единственный путь с клавиатуры. */
[data-vibeui-block="sortable-001"] [data-part="move"]{
appearance:none;border:0;background:none;cursor:pointer;flex:none;
width:1.5rem;height:1.5rem;border-radius:0.375rem;
color:var(--vibeui-sortable-001-muted);font:inherit;font-size:0.6875rem;line-height:1;
}
[data-vibeui-block="sortable-001"] [data-part="move"]:hover:not(:disabled){background:var(--vibeui-sortable-001-hover);color:var(--vibeui-sortable-001-fg)}
[data-vibeui-block="sortable-001"] [data-part="move"]:disabled{opacity:.35;cursor:default}
[data-vibeui-block="sortable-001"] [data-part="move"]:focus-visible{outline:2px solid var(--vibeui-sortable-001-accent);outline-offset:1px}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="sortable-001"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_ITEMS = [
"Hero с одним действием",
"Три преимущества",
"Тарифы",
"Отзывы",
"Форма заявки",
]
/**
* Список с ручной сортировкой: нативный drag и кнопки для клавиатуры.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Sortable001({
title = "Порядок секций",
hint = "Перетащите строку или используйте кнопки со стрелками",
items = DEFAULT_ITEMS,
onChange,
accent,
className,
style,
...props
}: Sortable001Props) {
const [order, setOrder] = useState(items)
const [dragged, setDragged] = useState<string | null>(null)
const [over, setOver] = useState<string | null>(null)
const apply = (next: string[]) => {
setOrder(next)
onChange?.(next)
}
const move = (from: number, to: number) => {
if (to < 0 || to >= order.length) return
const next = [...order]
const [row] = next.splice(from, 1)
next.splice(to, 0, row)
apply(next)
}
const drop = (event: DragEvent<HTMLLIElement>, target: string) => {
event.preventDefault()
setOver(null)
if (!dragged || dragged === target) return
move(order.indexOf(dragged), order.indexOf(target))
setDragged(null)
}
const palette = {
...(accent ? { "--vibeui-sortable-001-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-sortable-001" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="sortable-001"
className={className}
style={palette}
>
<h3>{title}</h3>
<p data-part="hint">{hint}</p>
<ol>
{order.map((row, index) => (
<li
key={row}
draggable
data-dragging={row === dragged}
data-over={row === over}
onDragStart={() => setDragged(row)}
onDragEnd={() => {
setDragged(null)
setOver(null)
}}
onDragOver={(event) => {
event.preventDefault()
setOver(row)
}}
onDrop={(event) => drop(event, row)}
>
<span data-part="grip" aria-hidden="true">
<span />
<span />
<span />
</span>
<span data-part="index">{index + 1}</span>
<span data-part="text">{row}</span>
<button
type="button"
data-part="move"
disabled={index === 0}
aria-label={`Поднять «${row}», сейчас ${index + 1} из ${order.length}`}
onClick={() => move(index, index - 1)}
>
▲
</button>
<button
type="button"
data-part="move"
disabled={index === order.length - 1}
aria-label={`Опустить «${row}», сейчас ${index + 1} из ${order.length}`}
onClick={() => move(index, index + 1)}
>
▼
</button>
</li>
))}
</ol>
</div>
</>
)
}