@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
44 lines (43 loc) • 1.77 kB
TypeScript
import type { DndItem, ListOrientation } from '../core/controller.js';
/** Options for {@link useDroppable}. */
export interface UseDroppableOptions {
/** Unique within the `Dnd` scope. */
id: string;
/** The zone's name, as announcements say it ("Archive"). */
label: string;
/** Which items it takes. Default: every item in the scope. */
accept?: (item: DndItem) => boolean;
/** Anything you want back in `onDragEnd`'s target. */
data?: unknown;
/** Stops it taking drops. */
disabled?: boolean;
/** Called when an item is dropped here. */
onDrop?: (item: DndItem) => void;
/**
* Makes this the container of a sortable list (the `list` its `useSortable` items
* name) instead of a drop zone: an item dropped on it, or moved into it by keyboard
* while it's empty, joins the list.
*/
list?: string;
/** For a list container: the list's direction. Default `vertical`. */
orientation?: ListOrientation;
}
/** What {@link useDroppable} returns. */
export interface UseDroppableResult {
/** Put on the drop target. */
ref: (element: HTMLElement | null) => void;
/** Whether the dragged item would land here if dropped now. */
isOver: boolean;
/** Whether an item this target accepts is being dragged. */
isActive: boolean;
}
/**
* Makes an element a place to drop draggable items.
*
* @remarks
* `useDroppable` is the primitive under `DropZone`. While an item it accepts is dragged,
* `isActive` is true; `isOver` is true when the item would land here. A keyboard user
* reaches drop zones with the arrow keys, in document order, and hears each zone's
* `label`.
*/
export declare function useDroppable(options: UseDroppableOptions): UseDroppableResult;