@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
54 lines (53 loc) • 2.75 kB
TypeScript
import { type ReactNode } from 'react';
import { type DragCancelEvent, type DragEndEvent, type DragOverEvent, type DragStartEvent } from '../../core/controller.js';
import type { EngineProps } from '../../core/engineTypes.js';
import { type DndAnnouncements } from '../../core/messages.js';
export interface DndProps {
children?: ReactNode;
/**
* Replace any of the words kiln-dnd says: the handle instructions, the drag handle's
* name and every announcement. The rest stay English.
*/
announcements?: Partial<DndAnnouncements>;
/** Called when an item is picked up, by pointer or keyboard. */
onDragStart?: (event: DragStartEvent) => void;
/** Called whenever the place an item would land changes. */
onDragOver?: (event: DragOverEvent) => void;
/**
* Called once when an item is dropped. Apply the move here. A sortable item only ends here
* when the drop moves it; a draggable always does, with `target: null` over no zone.
*/
onDragEnd?: (event: DragEndEvent) => void;
/**
* Called when a drag is cancelled: Escape, focus leaving the handle or a cancelled pointer
* drag. A sortable item dropped where nothing moves (its own slot, or over nothing) lands
* here too, instead of in `onDragEnd`.
*/
onDragCancel?: (event: DragCancelEvent) => void;
/**
* Options passed straight to the drag engine. An escape hatch outside semver: the
* engine and its options can change in any release. Read when the scope mounts.
*/
engineProps?: EngineProps;
}
/**
* The scope for draggable items and the places they drop: one keyboard model, one
* announcer and one drag engine for everything inside it.
*
* @remarks
* `Dnd` wraps the items made with `useDraggable`, `useSortable`, `Draggable` and
* `DropZone`, and hears every drop in `onDragEnd`. `Sortable`, `Board` and `GridLayout`
* bring their own, so you only need `Dnd` for drop zones or your own sortable markup.
*
* It renders no element of its own, just a live region for announcements and the
* instructions each drag handle points to. On the server and before hydration, items
* render as plain markup; the drag engine loads in the browser once the scope mounts, and
* keyboard dragging works as soon as the page is interactive.
*
* ## Keyboard
*
* Space or Enter on a handle picks the item up. The arrow keys move it, Space or Enter
* drops it, and Escape (or leaving the handle) cancels and puts it back. Focus stays on
* the handle throughout, and returns to it after a drop moves the item.
*/
export declare function Dnd({ children, announcements, onDragStart, onDragOver, onDragEnd, onDragCancel, engineProps, }: DndProps): import("react").JSX.Element;