UNPKG

@mitcsutt/kiln-dnd

Version:

Kiln drag and drop: sortable lists, boards, drop zones and grid layouts with one keyboard model and one announcer, rendered through kiln-ui

42 lines (41 loc) • 2.09 kB
import type { ReactNode } from 'react'; import type { DragInput, ListOrientation } from '../../core/controller.js'; import type { DragHandleAttributes } from '../../core/useDragSource.js'; import { type UseSortableOptions } from '../../hooks/useSortable.js'; /** The props `SortableItem` hands its element: kiln-dnd's look, and the drag props without a handle. */ export interface SortableItemAttributes extends Partial<DragHandleAttributes> { className: string; 'data-orientation': ListOrientation; 'data-handle'?: ''; 'data-dragging'?: DragInput; 'data-drop-edge'?: 'before' | 'after'; 'aria-disabled'?: true; } /** What `SortableItem` passes to the function that renders its element. */ export interface SortableItemRender { /** Put on the item's element. */ ref: (element: HTMLElement | null) => void; /** Spread onto the same element. Merge your own `className` with `props.className`. */ props: SortableItemAttributes; /** Whether this item is being dragged. */ isDragging: boolean; } export interface SortableItemProps extends UseSortableOptions { /** The list's direction, for where the drop line is drawn. Default `vertical`. */ orientation?: ListOrientation; /** Renders the item's element, with `ref` and `props` on it. */ children: (item: SortableItemRender) => ReactNode; } /** * One item of a sortable list you build from your own elements, with `Sortable`'s look. * * @remarks * `SortableItem` is `useSortable` with what `Sortable` draws around each row: the drop * line, the lifted look, and the context a `DragHandle` inside it needs. Use it when the * items can't be list items, such as table rows or cards in your own layout. Put `ref` and * `props` on the item's element, inside a `Dnd` that applies the move in `onDragEnd`. * * With `handle`, put a `DragHandle` inside the item; without it, the whole element is the * handle and takes focus. */ export declare function SortableItem({ orientation, handle, disabled, label, children, ...options }: SortableItemProps): import("react").JSX.Element;