forked from react-grid-layout/react-grid-layout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
445 lines (373 loc) · 12.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
// Type definitions for react-grid-layout 1.3
// Project: https://github.com/STRML/react-grid-layout
// Definitions by: Andrew Birkholz <https://github.com/abirkholz>
// Ali Taheri <https://github.com/alitaheri>
// Zheyang Song <https://github.com/ZheyangSong>
// Andrew Hathaway <https://github.com/andrewhathaway>
// Manav Mishra <https://github.com/manav-m>
// Alexey Fyodorov <https://github.com/al-fyodorov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
export as namespace ReactGridLayout;
export = ReactGridLayout;
declare class ReactGridLayout extends React.Component<ReactGridLayout.ReactGridLayoutProps> {}
type ResizeHandle = "s" | "w" | "e" | "n" | "sw" | "nw" | "se" | "ne";
declare namespace ReactGridLayout {
interface Layout {
/**
* A string corresponding to the component key.
* Uses the index of components instead if not provided.
*/
i: string;
/**
* X position in grid units.
*/
x: number;
/**
* Y position in grid units.
*/
y: number;
/**
* Width in grid units.
*/
w: number;
/**
* Height in grid units.
*/
h: number;
/**
* Minimum width in grid units.
*/
minW?: number | undefined;
/**
* Maximum width in grid units.
*/
maxW?: number | undefined;
/**
* Minimum height in grid units.
*/
minH?: number | undefined;
/**
* Maximum height in grid units.
*/
maxH?: number | undefined;
/**
* set by DragEvents (onDragStart, onDrag, onDragStop) and ResizeEvents (onResizeStart, onResize, onResizeStop)
*/
moved?: boolean | undefined;
/**
* If true, equal to `isDraggable: false` and `isResizable: false`.
*/
static?: boolean | undefined;
/**
* If false, will not be draggable. Overrides `static`.
*/
isDraggable?: boolean | undefined;
/**
* If false, will not be resizable. Overrides `static`.
*/
isResizable?: boolean | undefined;
/**
* By default, a handle is only shown on the bottom-right (southeast) corner.
* Note that resizing from the top or left is generally not intuitive.
*/
resizeHandles?: ResizeHandle[] | undefined;
/**
* If true and draggable, item will be moved only within grid.
*/
isBounded?: boolean | undefined;
}
interface Layouts {
[P: string]: Layout[];
}
type ItemCallback = (
layout: Layout[],
oldItem: Layout,
newItem: Layout,
placeholder: Layout,
event: MouseEvent,
element: HTMLElement
) => void;
type DragOverEvent = MouseEvent & {
nativeEvent: {
layerX: number;
layerY: number;
} & Event;
};
interface CoreProps {
/**
* The classname to add to the root element.
*/
className?: string | undefined;
/**
* Inline-style object to pass to the root element.
*/
style?: React.CSSProperties | undefined;
/**
* This allows setting the initial width on the server side.
* This is required unless using the HOC <WidthProvider> or similar.
*/
width?: number | undefined;
/**
* If true, the container height swells and contracts to fit contents.
*/
autoSize?: boolean | undefined;
/**
* A CSS selector for tags that will not be draggable.
* For example: `draggableCancel: '.MyNonDraggableAreaClassName'`
* If you forget the leading. it will not work.
* "".react-resizable-handle" is always prepended to this value.
*/
draggableCancel?: string | undefined;
/**
* A CSS selector for tags that will act as the draggable handle.
* For example: `draggableHandle: '.MyDragHandleClassName'`
* If you forget the leading . it will not work.
*/
draggableHandle?: string | undefined;
/**
* Compaction type.
*/
compactType?: "vertical" | "horizontal" | null | undefined;
/**
* Rows have a static height, but you can change this based on breakpoints if you like.
*/
rowHeight?: number | undefined;
/**
* Configuration of a dropping element. Dropping element is a "virtual" element
* which appears when you drag over some element from outside.
*/
droppingItem?:
| {
i: string;
w: number;
h: number;
}
| undefined;
/**
* If true, the layout will compact vertically.
*/
verticalCompact?: boolean | undefined;
/**
* Default Infinity, but you can specify a max here if you like.
* Note that this isn't fully fleshed out and won't error if you specify a layout that
* extends beyond the row capacity. It will, however, not allow users to drag/resize
* an item past the barrier. They can push items beyond the barrier, though.
* Intentionally not documented for this reason.
*/
maxRows?: number | undefined;
// Flags:
/**
* If set to false it will disable dragging on all children.
*/
isDraggable?: boolean | undefined;
/**
* If set to false it will disable resizing on all children.
*/
isResizable?: boolean | undefined;
/**
* If true and draggable, all items will be moved only within grid.
*/
isBounded?: boolean | undefined;
/**
* Uses CSS3 `translate()` instead of position top/left.
* This makes about 6x faster paint performance.
*/
useCSSTransforms?: boolean | undefined;
/**
* If parent DOM node of ResponsiveReactGridLayout or ReactGridLayout has "transform: scale(n)" css property,
* we should set scale coefficient to avoid render artefacts while dragging.
*/
transformScale?: number | undefined;
/**
* Direction
*/
transformDirection?: "rtl" | "ltr";
/**
* If true, grid can be placed one over the other.
*/
allowOverlap?: boolean | undefined;
/**
* If true, grid items won't change position when being dragged over.
*/
preventCollision?: boolean | undefined;
/**
* If true, droppable elements (with `draggable={true}` attribute)
* can be dropped on the grid. It triggers "onDrop" callback
* with position and event object as parameters.
* It can be useful for dropping an element in a specific position
* NOTE: In case of using Firefox you should add
* `onDragStart={e => e.dataTransfer.setData('text/plain', '')}` attribute
* along with `draggable={true}` otherwise this feature will work incorrect.
* onDragStart attribute is required for Firefox for a dragging initialization
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
*/
isDroppable?: boolean | undefined;
/**
* Defines which resize handles should be rendered
* Allows for any combination of:
* 's' - South handle (bottom-center)
* 'w' - West handle (left-center)
* 'e' - East handle (right-center)
* 'n' - North handle (top-center)
* 'sw' - Southwest handle (bottom-left)
* 'nw' - Northwest handle (top-left)
* 'se' - Southeast handle (bottom-right)
* 'ne' - Northeast handle (top-right)
*/
resizeHandles?: ResizeHandle[] | undefined;
/**
* Defines custom component for resize handle
*/
resizeHandle?:
| React.ReactNode
| ((resizeHandle: ResizeHandle) => React.ReactNode)
| undefined;
/**
* Calls when drag starts.
*/
onDragStart?: ItemCallback | undefined;
/**
* Calls on each drag movement.
*/
onDrag?: ItemCallback | undefined;
/**
* Calls when drag is complete.
*/
onDragStop?: ItemCallback | undefined;
/**
* Calls when resize starts.
*/
onResizeStart?: ItemCallback | undefined;
/**
* Calls when resize movement happens.
*/
onResize?: ItemCallback | undefined;
/**
* Calls when resize is complete.
*/
onResizeStop?: ItemCallback | undefined;
/**
* Calls when some element has been dropped
*/
onDrop?(layout: Layout[], item: Layout, e: Event): void;
/**
* Calls when an element is being dragged over the grid from outside as above.
* This callback should return an object to dynamically change the droppingItem size
* Return false to short-circuit the dragover
*/
onDropDragOver?(
e: DragOverEvent
): { w?: number; h?: number } | false | undefined;
/**
* Ref for getting a reference for the grid's wrapping div.
* You can use this instead of a regular ref and the deprecated `ReactDOM.findDOMNode()`` function.
*/
innerRef?: React.Ref<HTMLDivElement>;
}
interface ReactGridLayoutProps extends CoreProps {
children?: React.ReactNode;
/**
* Number of columns in this layout.
*/
cols?: number | undefined;
/**
* Margin between items `[x, y]` in px.
*/
margin?: [number, number] | undefined;
/**
* Padding inside the container `[x, y]` in px.
*/
containerPadding?: [number, number] | undefined;
/**
* Layout is an array of object with the format:
*
* `{x: number, y: number, w: number, h: number}`
*
* The index into the layout must match the key used on each item component.
* If you choose to use custom keys, you can specify that key in the layout
* array objects like so:
*
* `{i: string, x: number, y: number, w: number, h: number}`
*
* If not provided, use data-grid props on children.
*/
layout?: Layout[] | undefined;
/**
* Callback so you can save the layout.
* Calls back with (currentLayout) after every drag or resize stop.
*/
onLayoutChange?(layout: Layout[]): void;
}
interface ResponsiveProps extends CoreProps {
/**
* Optional, but if you are managing width yourself you may want to set the breakpoint
* yourself as well.
*/
breakpoint?: string | undefined;
/**
* `{name: pxVal}, e.g. {lg: 1200, md: 996, sm: 768, xs: 480}`
* Breakpoint names are arbitrary but must match in the cols and layouts objects.
*/
breakpoints?: { [P: string]: number } | undefined;
children?: React.ReactNode;
/**
* Number of cols. This is a breakpoint -> cols map, e.g. `{lg: 12, md: 10, ...}`.
*/
cols?: { [P: string]: number } | undefined;
/**
* Number of containerPadding. This is a breakpoint -> containerPadding map
* e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
* Padding inside the container [x, y] in px
* e.g. [10, 10]
*/
containerPadding?:
| [number, number]
| { [P: string]: [number, number] }
| undefined;
/**
* Layouts is an object mapping breakpoints to layouts.
* e.g. `{lg: Layout[], md: Layout[], ...}`
*/
layouts?: Layouts | undefined;
/**
* Number of margin. This is a breakpoint -> margin map
* e.g. { lg: [5, 5], md: [10, 10], sm: [15, 15] }
* Margin between items [x, y] in px
* e.g. [10, 10]
*/
margin?: [number, number] | { [P: string]: [number, number] } | undefined;
/**
* Calls back with breakpoint and new number pf cols.
*/
onBreakpointChange?(newBreakpoint: string, newCols: number): void;
/**
* Callback so you can save the layout.
* Calls back with (currentLayout, allLayouts). allLayouts are keyed by breakpoint.
*/
onLayoutChange?(currentLayout: Layout[], allLayouts: Layouts): void;
/**
* Callback that triggers when the width changes, so you can modify the layout as needed.
* Calls back with (containerWidth, margin, cols, containerPadding)
*/
onWidthChange?(
containerWidth: number,
margin: [number, number],
cols: number,
containerPadding: [number, number]
): void;
}
class Responsive extends React.Component<ResponsiveProps> {}
interface WidthProviderProps {
/**
* If true, WidthProvider will measure the container's width before mounting children.
* Use this if you'd like to completely eliminate any resizing animation on
* application/component mount.
*/
measureBeforeMount?: boolean | undefined;
}
function WidthProvider<P>(
component: React.ComponentClass<P> | React.FunctionComponent<P>
): React.ComponentClass<P & WidthProviderProps>;
}