🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@dnd-grid/react

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dnd-grid/react

A draggable and resizable grid layout with responsive breakpoints, for React.

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
725
-5.72%
Maintainers
1
Weekly downloads
 
Created
Source

dnd-grid

A draggable and resizable grid layout with responsive breakpoints for React.

Installation

npm install dnd-grid

Usage

import { DndGrid, type Layout } from "dnd-grid";

const layout: Layout = [
  { i: "a", x: 0, y: 0, w: 2, h: 2, deg: 0 },
  { i: "b", x: 2, y: 0, w: 2, h: 2, deg: 0 },
  { i: "c", x: 4, y: 0, w: 2, h: 2, deg: 0 },
];

function MyGrid() {
  const [currentLayout, setLayout] = useState(layout);

  return (
    <DndGrid
      layout={currentLayout}
      cols={12}
      rowHeight={30}
      width={1200}
      onLayoutChange={(newLayout) => setLayout(newLayout)}
    >
      <div key="a">A</div>
      <div key="b">B</div>
      <div key="c">C</div>
    </DndGrid>
  );
}

Features

  • 100% React - no jQuery
  • Compatible with server-rendered apps
  • Draggable widgets
  • Resizable widgets
  • Static widgets
  • Configurable packing: horizontal, vertical, or off
  • Bounds checking for dragging and resizing
  • Widgets may be added or removed without rebuilding grid
  • Layout can be serialized and restored
  • Grid Items placed using CSS Transforms

Props

PropTypeDefaultDescription
layoutLayout[]Array of layout items
colsnumber12Number of columns
rowHeightnumber150Height of a row in pixels
widthnumberrequiredWidth of the grid container
margin[number, number, number, number][10, 10, 10, 10]Margin around items [top, right, bottom, left]
containerPadding[number, number, number, number]nullContainer padding [top, right, bottom, left]
isDraggablebooleantrueEnable dragging
isResizablebooleantrueEnable resizing
isBoundedbooleanfalseKeep items within container bounds
isDroppablebooleanfalseEnable dropping items from outside
allowOverlapbooleanfalseAllow items to overlap
preventCollisionbooleanfalsePrevent items from colliding
compactType"vertical" | "horizontal" | null"vertical"Compacting direction
resizeHandlesResizeHandleAxis[]["se"]Resize handle positions
transformScalenumber1Scale factor for CSS transforms
dragTouchDelayDurationnumber0Touch delay before drag starts (ms)

Layout Item

Each item in the layout array has these properties:

interface LayoutItem {
  i: string;      // Unique identifier
  x: number;      // X position in grid units
  y: number;      // Y position in grid units
  w: number;      // Width in grid units
  h: number;      // Height in grid units
  deg?: number;   // Rotation in degrees
  minW?: number;  // Minimum width
  maxW?: number;  // Maximum width
  minH?: number;  // Minimum height
  maxH?: number;  // Maximum height
  static?: boolean;     // Cannot be moved or resized
  isDraggable?: boolean; // Override grid isDraggable
  isResizable?: boolean; // Override grid isResizable
  isBounded?: boolean;   // Override grid isBounded
}

Callbacks

CallbackTypeDescription
onLayoutChange(layout: Layout) => voidCalled when layout changes
onDragStart(layout, oldItem, newItem, placeholder, e, node) => voidCalled when drag starts
onDrag(layout, oldItem, newItem, placeholder, e, node) => voidCalled during drag
onDragStop(layout, oldItem, newItem, placeholder, e, node) => voidCalled when drag stops
onResizeStart(layout, oldItem, newItem, placeholder, e, node) => voidCalled when resize starts
onResize(layout, oldItem, newItem, placeholder, e, node) => voidCalled during resize
onResizeStop(layout, oldItem, newItem, placeholder, e, node) => voidCalled when resize stops
onDrop(layout, item, e) => voidCalled when item is dropped
onDropDragOver(e) => { w?: number; h?: number } | falseCustomize dropping item

CSS Classes

The grid uses the following CSS classes:

  • .dnd-grid - Grid container
  • .dnd-grid-item - Grid item
  • .dnd-grid-placeholder - Placeholder during drag/resize
  • .dnd-draggable - Draggable item
  • .dnd-draggable-dragging - Item being dragged

Acknowledgements

This project is based on react-grid-layout by Samuel Reed (STRML). The original project provided the foundation for the grid layout algorithms and core functionality.

License

MIT License - Copyright (c) 2025 Matthew Blode

Keywords

react

FAQs

Package last updated on 20 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts