{"id":26690762,"url":"https://github.com/STRML/react-grid-layout","last_synced_at":"2025-03-26T16:01:03.594Z","repository":{"id":25116961,"uuid":"28538501","full_name":"react-grid-layout/react-grid-layout","owner":"react-grid-layout","description":"A draggable and resizable grid layout with responsive breakpoints, for React.","archived":false,"fork":false,"pushed_at":"2025-03-11T12:53:37.000Z","size":15337,"stargazers_count":21015,"open_issues_count":231,"forks_count":2629,"subscribers_count":232,"default_branch":"master","last_synced_at":"2025-03-25T02:15:53.307Z","etag":null,"topics":["drag-and-drop","es2015","grid","javascript","react","resize"],"latest_commit_sha":null,"homepage":"https://react-grid-layout.github.io/react-grid-layout/examples/0-showcase.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/react-grid-layout.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-27T14:28:40.000Z","updated_at":"2025-03-25T01:09:51.000Z","dependencies_parsed_at":"2024-06-18T10:45:51.432Z","dependency_job_id":"e4a7ef19-7738-4d18-9eed-68e6aec61ebc","html_url":"https://github.com/react-grid-layout/react-grid-layout","commit_stats":{"total_commits":713,"total_committers":132,"mean_commits":5.401515151515151,"dds":0.300140252454418,"last_synced_commit":"915613d54b92afc4dbf6804ffac588d9e2987b09"},"previous_names":["strml/react-grid-layout"],"tags_count":114,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-grid-layout%2Freact-grid-layout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-grid-layout%2Freact-grid-layout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-grid-layout%2Freact-grid-layout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-grid-layout%2Freact-grid-layout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-grid-layout","download_url":"https://codeload.github.com/react-grid-layout/react-grid-layout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245689494,"owners_count":20656416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drag-and-drop","es2015","grid","javascript","react","resize"],"created_at":"2025-03-26T16:00:34.962Z","updated_at":"2025-03-26T16:01:03.575Z","avatar_url":"https://github.com/react-grid-layout.png","language":"JavaScript","readme":"# React-Grid-Layout\n\n[![travis build](https://travis-ci.org/STRML/react-grid-layout.svg?branch=master)](https://travis-ci.org/STRML/react-grid-layout)\n[![CDNJS](https://img.shields.io/cdnjs/v/react-grid-layout.svg)](https://cdnjs.com/libraries/react-grid-layout)\n[![npm package](https://img.shields.io/npm/v/react-grid-layout.svg?style=flat-square)](https://www.npmjs.org/package/react-grid-layout)\n[![npm downloads](https://img.shields.io/npm/dt/react-grid-layout.svg?maxAge=2592000)]()\n\nReact-Grid-Layout is a grid layout system much like [Packery](http://packery.metafizzy.co/) or\n[Gridster](http://dsmorse.github.io/gridster.js/), for React.\n\nUnlike those systems, it is responsive and supports breakpoints. Breakpoint layouts can be provided by the user\nor autogenerated.\n\nRGL is React-only and does not require jQuery.\n\n![BitMEX UI](http://i.imgur.com/oo1NT6c.gif)\n\n\u003e GIF from production usage on [BitMEX.com](https://www.bitmex.com)\n\n[**[Demo](https://react-grid-layout.github.io/react-grid-layout/) | [Changelog](/CHANGELOG.md) | [CodeSandbox Editable demo](https://codesandbox.io/s/5wy3rz5z1x?module=%2Fsrc%2FShowcaseLayout.js)**]\n\n## Table of Contents\n\n- [Demos](#demos)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Responsive Usage](#responsive-usage)\n- [Providing Grid Width](#providing-grid-width)\n- [Grid Layout Props](#grid-layout-props)\n- [Responsive Grid Layout Props](#responsive-grid-layout-props)\n- [Grid Item Props](#grid-item-props)\n- [User Recipes](../../wiki/Users-recipes)\n- [Performance](#performance)\n- [Contribute](#contribute)\n- [TODO List](#todo-list)\n\n## Demos\n\n1. [Showcase](https://react-grid-layout.github.io/react-grid-layout/examples/00-showcase.html)\n1. [Basic](https://react-grid-layout.github.io/react-grid-layout/examples/01-basic.html)\n1. [No Dragging/Resizing (Layout Only)](https://react-grid-layout.github.io/react-grid-layout/examples/02-no-dragging.html)\n1. [Messy Layout Autocorrect](https://react-grid-layout.github.io/react-grid-layout/examples/03-messy.html)\n1. [Layout Defined on Children](https://react-grid-layout.github.io/react-grid-layout/examples/04-grid-property.html)\n1. [Static Elements](https://react-grid-layout.github.io/react-grid-layout/examples/05-static-elements.html)\n1. [Adding/Removing Elements](https://react-grid-layout.github.io/react-grid-layout/examples/06-dynamic-add-remove.html)\n1. [Saving Layout to LocalStorage](https://react-grid-layout.github.io/react-grid-layout/examples/07-localstorage.html)\n1. [Saving a Responsive Layout to LocalStorage](https://react-grid-layout.github.io/react-grid-layout/examples/08-localstorage-responsive.html)\n1. [Minimum and Maximum Width/Height](https://react-grid-layout.github.io/react-grid-layout/examples/09-min-max-wh.html)\n1. [Dynamic Minimum and Maximum Width/Height](https://react-grid-layout.github.io/react-grid-layout/examples/10-dynamic-min-max-wh.html)\n1. [No Vertical Compacting (Free Movement)](https://react-grid-layout.github.io/react-grid-layout/examples/11-no-vertical-compact.html)\n1. [Prevent Collision](https://react-grid-layout.github.io/react-grid-layout/examples/12-prevent-collision.html)\n1. [Error Case](https://react-grid-layout.github.io/react-grid-layout/examples/13-error-case.html)\n1. [Toolbox](https://react-grid-layout.github.io/react-grid-layout/examples/14-toolbox.html)\n1. [Drag From Outside](https://react-grid-layout.github.io/react-grid-layout/examples/15-drag-from-outside.html)\n1. [Bounded Layout](https://react-grid-layout.github.io/react-grid-layout/examples/16-bounded.html)\n1. [Responsive Bootstrap-style Layout](https://react-grid-layout.github.io/react-grid-layout/examples/17-responsive-bootstrap-style.html)\n1. [Scaled Containers](https://react-grid-layout.github.io/react-grid-layout/examples/18-scale.html)\n1. [Allow Overlap](https://react-grid-layout.github.io/react-grid-layout/examples/19-allow-overlap.html)\n1. [All Resizable Handles](https://react-grid-layout.github.io/react-grid-layout/examples/20-resizable-handles.html)\n1. [Single Row Horizontal](https://react-grid-layout.github.io/react-grid-layout/examples/21-horizontal.html)\n\n#### Projects Using React-Grid-Layout\n\n- [BitMEX](https://www.bitmex.com/)\n- [AWS CloudFront Dashboards](https://aws.amazon.com/blogs/aws/cloudwatch-dashboards-create-use-customized-metrics-views/)\n- [Grafana](https://grafana.com/)\n- [Metabase](http://www.metabase.com/)\n- [HubSpot](http://www.hubspot.com)\n- [ComNetViz](http://www.grotto-networking.com/ComNetViz/ComNetViz.html)\n- [Stoplight](https://app.stoplight.io)\n- [Reflect](https://reflect.io)\n- [ez-Dashing](https://github.com/ylacaute/ez-Dashing)\n- [Kibana](https://www.elastic.co/products/kibana)\n- [Graphext](https://graphext.com/)\n- [Monday](https://support.monday.com/hc/en-us/articles/360002187819-What-are-the-Dashboards-)\n- [Quadency](https://quadency.com/)\n- [Hakkiri](https://www.hakkiri.io)\n- [Ubidots](https://help.ubidots.com/en/articles/2400308-create-dashboards-and-widgets)\n- [Statsout](https://statsout.com/)\n- [Datto RMM](https://www.datto.com/uk/products/rmm/)\n- [SquaredUp](https://squaredup.com/)\n\n_Know of others? Create a PR to let me know!_\n\n## Features\n\n- 100% React - no jQuery\n- Compatible with server-rendered apps\n- Draggable widgets\n- Resizable widgets\n- Static widgets\n- Configurable packing: horizontal, vertical, or off\n- Bounds checking for dragging and resizing\n- Widgets may be added or removed without rebuilding grid\n- Layout can be serialized and restored\n- Responsive breakpoints\n- Separate layouts per responsive breakpoint\n- Grid Items placed using CSS Transforms\n  - Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time\n- Compatibility with `\u003cReact.StrictMode\u003e`\n\n| Version      | Compatibility   |\n| ------------ | --------------- |\n| \u003e= 0.17.0    | React 16 \u0026 17   |\n| \u003e= 0.11.3    | React 0.14 \u0026 15 |\n| \u003e= 0.10.0    | React 0.14      |\n| 0.8. - 0.9.2 | React 0.13      |\n| \u003c 0.8        | React 0.12      |\n\n## Installation\n\nInstall the React-Grid-Layout [package](https://www.npmjs.org/package/react-grid-layout) using [npm](https://www.npmjs.com/):\n\n```bash\nnpm install react-grid-layout\n```\n\nInclude the following stylesheets in your application:\n\n```\n/node_modules/react-grid-layout/css/styles.css\n/node_modules/react-resizable/css/styles.css\n```\n\n## Usage\n\nUse ReactGridLayout like any other component. The following example below will\nproduce a grid with three items where:\n\n- users will not be able to drag or resize item `a`\n- item `b` will be restricted to a minimum width of 2 grid blocks and a maximum width of 4 grid blocks\n- users will be able to freely drag and resize item `c`\n\n```js\nimport GridLayout from \"react-grid-layout\";\n\nclass MyFirstGrid extends React.Component {\n  render() {\n    // layout is an array of objects, see the demo for more complete usage\n    const layout = [\n      { i: \"a\", x: 0, y: 0, w: 1, h: 2, static: true },\n      { i: \"b\", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },\n      { i: \"c\", x: 4, y: 0, w: 1, h: 2 }\n    ];\n    return (\n      \u003cGridLayout\n        className=\"layout\"\n        layout={layout}\n        cols={12}\n        rowHeight={30}\n        width={1200}\n      \u003e\n        \u003cdiv key=\"a\"\u003ea\u003c/div\u003e\n        \u003cdiv key=\"b\"\u003eb\u003c/div\u003e\n        \u003cdiv key=\"c\"\u003ec\u003c/div\u003e\n      \u003c/GridLayout\u003e\n    );\n  }\n}\n```\n\nYou may also choose to set layout properties directly on the children:\n\n```js\nimport GridLayout from \"react-grid-layout\";\n\nclass MyFirstGrid extends React.Component {\n  render() {\n    return (\n      \u003cGridLayout className=\"layout\" cols={12} rowHeight={30} width={1200}\u003e\n        \u003cdiv key=\"a\" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}\u003e\n          a\n        \u003c/div\u003e\n        \u003cdiv key=\"b\" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}\u003e\n          b\n        \u003c/div\u003e\n        \u003cdiv key=\"c\" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}\u003e\n          c\n        \u003c/div\u003e\n      \u003c/GridLayout\u003e\n    );\n  }\n}\n```\n\n### Usage without Browserify/Webpack\n\nA module usable in a `\u003cscript\u003e` tag is included [here](/dist/react-grid-layout.min.js). It uses a UMD shim and\nexcludes `React`, so it must be otherwise available in your application, either via RequireJS or on `window.React`.\n\n### Responsive Usage\n\nTo make RGL responsive, use the `\u003cResponsiveReactGridLayout\u003e` element:\n\n```js\nimport { Responsive as ResponsiveGridLayout } from \"react-grid-layout\";\n\nclass MyResponsiveGrid extends React.Component {\n  render() {\n    // {lg: layout1, md: layout2, ...}\n    const layouts = getLayoutsFromSomewhere();\n    return (\n      \u003cResponsiveGridLayout\n        className=\"layout\"\n        layouts={layouts}\n        breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}\n        cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}\n      \u003e\n        \u003cdiv key=\"1\"\u003e1\u003c/div\u003e\n        \u003cdiv key=\"2\"\u003e2\u003c/div\u003e\n        \u003cdiv key=\"3\"\u003e3\u003c/div\u003e\n      \u003c/ResponsiveGridLayout\u003e\n    );\n  }\n}\n```\n\nWhen in responsive mode, you should supply at least one breakpoint via the `layouts` property.\n\nWhen using `layouts`, it is best to supply as many breakpoints as possible, especially the largest one.\nIf the largest is provided, RGL will attempt to interpolate the rest.\n\nYou will also need to provide a `width`, when using `\u003cResponsiveReactGridLayout\u003e` it is suggested you use the HOC\n`WidthProvider` as per the instructions below.\n\nIt is possible to supply default mappings via the `data-grid` property on individual\nitems, so that they would be taken into account within layout interpolation.\n\n### Providing Grid Width\n\nBoth `\u003cResponsiveReactGridLayout\u003e` and `\u003cReactGridLayout\u003e` take `width` to calculate\npositions on drag events. In simple cases a HOC `WidthProvider` can be used to automatically determine\nwidth upon initialization and window resize events.\n\n```js\nimport { Responsive, WidthProvider } from \"react-grid-layout\";\n\nconst ResponsiveGridLayout = WidthProvider(Responsive);\n\nclass MyResponsiveGrid extends React.Component {\n  render() {\n    // {lg: layout1, md: layout2, ...}\n    var layouts = getLayoutsFromSomewhere();\n    return (\n      \u003cResponsiveGridLayout\n        className=\"layout\"\n        layouts={layouts}\n        breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}\n        cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}\n      \u003e\n        \u003cdiv key=\"1\"\u003e1\u003c/div\u003e\n        \u003cdiv key=\"2\"\u003e2\u003c/div\u003e\n        \u003cdiv key=\"3\"\u003e3\u003c/div\u003e\n      \u003c/ResponsiveGridLayout\u003e\n    );\n  }\n}\n```\n\nThis allows you to easily replace `WidthProvider` with your own Provider HOC if you need more sophisticated logic.\n\n`WidthProvider` accepts a single prop, `measureBeforeMount`. If `true`, `WidthProvider` will measure the\ncontainer's width before mounting children. Use this if you'd like to completely eliminate any resizing animation\non application/component mount.\n\nHave a more complicated layout? `WidthProvider` [is very simple](/lib/components/WidthProvider.jsx) and only\nlistens to window `'resize'` events. If you need more power and flexibility, try the\n[SizeMe React HOC](https://github.com/ctrlplusb/react-sizeme) as an alternative to WidthProvider.\n\n### Grid Layout Props\n\nRGL supports the following properties (see the source for the final word on this):\n\n```js\n//\n// Basic props\n//\n\n// This allows setting the initial width on the server side.\n// This is required unless using the HOC \u003cWidthProvider\u003e or similar\nwidth: number,\n\n// If true, the container height swells and contracts to fit contents\nautoSize: ?boolean = true,\n\n// Number of columns in this layout.\ncols: ?number = 12,\n\n// A CSS selector for tags that will not be draggable.\n// For example: draggableCancel:'.MyNonDraggableAreaClassName'\n// If you forget the leading . it will not work.\n// .react-resizable-handle\" is always prepended to this value.\ndraggableCancel: ?string = '',\n\n// A CSS selector for tags that will act as the draggable handle.\n// For example: draggableHandle:'.MyDragHandleClassName'\n// If you forget the leading . it will not work.\ndraggableHandle: ?string = '',\n\n// Compaction type.\ncompactType: ?('vertical' | 'horizontal' | null) = 'vertical';\n\n// Layout is an array of objects with the format:\n// The index into the layout must match the key used on each item component.\n// If you choose to use custom keys, you can specify that key in the layout\n// array objects using the `i` prop.\nlayout: ?Array\u003c{i?: string, x: number, y: number, w: number, h: number}\u003e = null, // If not provided, use data-grid props on children\n\n// Margin between items [x, y] in px.\nmargin: ?[number, number] = [10, 10],\n\n// Padding inside the container [x, y] in px\ncontainerPadding: ?[number, number] = margin,\n\n// Rows have a static height, but you can change this based on breakpoints\n// if you like.\nrowHeight: ?number = 150,\n\n// Configuration of a dropping element. Dropping element is a \"virtual\" element\n// which appears when you drag over some element from outside.\n// It can be changed by passing specific parameters:\n//  i - id of an element\n//  w - width of an element\n//  h - height of an element\ndroppingItem?: { i: string, w: number, h: number }\n\n//\n// Flags\n//\nisDraggable: ?boolean = true,\nisResizable: ?boolean = true,\nisBounded: ?boolean = false,\n// Uses CSS3 translate() instead of position top/left.\n// This makes about 6x faster paint performance\nuseCSSTransforms: ?boolean = true,\n// If parent DOM node of ResponsiveReactGridLayout or ReactGridLayout has \"transform: scale(n)\" css property,\n// we should set scale coefficient to avoid render artefacts while dragging.\ntransformScale: ?number = 1,\n\n// If true, grid can be placed one over the other.\n// If set, implies `preventCollision`.\nallowOverlap: ?boolean = false,\n\n// If true, grid items won't change position when being\n// dragged over. If `allowOverlap` is still false,\n// this simply won't allow one to drop on an existing object.\npreventCollision: ?boolean = false,\n\n// If true, droppable elements (with `draggable={true}` attribute)\n// can be dropped on the grid. It triggers \"onDrop\" callback\n// with position and event object as parameters.\n// It can be useful for dropping an element in a specific position\n//\n// NOTE: In case of using Firefox you should add\n// `onDragStart={e =\u003e e.dataTransfer.setData('text/plain', '')}` attribute\n// along with `draggable={true}` otherwise this feature will work incorrect.\n// onDragStart attribute is required for Firefox for a dragging initialization\n// @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313\nisDroppable: ?boolean = false,\n// Defines which resize handles should be rendered.\n// Allows for any combination of:\n// 's' - South handle (bottom-center)\n// 'w' - West handle (left-center)\n// 'e' - East handle (right-center)\n// 'n' - North handle (top-center)\n// 'sw' - Southwest handle (bottom-left)\n// 'nw' - Northwest handle (top-left)\n// 'se' - Southeast handle (bottom-right)\n// 'ne' - Northeast handle (top-right)\n//\n// Note that changing this property dynamically does not work due to a restriction in react-resizable.\nresizeHandles: ?Array\u003c's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'\u003e = ['se'],\n// Custom component for resize handles\n// See `handle` as used in https://github.com/react-grid-layout/react-resizable#resize-handle\n// Your component should have the class `.react-resizable-handle`, or you should add your custom\n// class to the `draggableCancel` prop.\nresizeHandle?: ReactElement\u003cany\u003e | ((resizeHandleAxis: ResizeHandleAxis, ref: ReactRef\u003cHTMLElement\u003e) =\u003e ReactElement\u003cany\u003e),\n\n//\n// Callbacks\n//\n\n// Callback so you can save the layout.\n// Calls back with (currentLayout) after every drag or resize stop.\nonLayoutChange: (layout: Layout) =\u003e void,\n\n//\n// All callbacks below have signature (layout, oldItem, newItem, placeholder, e, element).\n// 'start' and 'stop' callbacks pass `undefined` for 'placeholder'.\n//\ntype ItemCallback = (layout: Layout, oldItem: LayoutItem, newItem: LayoutItem,\n                     placeholder: LayoutItem, e: MouseEvent, element: HTMLElement) =\u003e void,\n\n// Calls when drag starts.\nonDragStart: ItemCallback,\n// Calls on each drag movement.\nonDrag: ItemCallback,\n// Calls when drag is complete.\nonDragStop: ItemCallback,\n// Calls when resize starts.\nonResizeStart: ItemCallback,\n// Calls when resize movement happens.\nonResize: ItemCallback,\n// Calls when resize is complete.\nonResizeStop: ItemCallback,\n\n//\n// Dropover functionality\n//\n\n// Calls when an element has been dropped into the grid from outside.\nonDrop: (layout: Layout, item: ?LayoutItem, e: Event) =\u003e void,\n// Calls when an element is being dragged over the grid from outside as above.\n// This callback should return an object to dynamically change the droppingItem size\n// Return false to short-circuit the dragover\nonDropDragOver: (e: DragOverEvent) =\u003e ?({|w?: number, h?: number|} | false),\n\n// Ref for getting a reference for the grid's wrapping div.\n// You can use this instead of a regular ref and the deprecated `ReactDOM.findDOMNode()`` function.\n// Note that this type is React.Ref\u003cHTMLDivElement\u003e in TypeScript, Flow has a bug here\n// https://github.com/facebook/flow/issues/8671#issuecomment-862634865\ninnerRef: {current: null | HTMLDivElement},\n```\n\n### Responsive Grid Layout Props\n\nThe responsive grid layout can be used instead. It supports all of the props above, excepting `layout`.\nThe new properties and changes are:\n\n```js\n// {name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}\n// Breakpoint names are arbitrary but must match in the cols and layouts objects.\nbreakpoints: ?Object = {lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0},\n\n// # of cols. This is a breakpoint -\u003e cols map, e.g. {lg: 12, md: 10, ...}\ncols: ?Object = {lg: 12, md: 10, sm: 6, xs: 4, xxs: 2},\n\n\n// margin (in pixels). Can be specified either as horizontal and vertical margin, e.g. `[10, 10]` or as a breakpoint -\u003e margin map, e.g. `{lg: [10, 10], md: [10, 10], ...}.\nmargin: [number, number] | {[breakpoint: $Keys\u003cbreakpoints\u003e]: [number, number]},\n\n\n// containerPadding (in pixels). Can be specified either as horizontal and vertical padding, e.g. `[10, 10]` or as a breakpoint -\u003e containerPadding map, e.g. `{lg: [10, 10], md: [10, 10], ...}.\ncontainerPadding: [number, number] | {[breakpoint: $Keys\u003cbreakpoints\u003e]: [number, number]},\n\n\n// layouts is an object mapping breakpoints to layouts.\n// e.g. {lg: Layout, md: Layout, ...}\nlayouts: {[key: $Keys\u003cbreakpoints\u003e]: Layout},\n\n//\n// Callbacks\n//\n\n// Calls back with breakpoint and new # cols\nonBreakpointChange: (newBreakpoint: string, newCols: number) =\u003e void,\n\n// Callback so you can save the layout.\n// AllLayouts are keyed by breakpoint.\nonLayoutChange: (currentLayout: Layout, allLayouts: {[key: $Keys\u003cbreakpoints\u003e]: Layout}) =\u003e void,\n\n// Callback when the width changes, so you can modify the layout as needed.\nonWidthChange: (containerWidth: number, margin: [number, number], cols: number, containerPadding: [number, number]) =\u003e void;\n\n```\n\n### Grid Item Props\n\nRGL supports the following properties on grid items or layout items. When initializing a grid,\nbuild a layout array (as in the first example above), or attach this object as the `data-grid` property\nto each of your child elements (as in the second example).\n\nIf `data-grid` is provided on an item, it will take precedence over an item in the `layout` with the same key (`i`).\n\nNote that if a grid item is provided but incomplete (missing one of `x, y, w, or h`), an error\nwill be thrown so you can correct your layout.\n\nIf no properties are provided for a grid item, one will be generated with a width and height of `1`.\n\nYou can set minimums and maximums for each dimension. This is for resizing; it of course has no effect if resizing\nis disabled. Errors will be thrown if your mins and maxes overlap incorrectly, or your initial dimensions\nare out of range.\n\nAny `\u003cGridItem\u003e` properties defined directly will take precedence over globally-set options. For\nexample, if the layout has the property `isDraggable: false`, but the grid item has the prop `isDraggable: true`, the item\nwill be draggable, even if the item is marked `static: true`.\n\n```js\n{\n\n  // A string corresponding to the component key\n  i: string,\n\n  // These are all in grid units, not pixels\n  x: number,\n  y: number,\n  w: number,\n  h: number,\n  minW: ?number = 0,\n  maxW: ?number = Infinity,\n  minH: ?number = 0,\n  maxH: ?number = Infinity,\n\n  // If true, equal to `isDraggable: false, isResizable: false`.\n  static: ?boolean = false,\n  // If false, will not be draggable. Overrides `static`.\n  isDraggable: ?boolean = true,\n  // If false, will not be resizable. Overrides `static`.\n  isResizable: ?boolean = true,\n  // By default, a handle is only shown on the bottom-right (southeast) corner.\n  // As of RGL \u003e= 1.4.0, resizing on any corner works just fine!\n  resizeHandles?: ?Array\u003c's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'\u003e = ['se']\n  // If true and draggable, item will be moved only within grid.\n  isBounded: ?boolean = false\n}\n```\n\n### Grid Item Heights and Widths\n\nGrid item widths are based on container and number of columns. The size of a grid unit's height is based on `rowHeight`.\n\nNote that an item that has `h=2` is _not exactly twice as tall as one with `h=1` unless you have no `margin`_!\n\nIn order for the grid to not be ragged, when an item spans grid units, it must also span margins. So you must add the height or width or the margin you are spanning for each unit. So actual pixel height is `(rowHeight * h) + (marginH * (h - 1)`.\n\nFor example, with `rowHeight=30`, `margin=[10,10]` and a unit with height 4, the calculation is `(30 * 4) + (10 * 3)`\n\n![margin](margin.png)\n\nIf this is a problem for you, set `margin=[0,0]` and handle visual spacing between your elements inside the elements' content.\n\n### Performance\n\n`\u003cReactGridLayout\u003e` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:\n\n```js\n// lib/ReactGridLayout.jsx\n// ...\nshouldComponentUpdate(nextProps: Props, nextState: State) {\n  return (\n    // NOTE: this is almost always unequal. Therefore the only way to get better performance\n    // from SCU is if the user intentionally memoizes children. If they do, and they can\n    // handle changes properly, performance will increase.\n    this.props.children !== nextProps.children ||\n    !fastRGLPropsEqual(this.props, nextProps, isEqual) ||\n    !isEqual(this.state.activeDrag, nextState.activeDrag)\n  );\n}\n// ...\n```\n\nIf you memoize your children, you can take advantage of this, and reap faster rerenders. For example:\n\n```js\nfunction MyGrid(props) {\n  const children = React.useMemo(() =\u003e {\n    return new Array(props.count).fill(undefined).map((val, idx) =\u003e {\n      return \u003cdiv key={idx} data-grid={{ x: idx, y: 1, w: 1, h: 1 }} /\u003e;\n    });\n  }, [props.count]);\n  return \u003cReactGridLayout cols={12}\u003e{children}\u003c/ReactGridLayout\u003e;\n}\n```\n\nBecause the `children` prop doesn't change between rerenders, updates to `\u003cMyGrid\u003e` won't result in new renders, improving performance.\n\n### React Hooks Performance\n\nUsing hooks to save your layout state on change will cause the layouts to re-render as the ResponsiveGridLayout will change it's value on every render.\nTo avoid this you should wrap your WidthProvider in a useMemo:\n\n```js\nconst ResponsiveReactGridLayout = useMemo(() =\u003e WidthProvider(Responsive), []);\n```\n\n### Custom Child Components and Draggable Handles\n\nIf you use React Components as grid children, they need to do a few things:\n\n1. Forward refs to an underlying DOM node, and\n2. Forward `style`,`className`, `onMouseDown`, `onMouseUp` and `onTouchEnd` to that same DOM node.\n\nFor example:\n\n```js\nconst CustomGridItemComponent = React.forwardRef(({style, className, onMouseDown, onMouseUp, onTouchEnd, children, ...props}, ref) =\u003e {\n  return (\n    \u003cdiv style={{ /* styles */, ...style}} className={className} ref={ref} onMouseDown={onMouseDown} onMouseUp={onMouseUp} onTouchEnd={onTouchEnd}\u003e\n      {/* Some other content */}\n      {children} {/* Make sure to include children to add resizable handle */}\n    \u003c/div\u003e\n  );\n})\n```\n\nThe same is true of custom elements as draggable handles using the `draggableHandle` prop. This is so that\nthe underlying `react-draggable` library can get a reference to the DOM node underneath, manipulate\npositioning via `style`, and set classes.\n\n## Contribute\n\nIf you have a feature request, please add it as an issue or make a pull request.\n\nIf you have a bug to report, please reproduce the bug in [CodeSandbox](https://codesandbox.io/s/staging-bush-3lvt7?file=/src/ShowcaseLayout.js) to help\nus easily isolate it.\n\n## TODO List\n\n- [x] Basic grid layout\n- [x] Fluid grid layout\n- [x] Grid packing\n- [x] Draggable grid items\n- [x] Live grid packing while dragging\n- [x] Resizable grid items\n- [x] Layouts per responsive breakpoint\n- [x] Define grid attributes on children themselves (`data-grid` key)\n- [x] Static elements\n- [x] Persistent id per item for predictable localstorage restores, even when # items changes\n- [x] Min/max w/h per item\n- [x] Resizable handles on other corners\n- [ ] Configurable w/h per breakpoint\n","funding_links":[],"categories":["React","UI Layout","Uncategorized","UI Components","Please find below the links to awesome cheat-sheet and resources:","JavaScript","Soluções","目录"],"sub_categories":["React Components","Form Components","Uncategorized","Layout","React/React-Native:","\u003ca id=\"ui\"\u003eui\u003c/a\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSTRML%2Freact-grid-layout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSTRML%2Freact-grid-layout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSTRML%2Freact-grid-layout/lists"}