react-grid-layout 1.2.0 → 1.2.4

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/lib/GridItem.jsx CHANGED
@@ -1,6 +1,5 @@
1
1
  // @flow
2
2
  import React from "react";
3
- import ReactDOM from "react-dom";
4
3
  import PropTypes from "prop-types";
5
4
  import { DraggableCore } from "react-draggable";
6
5
  import { Resizable } from "react-resizable";
@@ -29,7 +28,11 @@ import type {
29
28
  } from "./utils";
30
29
 
31
30
  import type { PositionParams } from "./calculateUtils";
32
- import type { ResizeHandles, ResizeHandle } from "./ReactGridLayoutPropTypes";
31
+ import type {
32
+ ResizeHandles,
33
+ ResizeHandle,
34
+ ReactRef
35
+ } from "./ReactGridLayoutPropTypes";
33
36
 
34
37
  type PartialPosition = { top: number, left: number };
35
38
  type GridItemCallback<Data: GridDragEvent | GridResizeEvent> = (
@@ -90,6 +93,17 @@ type Props = {
90
93
  onResizeStop?: GridItemCallback<GridResizeEvent>
91
94
  };
92
95
 
96
+ type DefaultProps = {
97
+ className: string,
98
+ cancel: string,
99
+ handle: string,
100
+ minH: number,
101
+ minW: number,
102
+ maxH: number,
103
+ maxW: number,
104
+ transformScale: number
105
+ };
106
+
93
107
  /**
94
108
  * An individual item within a ReactGridLayout.
95
109
  */
@@ -180,7 +194,7 @@ export default class GridItem extends React.Component<Props, State> {
180
194
  })
181
195
  };
182
196
 
183
- static defaultProps = {
197
+ static defaultProps: DefaultProps = {
184
198
  className: "",
185
199
  cancel: "",
186
200
  handle: "",
@@ -197,9 +211,9 @@ export default class GridItem extends React.Component<Props, State> {
197
211
  className: ""
198
212
  };
199
213
 
200
- currentNode: HTMLElement;
214
+ elementRef: ReactRef<HTMLDivElement> = React.createRef();
201
215
 
202
- shouldComponentUpdate(nextProps: Props, nextState: State) {
216
+ shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
203
217
  // We can't deeply compare children. If the developer memoizes them, we can
204
218
  // use this optimization.
205
219
  if (this.props.children !== nextProps.children) return true;
@@ -240,6 +254,9 @@ export default class GridItem extends React.Component<Props, State> {
240
254
  moveDroppingItem(prevProps: Props) {
241
255
  const { droppingPosition } = this.props;
242
256
  if (!droppingPosition) return;
257
+ const node = this.elementRef.current;
258
+ // Can't find DOM node (are we unmounted?)
259
+ if (!node) return;
243
260
 
244
261
  const prevDroppingPosition = prevProps.droppingPosition || {
245
262
  left: 0,
@@ -247,18 +264,13 @@ export default class GridItem extends React.Component<Props, State> {
247
264
  };
248
265
  const { dragging } = this.state;
249
266
 
250
- if (!this.currentNode) {
251
- // eslint-disable-next-line react/no-find-dom-node
252
- this.currentNode = ((ReactDOM.findDOMNode(this): any): HTMLElement);
253
- }
254
-
255
267
  const shouldDrag =
256
268
  (dragging && droppingPosition.left !== prevDroppingPosition.left) ||
257
269
  droppingPosition.top !== prevDroppingPosition.top;
258
270
 
259
271
  if (!dragging) {
260
272
  this.onDragStart(droppingPosition.e, {
261
- node: this.currentNode,
273
+ node,
262
274
  deltaX: droppingPosition.left,
263
275
  deltaY: droppingPosition.top
264
276
  });
@@ -267,7 +279,7 @@ export default class GridItem extends React.Component<Props, State> {
267
279
  const deltaY = droppingPosition.top - dragging.top;
268
280
 
269
281
  this.onDrag(droppingPosition.e, {
270
- node: this.currentNode,
282
+ node,
271
283
  deltaX,
272
284
  deltaY
273
285
  });
@@ -337,6 +349,7 @@ export default class GridItem extends React.Component<Props, State> {
337
349
  (this.props.cancel ? "," + this.props.cancel : "")
338
350
  }
339
351
  scale={this.props.transformScale}
352
+ nodeRef={this.elementRef}
340
353
  >
341
354
  {child}
342
355
  </DraggableCore>
@@ -382,7 +395,8 @@ export default class GridItem extends React.Component<Props, State> {
382
395
  return (
383
396
  <Resizable
384
397
  draggableOpts={{
385
- disabled: !isResizable
398
+ disabled: !isResizable,
399
+ nodeRef: this.elementRef
386
400
  }}
387
401
  className={isResizable ? undefined : "react-resizable-hide"}
388
402
  width={position.width}
@@ -406,8 +420,8 @@ export default class GridItem extends React.Component<Props, State> {
406
420
  * @param {Event} e event data
407
421
  * @param {Object} callbackData an object with node, delta and position information
408
422
  */
409
- onDragStart = (e: Event, { node }: ReactDraggableCallbackData) => {
410
- const { onDragStart } = this.props;
423
+ onDragStart: (Event, ReactDraggableCallbackData) => void = (e, { node }) => {
424
+ const { onDragStart, transformScale } = this.props;
411
425
  if (!onDragStart) return;
412
426
 
413
427
  const newPosition: PartialPosition = { top: 0, left: 0 };
@@ -417,10 +431,10 @@ export default class GridItem extends React.Component<Props, State> {
417
431
  if (!offsetParent) return;
418
432
  const parentRect = offsetParent.getBoundingClientRect();
419
433
  const clientRect = node.getBoundingClientRect();
420
- const cLeft = clientRect.left / this.props.transformScale;
421
- const pLeft = parentRect.left / this.props.transformScale;
422
- const cTop = clientRect.top / this.props.transformScale;
423
- const pTop = parentRect.top / this.props.transformScale;
434
+ const cLeft = clientRect.left / transformScale;
435
+ const pLeft = parentRect.left / transformScale;
436
+ const cTop = clientRect.top / transformScale;
437
+ const pTop = parentRect.top / transformScale;
424
438
  newPosition.left = cLeft - pLeft + offsetParent.scrollLeft;
425
439
  newPosition.top = cTop - pTop + offsetParent.scrollTop;
426
440
  this.setState({ dragging: newPosition });
@@ -446,11 +460,12 @@ export default class GridItem extends React.Component<Props, State> {
446
460
  * @param {Event} e event data
447
461
  * @param {Object} callbackData an object with node, delta and position information
448
462
  */
449
- onDrag = (e: Event, { node, deltaX, deltaY }: ReactDraggableCallbackData) => {
450
- const { onDrag, transformScale } = this.props;
463
+ onDrag: (Event, ReactDraggableCallbackData) => void = (
464
+ e,
465
+ { node, deltaX, deltaY }
466
+ ) => {
467
+ const { onDrag } = this.props;
451
468
  if (!onDrag) return;
452
- deltaX /= transformScale;
453
- deltaY /= transformScale;
454
469
 
455
470
  if (!this.state.dragging) {
456
471
  throw new Error("onDrag called before onDragStart.");
@@ -495,7 +510,7 @@ export default class GridItem extends React.Component<Props, State> {
495
510
  * @param {Event} e event data
496
511
  * @param {Object} callbackData an object with node, delta and position information
497
512
  */
498
- onDragStop = (e: Event, { node }: ReactDraggableCallbackData) => {
513
+ onDragStop: (Event, ReactDraggableCallbackData) => void = (e, { node }) => {
499
514
  const { onDragStop } = this.props;
500
515
  if (!onDragStop) return;
501
516
 
@@ -521,9 +536,9 @@ export default class GridItem extends React.Component<Props, State> {
521
536
  * @param {Event} e event data
522
537
  * @param {Object} callbackData an object with node and size information
523
538
  */
524
- onResizeStop = (
525
- e: Event,
526
- callbackData: { node: HTMLElement, size: Position }
539
+ onResizeStop: (Event, { node: HTMLElement, size: Position }) => void = (
540
+ e,
541
+ callbackData
527
542
  ) => {
528
543
  this.onResizeHandler(e, callbackData, "onResizeStop");
529
544
  };
@@ -533,9 +548,9 @@ export default class GridItem extends React.Component<Props, State> {
533
548
  * @param {Event} e event data
534
549
  * @param {Object} callbackData an object with node and size information
535
550
  */
536
- onResizeStart = (
537
- e: Event,
538
- callbackData: { node: HTMLElement, size: Position }
551
+ onResizeStart: (Event, { node: HTMLElement, size: Position }) => void = (
552
+ e,
553
+ callbackData
539
554
  ) => {
540
555
  this.onResizeHandler(e, callbackData, "onResizeStart");
541
556
  };
@@ -545,9 +560,9 @@ export default class GridItem extends React.Component<Props, State> {
545
560
  * @param {Event} e event data
546
561
  * @param {Object} callbackData an object with node and size information
547
562
  */
548
- onResize = (
549
- e: Event,
550
- callbackData: { node: HTMLElement, size: Position }
563
+ onResize: (Event, { node: HTMLElement, size: Position }) => void = (
564
+ e,
565
+ callbackData
551
566
  ) => {
552
567
  this.onResizeHandler(e, callbackData, "onResize");
553
568
  };
@@ -564,7 +579,7 @@ export default class GridItem extends React.Component<Props, State> {
564
579
  e: Event,
565
580
  { node, size }: { node: HTMLElement, size: Position },
566
581
  handlerName: string
567
- ) {
582
+ ): void {
568
583
  const handler = this.props[handlerName];
569
584
  if (!handler) return;
570
585
  const { cols, x, y, i, maxH, minH } = this.props;
@@ -618,6 +633,7 @@ export default class GridItem extends React.Component<Props, State> {
618
633
 
619
634
  // Create the child element. We clone the existing element but modify its className and style.
620
635
  let newChild = React.cloneElement(child, {
636
+ ref: this.elementRef,
621
637
  className: classNames(
622
638
  "react-grid-item",
623
639
  child.props.className,
@@ -1,5 +1,5 @@
1
1
  // @flow
2
- import React from "react";
2
+ import * as React from "react";
3
3
 
4
4
  import isEqual from "lodash.isequal";
5
5
  import classNames from "classnames";
@@ -9,13 +9,14 @@ import {
9
9
  childrenEqual,
10
10
  cloneLayoutItem,
11
11
  compact,
12
+ compactType,
13
+ fastRGLPropsEqual,
14
+ getAllCollisions,
12
15
  getLayoutItem,
13
16
  moveElement,
14
- synchronizeLayoutWithChildren,
15
- getAllCollisions,
16
- compactType,
17
17
  noop,
18
- fastRGLPropsEqual
18
+ synchronizeLayoutWithChildren,
19
+ withLayoutItem
19
20
  } from "./utils";
20
21
 
21
22
  import { calcXY } from "./calculateUtils";
@@ -55,7 +56,7 @@ type State = {
55
56
  propsLayout?: Layout
56
57
  };
57
58
 
58
- import type { Props } from "./ReactGridLayoutPropTypes";
59
+ import type { Props, DefaultProps } from "./ReactGridLayoutPropTypes";
59
60
 
60
61
  // End Types
61
62
 
@@ -74,12 +75,12 @@ try {
74
75
 
75
76
  export default class ReactGridLayout extends React.Component<Props, State> {
76
77
  // TODO publish internal ReactClass displayName transform
77
- static displayName = "ReactGridLayout";
78
+ static displayName: ?string = "ReactGridLayout";
78
79
 
79
80
  // Refactored to another module to make way for preval
80
81
  static propTypes = ReactGridLayoutPropTypes;
81
82
 
82
- static defaultProps = {
83
+ static defaultProps: DefaultProps = {
83
84
  autoSize: true,
84
85
  cols: 12,
85
86
  className: "",
@@ -133,7 +134,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
133
134
  children: []
134
135
  };
135
136
 
136
- dragEnterCounter = 0;
137
+ dragEnterCounter: number = 0;
137
138
 
138
139
  constructor(props: Props, context: any): void {
139
140
  super(props, context);
@@ -154,7 +155,10 @@ export default class ReactGridLayout extends React.Component<Props, State> {
154
155
  this.onLayoutMaybeChanged(this.state.layout, this.props.layout);
155
156
  }
156
157
 
157
- static getDerivedStateFromProps(nextProps: Props, prevState: State) {
158
+ static getDerivedStateFromProps(
159
+ nextProps: Props,
160
+ prevState: State
161
+ ): $Shape<State> | null {
158
162
  let newLayoutBase;
159
163
 
160
164
  if (prevState.activeDrag) {
@@ -197,7 +201,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
197
201
  return null;
198
202
  }
199
203
 
200
- shouldComponentUpdate(nextProps: Props, nextState: State) {
204
+ shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
201
205
  return (
202
206
  // NOTE: this is almost always unequal. Therefore the only way to get better performance
203
207
  // from SCU is if the user intentionally memoizes children. If they do, and they can
@@ -223,7 +227,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
223
227
  * Calculates a pixel value for the container.
224
228
  * @return {String} Container height in pixels.
225
229
  */
226
- containerHeight() {
230
+ containerHeight(): ?string {
227
231
  if (!this.props.autoSize) return;
228
232
  const nbRow = bottom(this.state.layout);
229
233
  const containerPaddingY = this.props.containerPadding
@@ -245,9 +249,14 @@ export default class ReactGridLayout extends React.Component<Props, State> {
245
249
  * @param {Event} e The mousedown event
246
250
  * @param {Element} node The current dragging DOM element
247
251
  */
248
- onDragStart(i: string, x: number, y: number, { e, node }: GridDragEvent) {
252
+ onDragStart(
253
+ i: string,
254
+ x: number,
255
+ y: number,
256
+ { e, node }: GridDragEvent
257
+ ): void {
249
258
  const { layout } = this.state;
250
- var l = getLayoutItem(layout, i);
259
+ const l = getLayoutItem(layout, i);
251
260
  if (!l) return;
252
261
 
253
262
  this.setState({
@@ -266,15 +275,15 @@ export default class ReactGridLayout extends React.Component<Props, State> {
266
275
  * @param {Event} e The mousedown event
267
276
  * @param {Element} node The current dragging DOM element
268
277
  */
269
- onDrag(i: string, x: number, y: number, { e, node }: GridDragEvent) {
278
+ onDrag(i: string, x: number, y: number, { e, node }: GridDragEvent): void {
270
279
  const { oldDragItem } = this.state;
271
280
  let { layout } = this.state;
272
281
  const { cols } = this.props;
273
- var l = getLayoutItem(layout, i);
282
+ const l = getLayoutItem(layout, i);
274
283
  if (!l) return;
275
284
 
276
285
  // Create placeholder (display only)
277
- var placeholder = {
286
+ const placeholder = {
278
287
  w: l.w,
279
288
  h: l.h,
280
289
  x: l.x,
@@ -312,7 +321,12 @@ export default class ReactGridLayout extends React.Component<Props, State> {
312
321
  * @param {Event} e The mousedown event
313
322
  * @param {Element} node The current dragging DOM element
314
323
  */
315
- onDragStop(i: string, x: number, y: number, { e, node }: GridDragEvent) {
324
+ onDragStop(
325
+ i: string,
326
+ x: number,
327
+ y: number,
328
+ { e, node }: GridDragEvent
329
+ ): void {
316
330
  if (!this.state.activeDrag) return;
317
331
 
318
332
  const { oldDragItem } = this.state;
@@ -359,7 +373,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
359
373
 
360
374
  onResizeStart(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
361
375
  const { layout } = this.state;
362
- var l = getLayoutItem(layout, i);
376
+ const l = getLayoutItem(layout, i);
363
377
  if (!l) return;
364
378
 
365
379
  this.setState({
@@ -373,41 +387,46 @@ export default class ReactGridLayout extends React.Component<Props, State> {
373
387
  onResize(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
374
388
  const { layout, oldResizeItem } = this.state;
375
389
  const { cols, preventCollision } = this.props;
376
- const l: ?LayoutItem = getLayoutItem(layout, i);
377
- if (!l) return;
378
390
 
379
- // Something like quad tree should be used
380
- // to find collisions faster
381
- let hasCollisions;
382
- if (preventCollision) {
383
- const collisions = getAllCollisions(layout, { ...l, w, h }).filter(
384
- layoutItem => layoutItem.i !== l.i
385
- );
386
- hasCollisions = collisions.length > 0;
387
-
388
- // If we're colliding, we need adjust the placeholder.
389
- if (hasCollisions) {
390
- // adjust w && h to maximum allowed space
391
- let leastX = Infinity,
392
- leastY = Infinity;
393
- collisions.forEach(layoutItem => {
394
- if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
395
- if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
396
- });
397
-
398
- if (Number.isFinite(leastX)) l.w = leastX - l.x;
399
- if (Number.isFinite(leastY)) l.h = leastY - l.y;
391
+ const [newLayout, l] = withLayoutItem(layout, i, l => {
392
+ // Something like quad tree should be used
393
+ // to find collisions faster
394
+ let hasCollisions;
395
+ if (preventCollision) {
396
+ const collisions = getAllCollisions(layout, { ...l, w, h }).filter(
397
+ layoutItem => layoutItem.i !== l.i
398
+ );
399
+ hasCollisions = collisions.length > 0;
400
+
401
+ // If we're colliding, we need adjust the placeholder.
402
+ if (hasCollisions) {
403
+ // adjust w && h to maximum allowed space
404
+ let leastX = Infinity,
405
+ leastY = Infinity;
406
+ collisions.forEach(layoutItem => {
407
+ if (layoutItem.x > l.x) leastX = Math.min(leastX, layoutItem.x);
408
+ if (layoutItem.y > l.y) leastY = Math.min(leastY, layoutItem.y);
409
+ });
410
+
411
+ if (Number.isFinite(leastX)) l.w = leastX - l.x;
412
+ if (Number.isFinite(leastY)) l.h = leastY - l.y;
413
+ }
400
414
  }
401
- }
402
415
 
403
- if (!hasCollisions) {
404
- // Set new width and height.
405
- l.w = w;
406
- l.h = h;
407
- }
416
+ if (!hasCollisions) {
417
+ // Set new width and height.
418
+ l.w = w;
419
+ l.h = h;
420
+ }
421
+
422
+ return l;
423
+ });
424
+
425
+ // Shouldn't ever happen, but typechecking makes it necessary
426
+ if (!l) return;
408
427
 
409
428
  // Create placeholder element (display only)
410
- var placeholder = {
429
+ const placeholder = {
411
430
  w: l.w,
412
431
  h: l.h,
413
432
  x: l.x,
@@ -416,11 +435,11 @@ export default class ReactGridLayout extends React.Component<Props, State> {
416
435
  i: i
417
436
  };
418
437
 
419
- this.props.onResize(layout, oldResizeItem, l, placeholder, e, node);
438
+ this.props.onResize(newLayout, oldResizeItem, l, placeholder, e, node);
420
439
 
421
- // Re-compact the layout and set the drag placeholder.
440
+ // Re-compact the newLayout and set the drag placeholder.
422
441
  this.setState({
423
- layout: compact(layout, compactType(this.props), cols),
442
+ layout: compact(newLayout, compactType(this.props), cols),
424
443
  activeDrag: placeholder
425
444
  });
426
445
  }
@@ -428,7 +447,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
428
447
  onResizeStop(i: string, w: number, h: number, { e, node }: GridResizeEvent) {
429
448
  const { layout, oldResizeItem } = this.state;
430
449
  const { cols } = this.props;
431
- var l = getLayoutItem(layout, i);
450
+ const l = getLayoutItem(layout, i);
432
451
 
433
452
  this.props.onResizeStop(layout, oldResizeItem, l, null, e, node);
434
453
 
@@ -579,13 +598,14 @@ export default class ReactGridLayout extends React.Component<Props, State> {
579
598
 
580
599
  // Called while dragging an element. Part of browser native drag/drop API.
581
600
  // Native event target might be the layout itself, or an element within the layout.
582
- onDragOver = (e: DragOverEvent) => {
601
+ onDragOver: DragOverEvent => void | false = e => {
583
602
  // we should ignore events from layout's children in Firefox
584
603
  // to avoid unpredictable jumping of a dropping placeholder
585
604
  // FIXME remove this hack
586
605
  if (
587
606
  isFirefox &&
588
- e.nativeEvent.target.className.indexOf(layoutClassName) === -1
607
+ // $FlowIgnore can't figure this out
608
+ !e.nativeEvent.target?.classList.contains(layoutClassName)
589
609
  ) {
590
610
  // without this Firefox will not allow drop if currently over droppingItem
591
611
  e.preventDefault();
@@ -650,7 +670,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
650
670
  e.preventDefault();
651
671
  };
652
672
 
653
- removeDroppingPlaceholder = () => {
673
+ removeDroppingPlaceholder: () => void = () => {
654
674
  const { droppingItem, cols } = this.props;
655
675
  const { layout } = this.state;
656
676
 
@@ -668,7 +688,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
668
688
  });
669
689
  };
670
690
 
671
- onDragLeave = () => {
691
+ onDragLeave: () => void = () => {
672
692
  this.dragEnterCounter--;
673
693
 
674
694
  // onDragLeave can be triggered on each layout's child.
@@ -681,11 +701,11 @@ export default class ReactGridLayout extends React.Component<Props, State> {
681
701
  }
682
702
  };
683
703
 
684
- onDragEnter = () => {
704
+ onDragEnter: () => void = () => {
685
705
  this.dragEnterCounter++;
686
706
  };
687
707
 
688
- onDrop = (e: Event) => {
708
+ onDrop: EventHandler = (e: Event) => {
689
709
  const { droppingItem } = this.props;
690
710
  const { layout } = this.state;
691
711
  const item = layout.find(l => l.i === droppingItem.i);
@@ -698,7 +718,7 @@ export default class ReactGridLayout extends React.Component<Props, State> {
698
718
  this.props.onDrop(layout, item, e);
699
719
  };
700
720
 
701
- render() {
721
+ render(): React.Element<"div"> {
702
722
  const { className, style, isDroppable, innerRef } = this.props;
703
723
 
704
724
  const mergedClassName = classNames(layoutClassName, className);
@@ -14,6 +14,11 @@ export type ResizeHandle =
14
14
  | ReactElement<any>
15
15
  | ((resizeHandleAxis: ResizeHandleAxis) => ReactElement<any>);
16
16
 
17
+ // util
18
+ export type ReactRef<T: HTMLElement> = {|
19
+ +current: T | null
20
+ |};
21
+
17
22
  // Defines which resize handles should be rendered (default: 'se')
18
23
  // Allows for any combination of:
19
24
  // 's' - South handle (bottom-center)
@@ -24,14 +29,13 @@ export type ResizeHandle =
24
29
  // 'nw' - Northwest handle (top-left)
25
30
  // 'se' - Southeast handle (bottom-right)
26
31
  // 'ne' - Northeast handle (top-right)
27
- export const resizeHandlesType = PropTypes.arrayOf(
32
+ export const resizeHandlesType: ReactPropsChainableTypeChecker = PropTypes.arrayOf(
28
33
  PropTypes.oneOf(["s", "w", "e", "n", "sw", "nw", "se", "ne"])
29
34
  );
30
35
  // Custom component for resize handles
31
- export const resizeHandleType = PropTypes.oneOfType([
32
- PropTypes.node,
33
- PropTypes.func
34
- ]);
36
+ export const resizeHandleType: ReactPropsChainableTypeChecker = PropTypes.oneOfType(
37
+ [PropTypes.node, PropTypes.func]
38
+ );
35
39
 
36
40
  export type Props = {|
37
41
  className: string,
@@ -72,6 +76,14 @@ export type Props = {|
72
76
  innerRef?: Ref<"div">
73
77
  |};
74
78
 
79
+ export type DefaultProps = $Diff<
80
+ Props,
81
+ {
82
+ children: ReactChildrenArray<ReactElement<any>>,
83
+ width: number
84
+ }
85
+ >;
86
+
75
87
  export default {
76
88
  //
77
89
  // Basic props
@@ -108,7 +120,10 @@ export default {
108
120
  }
109
121
  },
110
122
  // Choose vertical or hotizontal compaction
111
- compactType: PropTypes.oneOf(["vertical", "horizontal"]),
123
+ compactType: (PropTypes.oneOf([
124
+ "vertical",
125
+ "horizontal"
126
+ ]): ReactPropsChainableTypeChecker),
112
127
 
113
128
  // layout is an array of object with the format:
114
129
  // {x: Number, y: Number, w: Number, h: Number, i: String}
@@ -124,9 +139,11 @@ export default {
124
139
  //
125
140
 
126
141
  // Margin between items [x, y] in px
127
- margin: PropTypes.arrayOf(PropTypes.number),
142
+ margin: (PropTypes.arrayOf(PropTypes.number): ReactPropsChainableTypeChecker),
128
143
  // Padding inside the container [x, y] in px
129
- containerPadding: PropTypes.arrayOf(PropTypes.number),
144
+ containerPadding: (PropTypes.arrayOf(
145
+ PropTypes.number
146
+ ): ReactPropsChainableTypeChecker),
130
147
  // Rows have a static height, but you can change this based on breakpoints if you like
131
148
  rowHeight: PropTypes.number,
132
149
  // Default Infinity, but you can specify a max here if you like.
@@ -182,11 +199,11 @@ export default {
182
199
  // Other validations
183
200
  //
184
201
 
185
- droppingItem: PropTypes.shape({
202
+ droppingItem: (PropTypes.shape({
186
203
  i: PropTypes.string.isRequired,
187
204
  w: PropTypes.number.isRequired,
188
205
  h: PropTypes.number.isRequired
189
- }),
206
+ }): ReactPropsChainableTypeChecker),
190
207
 
191
208
  // Children must not have duplicate keys.
192
209
  children: function (props: Props, propName: string) {