react-grid-layout 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.js +3 -2
- package/.eslintignore +3 -0
- package/.prettierignore +1 -0
- package/CHANGELOG.md +358 -260
- package/README.md +68 -48
- package/build/utils.js +1 -10
- package/coverage/clover.xml +761 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/react-grid-layout/index-dev.js.html +104 -0
- package/coverage/lcov-report/react-grid-layout/lib/GridItem.jsx.html +2099 -0
- package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayout.jsx.html +2453 -0
- package/coverage/lcov-report/react-grid-layout/lib/ReactGridLayoutPropTypes.js.html +833 -0
- package/coverage/lcov-report/react-grid-layout/lib/ResponsiveReactGridLayout.jsx.html +1133 -0
- package/coverage/lcov-report/react-grid-layout/lib/calculateUtils.js.html +557 -0
- package/coverage/lcov-report/react-grid-layout/lib/components/WidthProvider.jsx.html +410 -0
- package/coverage/lcov-report/react-grid-layout/lib/fastRGLPropsEqual.js.html +224 -0
- package/coverage/lcov-report/react-grid-layout/lib/responsiveUtils.js.html +440 -0
- package/coverage/lcov-report/react-grid-layout/lib/utils.js.html +2456 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/0-showcase.jsx.html +521 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/1-basic.jsx.html +284 -0
- package/coverage/lcov-report/react-grid-layout/test/examples/15-drag-from-outside.jsx.html +506 -0
- package/coverage/lcov-report/react-grid-layout/test/util/deepFreeze.js.html +248 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +1584 -0
- package/dist/react-grid-layout.min.js +1 -1
- package/dist/react-grid-layout.min.js.map +1 -1
- package/index.js +4 -2
- package/lib/GridItem.jsx +8 -3
- package/lib/utils.js +1 -15
- package/package.json +18 -6
- package/foo.html +0 -388
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ or autogenerated.
|
|
|
14
14
|
RGL is React-only and does not require jQuery.
|
|
15
15
|
|
|
16
16
|

|
|
17
|
+
|
|
17
18
|
> GIF from production usage on [BitMEX.com](https://www.bitmex.com)
|
|
18
19
|
|
|
19
20
|
[**[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)**]
|
|
@@ -77,32 +78,32 @@ RGL is React-only and does not require jQuery.
|
|
|
77
78
|
- [Statsout](https://statsout.com/)
|
|
78
79
|
- [Datto RMM](https://www.datto.com/uk/products/rmm/)
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
_Know of others? Create a PR to let me know!_
|
|
81
82
|
|
|
82
83
|
## Features
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|Version
|
|
100
|
-
|
|
101
|
-
| >= 0.17.0
|
|
102
|
-
| >= 0.11.3
|
|
103
|
-
| >= 0.10.0
|
|
104
|
-
| 0.8. - 0.9.2
|
|
105
|
-
| < 0.8
|
|
85
|
+
- 100% React - no jQuery
|
|
86
|
+
- Compatible with server-rendered apps
|
|
87
|
+
- Draggable widgets
|
|
88
|
+
- Resizable widgets
|
|
89
|
+
- Static widgets
|
|
90
|
+
- Configurable packing: horizontal, vertical, or off
|
|
91
|
+
- Bounds checking for dragging and resizing
|
|
92
|
+
- Widgets may be added or removed without rebuilding grid
|
|
93
|
+
- Layout can be serialized and restored
|
|
94
|
+
- Responsive breakpoints
|
|
95
|
+
- Separate layouts per responsive breakpoint
|
|
96
|
+
- Grid Items placed using CSS Transforms
|
|
97
|
+
- Performance with CSS Transforms: [on](http://i.imgur.com/FTogpLp.jpg) / [off](http://i.imgur.com/gOveMm8.jpg), note paint (green) as % of time
|
|
98
|
+
- Compatibility with `<React.StrictMode>`
|
|
99
|
+
|
|
100
|
+
| Version | Compatibility |
|
|
101
|
+
| ------------ | --------------- |
|
|
102
|
+
| >= 0.17.0 | React 16 & 17 |
|
|
103
|
+
| >= 0.11.3 | React 0.14 & 15 |
|
|
104
|
+
| >= 0.10.0 | React 0.14 |
|
|
105
|
+
| 0.8. - 0.9.2 | React 0.13 |
|
|
106
|
+
| < 0.8 | React 0.12 |
|
|
106
107
|
|
|
107
108
|
## Installation
|
|
108
109
|
|
|
@@ -129,23 +130,29 @@ produce a grid with three items where:
|
|
|
129
130
|
- users will be able to freely drag and resize item `c`
|
|
130
131
|
|
|
131
132
|
```js
|
|
132
|
-
import GridLayout from
|
|
133
|
+
import GridLayout from "react-grid-layout";
|
|
133
134
|
|
|
134
135
|
class MyFirstGrid extends React.Component {
|
|
135
136
|
render() {
|
|
136
137
|
// layout is an array of objects, see the demo for more complete usage
|
|
137
138
|
const layout = [
|
|
138
|
-
{i:
|
|
139
|
-
{i:
|
|
140
|
-
{i:
|
|
139
|
+
{ i: "a", x: 0, y: 0, w: 1, h: 2, static: true },
|
|
140
|
+
{ i: "b", x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
|
|
141
|
+
{ i: "c", x: 4, y: 0, w: 1, h: 2 }
|
|
141
142
|
];
|
|
142
143
|
return (
|
|
143
|
-
<GridLayout
|
|
144
|
+
<GridLayout
|
|
145
|
+
className="layout"
|
|
146
|
+
layout={layout}
|
|
147
|
+
cols={12}
|
|
148
|
+
rowHeight={30}
|
|
149
|
+
width={1200}
|
|
150
|
+
>
|
|
144
151
|
<div key="a">a</div>
|
|
145
152
|
<div key="b">b</div>
|
|
146
153
|
<div key="c">c</div>
|
|
147
154
|
</GridLayout>
|
|
148
|
-
)
|
|
155
|
+
);
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
```
|
|
@@ -153,17 +160,23 @@ class MyFirstGrid extends React.Component {
|
|
|
153
160
|
You may also choose to set layout properties directly on the children:
|
|
154
161
|
|
|
155
162
|
```js
|
|
156
|
-
import GridLayout from
|
|
163
|
+
import GridLayout from "react-grid-layout";
|
|
157
164
|
|
|
158
165
|
class MyFirstGrid extends React.Component {
|
|
159
166
|
render() {
|
|
160
167
|
return (
|
|
161
168
|
<GridLayout className="layout" cols={12} rowHeight={30} width={1200}>
|
|
162
|
-
<div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}>
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
<div key="a" data-grid={{ x: 0, y: 0, w: 1, h: 2, static: true }}>
|
|
170
|
+
a
|
|
171
|
+
</div>
|
|
172
|
+
<div key="b" data-grid={{ x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 }}>
|
|
173
|
+
b
|
|
174
|
+
</div>
|
|
175
|
+
<div key="c" data-grid={{ x: 4, y: 0, w: 1, h: 2 }}>
|
|
176
|
+
c
|
|
177
|
+
</div>
|
|
165
178
|
</GridLayout>
|
|
166
|
-
)
|
|
179
|
+
);
|
|
167
180
|
}
|
|
168
181
|
}
|
|
169
182
|
```
|
|
@@ -178,21 +191,24 @@ excludes `React`, so it must be otherwise available in your application, either
|
|
|
178
191
|
To make RGL responsive, use the `<ResponsiveReactGridLayout>` element:
|
|
179
192
|
|
|
180
193
|
```js
|
|
181
|
-
import { Responsive as ResponsiveGridLayout } from
|
|
194
|
+
import { Responsive as ResponsiveGridLayout } from "react-grid-layout";
|
|
182
195
|
|
|
183
196
|
class MyResponsiveGrid extends React.Component {
|
|
184
197
|
render() {
|
|
185
198
|
// {lg: layout1, md: layout2, ...}
|
|
186
199
|
const layouts = getLayoutsFromSomewhere();
|
|
187
200
|
return (
|
|
188
|
-
<ResponsiveGridLayout
|
|
189
|
-
|
|
190
|
-
|
|
201
|
+
<ResponsiveGridLayout
|
|
202
|
+
className="layout"
|
|
203
|
+
layouts={layouts}
|
|
204
|
+
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
|
|
205
|
+
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
|
|
206
|
+
>
|
|
191
207
|
<div key="1">1</div>
|
|
192
208
|
<div key="2">2</div>
|
|
193
209
|
<div key="3">3</div>
|
|
194
210
|
</ResponsiveGridLayout>
|
|
195
|
-
)
|
|
211
|
+
);
|
|
196
212
|
}
|
|
197
213
|
}
|
|
198
214
|
```
|
|
@@ -215,7 +231,7 @@ positions on drag events. In simple cases a HOC `WidthProvider` can be used to a
|
|
|
215
231
|
width upon initialization and window resize events.
|
|
216
232
|
|
|
217
233
|
```js
|
|
218
|
-
import { Responsive, WidthProvider } from
|
|
234
|
+
import { Responsive, WidthProvider } from "react-grid-layout";
|
|
219
235
|
|
|
220
236
|
const ResponsiveGridLayout = WidthProvider(Responsive);
|
|
221
237
|
|
|
@@ -224,14 +240,17 @@ class MyResponsiveGrid extends React.Component {
|
|
|
224
240
|
// {lg: layout1, md: layout2, ...}
|
|
225
241
|
var layouts = getLayoutsFromSomewhere();
|
|
226
242
|
return (
|
|
227
|
-
<ResponsiveGridLayout
|
|
228
|
-
|
|
229
|
-
|
|
243
|
+
<ResponsiveGridLayout
|
|
244
|
+
className="layout"
|
|
245
|
+
layouts={layouts}
|
|
246
|
+
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
|
|
247
|
+
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
|
|
248
|
+
>
|
|
230
249
|
<div key="1">1</div>
|
|
231
250
|
<div key="2">2</div>
|
|
232
251
|
<div key="3">3</div>
|
|
233
252
|
</ResponsiveGridLayout>
|
|
234
|
-
)
|
|
253
|
+
);
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
256
|
```
|
|
@@ -396,7 +415,9 @@ onDropDragOver: (e: DragOverEvent) => ?({|w?: number, h?: number|} | false),
|
|
|
396
415
|
|
|
397
416
|
// Ref for getting a reference for the grid's wrapping div.
|
|
398
417
|
// You can use this instead of a regular ref and the deprecated `ReactDOM.findDOMNode()`` function.
|
|
399
|
-
|
|
418
|
+
// Note that this type is React.Ref<HTMLDivElement> in TypeScript, Flow has a bug here
|
|
419
|
+
// https://github.com/facebook/flow/issues/8671#issuecomment-862634865
|
|
420
|
+
innerRef: {current: null | HTMLDivElement},
|
|
400
421
|
```
|
|
401
422
|
|
|
402
423
|
### Responsive Grid Layout Props
|
|
@@ -494,7 +515,6 @@ will be draggable, even if the item is marked `static: true`.
|
|
|
494
515
|
|
|
495
516
|
`<ReactGridLayout>` has [an optimized `shouldComponentUpdate` implementation](lib/ReactGridLayout.jsx), but it relies on the user memoizing the `children` array:
|
|
496
517
|
|
|
497
|
-
|
|
498
518
|
```js
|
|
499
519
|
// lib/ReactGridLayout.jsx
|
|
500
520
|
// ...
|
|
@@ -517,7 +537,7 @@ If you memoize your children, you can take advantage of this, and reap faster re
|
|
|
517
537
|
function MyGrid(props) {
|
|
518
538
|
const children = React.useMemo(() => {
|
|
519
539
|
return new Array(props.count).fill(undefined).map((val, idx) => {
|
|
520
|
-
return <div key={idx} data-grid={{x: idx, y: 1, w: 1, h: 1}} />;
|
|
540
|
+
return <div key={idx} data-grid={{ x: idx, y: 1, w: 1, h: 1 }} />;
|
|
521
541
|
});
|
|
522
542
|
}, [props.count]);
|
|
523
543
|
return <ReactGridLayout cols={12}>{children}</ReactGridLayout>;
|
|
@@ -540,7 +560,7 @@ const CustomGridItemComponent = React.forwardRef(({style, className, ...props},
|
|
|
540
560
|
return (
|
|
541
561
|
<div style={{ /* styles */, ...style}} className={className} ref={ref}>
|
|
542
562
|
{/* Some other content */}
|
|
543
|
-
</div>
|
|
563
|
+
</div>
|
|
544
564
|
);
|
|
545
565
|
}
|
|
546
566
|
```
|
package/build/utils.js
CHANGED
|
@@ -779,8 +779,7 @@ function synchronizeLayoutWithChildren(initialLayout
|
|
|
779
779
|
layout.push(cloneLayoutItem(exists));
|
|
780
780
|
} else {
|
|
781
781
|
if (!isProduction && child.props._grid) {
|
|
782
|
-
console.warn("`_grid` properties on children have been deprecated as of React 15.2. " +
|
|
783
|
-
"Please use `data-grid` or add your properties directly to the `layout`.");
|
|
782
|
+
console.warn("`_grid` properties on children have been deprecated as of React 15.2. " + "Please use `data-grid` or add your properties directly to the `layout`.");
|
|
784
783
|
}
|
|
785
784
|
|
|
786
785
|
var g = child.props["data-grid"] || child.props._grid; // Hey, this item has a data-grid property, use it.
|
|
@@ -842,14 +841,6 @@ function validateLayout(layout
|
|
|
842
841
|
throw new Error("ReactGridLayout: " + contextName + "[" + i + "]." + subProps[j] + " must be a number!");
|
|
843
842
|
}
|
|
844
843
|
}
|
|
845
|
-
|
|
846
|
-
if (item.i && typeof item.i !== "string") {
|
|
847
|
-
throw new Error("ReactGridLayout: " + contextName + "[" + i + "].i must be a string!");
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
if (item.static !== undefined && typeof item.static !== "boolean") {
|
|
851
|
-
throw new Error("ReactGridLayout: " + contextName + "[" + i + "].static must be a boolean!");
|
|
852
|
-
}
|
|
853
844
|
}
|
|
854
845
|
} // Legacy support for verticalCompact: false
|
|
855
846
|
|