Bounded
dnd-grid/bounded-exampleFreeComponent
Keep items within grid bounds.
Install it
npx shadcn@latest add https://dnd-grid.com/r/bounded-example.jsonSource
1"use client";23import { DndGrid, type Layout } from "@dnd-grid/react";4import { useState } from "react";56const initialLayout: Layout = [0, 1, 2, 3, 4, 5].map((i) => ({7 id: i.toString(),8 x: (i * 2) % 12,9 y: Math.floor(i / 6) * 2,10 w: 2,11 h: 2,12}));1314export function BoundedExample() {15 const [layout, setLayout] = useState<Layout>(initialLayout);1617 return (18 <DndGrid19 bounded20 cols={12}21 layout={layout}22 onLayoutChange={setLayout}23 rowHeight={50}24 >25 {layout.map((item) => (26 <div className="grid-item" key={item.id}>27 {item.id}28 </div>29 ))}30 </DndGrid>31 );32}
What it pulls in
npm packages
Files it writes
More from dnd-grid
All 19 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Allow overlapallow-overlap-example | dnd-grid | Components | Free | 3 deps | |
| Aspect ratio constraintsaspect-ratio-constraints-example | dnd-grid | Components | Free | 3 deps | |
| Basic examplebasic-example | dnd-grid | Components | Free | 3 deps | |
| Compactor showcasecompactor-showcase-example | dnd-grid | Components | Free | 3 deps | |
| Compositioncomposition-example | dnd-grid | Components | Free | 3 deps | |
| Constraintsconstraints-example | dnd-grid | Components | Free | 3 deps | |
| Drag from outsidedrag-from-outside-example | dnd-grid | Components | Free | 3 deps | |
| Dynamic add/removedynamic-add-remove-example | dnd-grid | Components | Free | 3 deps |
