BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/dnd-grid/constraints-example

Constraints

dnd-grid/constraints-example
FreeComponent

Plug in constraints and custom rules.

Install it

npx shadcn@latest add https://dnd-grid.com/r/constraints-example.json

Source

examples/dnd-grid-constraints-example.tsxdnd-grid.com/r/constraints-example.json
1"use client";
2
3import {
4 DndGrid,
5 defaultConstraints,
6 type Layout,
7 type LayoutConstraint,
8 snapToGrid,
9} from "@dnd-grid/react";
10import { useState } from "react";
11
12const topBandConstraint: LayoutConstraint = {
13 name: "topBand(4)",
14 constrainPosition(item, x, y) {
15 const maxY = Math.max(0, 4 - item.h);
16 return { x, y: Math.min(y, maxY) };
17 },
18};
19
20const gridConstraints: LayoutConstraint[] = [
21 ...defaultConstraints,
22 snapToGrid(2, 1),
23];
24
25const initialLayout: Layout = [
26 { id: "snap", x: 0, y: 0, w: 3, h: 2 },
27 {
28 id: "limits",
29 x: 3,
30 y: 0,
31 w: 3,
32 h: 2,
33 minW: 2,
34 maxW: 5,
35 minH: 2,
36 maxH: 4,
37 },
38 {
39 id: "band",
40 x: 6,
41 y: 0,
42 w: 3,
43 h: 2,
44 constraints: [topBandConstraint],
45 },
46];
47
48export function ConstraintsExample() {
49 const [layout, setLayout] = useState<Layout>(initialLayout);
50
51 return (
52 <DndGrid
53 cols={12}
54 constraints={gridConstraints}
55 layout={layout}
56 onLayoutChange={setLayout}
57 rowHeight={50}
58 >
59 {layout.map((item) => (
60 <div className="grid-item" key={item.id}>
61 {item.id}
62 </div>
63 ))}
64 </DndGrid>
65 );
66}

What it pulls in

npm packages

  • @dnd-grid/react
  • react-draggable
  • react-resizable

Files it writes

  • examples/dnd-grid-constraints-example.tsx

Facts

Registry
dnd-grid
Type
registry:component
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-01
Last confirmed
yesterday

Go to the source

dnd-grid.com mblode/dnd-grid on GitHub Raw registry item This item as JSON

More from dnd-grid

All 19 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Allow overlapallow-overlap-examplednd-gridComponentsFree3 deps
Aspect ratio constraintsaspect-ratio-constraints-examplednd-gridComponentsFree3 deps
Basic examplebasic-examplednd-gridComponentsFree3 deps
Boundedbounded-examplednd-gridComponentsFree3 deps
Compactor showcasecompactor-showcase-examplednd-gridComponentsFree3 deps
Compositioncomposition-examplednd-gridComponentsFree3 deps
Drag from outsidedrag-from-outside-examplednd-gridComponentsFree3 deps
Dynamic add/removedynamic-add-remove-examplednd-gridComponentsFree3 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex