Layout item
Layout item type reference.
Layout type
Layout<TData> is an array of LayoutItem<TData> objects:
import { type Layout } from "@dnd-grid/react";
type CardData = { kind: "chart" | "text" };
const layout: Layout<CardData> = [
{ id: "a", x: 0, y: 0, w: 2, h: 2, data: { kind: "chart" } },
{ id: "b", x: 2, y: 0, w: 2, h: 2, data: { kind: "text" } },
];Properties
Required
idstringrequiredUnique id. Must match the child's key.
xnumberrequiredX position in grid units (0-based).
ynumberrequiredY position in grid units (0-based).
wnumberrequiredWidth in grid units.
hnumberrequiredHeight in grid units.
Optional
minWnumberMinimum width.
maxWnumberMaximum width.
minHnumberMinimum height.
maxHnumberMaximum height.
constraintsLayoutConstraint[]Per-item drag and resize constraints.
staticbooleanDefault: falseIf true, the item is locked.
draggablebooleanOverride grid drag setting.
resizablebooleanOverride grid resize setting.
boundedbooleanOverride grid bounded setting.
resizeHandlesResizeHandleAxis[]Override grid resize handles.
dataTDataOptional typed metadata for the item.
Examples
With size constraints
const layout: Layout = [
{
id: "constrained",
x: 0, y: 0, w: 4, h: 3,
minW: 2, maxW: 8,
minH: 2, maxH: 6,
},
];