Skip to content

hooks/useTabDrag

import { … } from 'zidane-ui'ui/src/hooks/useTabDrag.ts

Functions#

moveIdFunction#

Moves id by delta slots (keyboard reorder), clamped at the ends.

TypeScript
function moveId(ids: readonly string[], id: string, delta: number): string[]
Parameters
NameTypeDescription
idsreadonly string[]

The current order; not mutated.

idstring

The tab to move; a copy of ids comes back unchanged when it is absent.

deltanumber

Slots to move: negative is left, positive right.

string[]

ui/src/hooks/useTabDrag.ts:80

useTabDragFunction#

Tracks one tab strip's drag: what to draw, the held tab, and the handlers to pass to Reorder.Group and each Reorder.Item.

TypeScript
function useTabDrag(
  ids: readonly string[],
  commit: (order: readonly string[]) => void,
): { bounds: TabDragBounds | undefined; dragging: string | null; onDragEnd: () => void; onDragStart: (id: string) => void; onPointerDown: (e: PointerEvent<HTMLElement>) => void; onReorder: (next: string[]) => void; shown: string[]; wasDragged: () => boolean }
Parameters
NameTypeDescription
idsreadonly string[]

The owner's order, drawn while nothing is held.

commit(order: readonly string[]) => void

Receives the new order once, on drop.

{ bounds: TabDragBounds | undefined; dragging: string | null; onDragEnd: () => void; onDragStart: (id: string) => void; onPointerDown: (e: PointerEvent<HTMLElement>) => void; onReorder: (next: string[]) => void; shown: string[]; wasDragged: () => boolean }

ui/src/hooks/useTabDrag.ts:24

Interfaces#

TabDragBoundsInterface#

How far the held tab may travel (dragConstraints): the strip's edges, relative to the tab.

TypeScript
interface TabDragBounds
TabDragBounds properties
NameTypeDescription
leftnumber

How far left the held tab may go, in px from where the press started (zero or negative).

rightnumber

How far right it may go, in px from where the press started (zero or positive).

ui/src/hooks/useTabDrag.ts:10