Scale
dnd-grid/scale-exampleFreeComponent
Keep drag math correct when scaling the grid.
Install it
npx shadcn@latest add https://dnd-grid.com/r/scale-example.jsonSource
1"use client";23import { DndGrid, type Layout } from "@dnd-grid/react";4import { type CSSProperties, useState } from "react";56const scaleOptions = [0.75, 1, 1.25];78const initialLayout: Layout = [9 { id: "a", x: 0, y: 0, w: 3, h: 2 },10 { id: "b", x: 3, y: 0, w: 3, h: 2 },11 { id: "c", x: 6, y: 0, w: 3, h: 2 },12 { id: "d", x: 0, y: 2, w: 6, h: 2 },13 { id: "e", x: 6, y: 2, w: 3, h: 3 },14];1516export function ScaleExample() {17 const [layout, setLayout] = useState<Layout>(initialLayout);18 const [scale, setScale] = useState(1);1920 const scaledStyle: CSSProperties & Record<"--dnd-grid-scale", number> = {21 transform: `scale(${scale})`,22 transformOrigin: "top left",23 "--dnd-grid-scale": scale,24 };2526 return (27 <div>28 <div style={{ display: "flex", gap: 8, marginBottom: 12 }}>29 {scaleOptions.map((value) => (30 <button key={value} onClick={() => setScale(value)} type="button">31 {value}x32 </button>33 ))}34 </div>3536 <DndGrid37 cols={12}38 containerProps={{ style: scaledStyle }}39 layout={layout}40 onLayoutChange={setLayout}41 rowHeight={50}42 transformScale={scale}43 >44 {layout.map((item) => (45 <div className="grid-item" key={item.id}>46 {item.id}47 </div>48 ))}49 </DndGrid>50 </div>51 );52}
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 | |
| Boundedbounded-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 |
