Portal
dnd-grid/portal-exampleFreeComponent
Render the grid into a portal container.
Install it
npx shadcn@latest add https://dnd-grid.com/r/portal-example.jsonSource
1"use client";23import { DndGrid, type Layout } from "@dnd-grid/react";4import { useEffect, useRef, useState } from "react";5import { createPortal } from "react-dom";67const initialLayout: Layout = [8 { id: "p1", x: 0, y: 0, w: 3, h: 2 },9 { id: "p2", x: 3, y: 0, w: 3, h: 2 },10 { id: "p3", x: 6, y: 0, w: 3, h: 2 },11 { id: "p4", x: 9, y: 0, w: 3, h: 2 },12];1314export function PortalExample() {15 const [layout, setLayout] = useState<Layout>(initialLayout);16 const portalRef = useRef<HTMLDivElement>(null);17 const [mounted, setMounted] = useState(false);1819 useEffect(() => {20 setMounted(true);21 }, []);2223 const grid = (24 <DndGrid25 cols={12}26 layout={layout}27 onLayoutChange={setLayout}28 rowHeight={50}29 >30 {layout.map((item) => (31 <div className="grid-item" key={item.id}>32 {item.id}33 </div>34 ))}35 </DndGrid>36 );3738 return (39 <div className="space-y-4">40 <div className="text-xs text-zinc-500">41 Grid rendered via createPortal into a separate container.42 </div>43 <div44 className="min-h-[200px] rounded-lg border border-zinc-300 border-dashed p-4"45 ref={portalRef}46 />47 {mounted && portalRef.current && createPortal(grid, portalRef.current)}48 </div>49 );50}
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 |
