You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`DisplayComponent`: is a react component to display in your grid
34
+
*`displayProps`: *optional* : are properties you want passed down to the DisplayComponent such as event handlers.
35
+
*`forceImpure`: *optional* : **not recommended** Will make this function as an impure component, meaning it always renders.
23
36
37
+
Options (Properties)
38
+
------
24
39
| Property | Default | Description |
25
40
|---|:---:|---|
26
41
|**items**|[]| The array of items in the grid |
27
-
|**displayObject**| (required) | The React component to render items |
28
42
|**keyProp**| 'key' | The property to be used as a key |
29
43
|**filterProp**| 'filtered' | The property to be used for filtering, if the filtered value is true, the item won't be displayed. It's important to not remove items from the array because that will cause React to remove the DOM, for performance we would rather hide it then remove it. |
30
44
|**sortProp**| 'sort' | The property to sort on |
@@ -36,47 +50,51 @@ Options (Properties)
36
50
|**animation**| 'transform 300ms ease' | The CSS animation to use on elements. Pass a blank string or `false` for no animation. |
37
51
|**zoom**| 1 | Zooms the contents of the grid, 1 = 100% |
38
52
|**onMove**|`fn(from, to)`| This function is called when an item is dragged over another item. It is your responsibility to update the sort of all items when this happens. |
53
+
|**onDragStart**|`fn(e)`| This function is called when an item starts dragging, this is NOT required. |
54
+
|**onDragMove**|`fn(e)`| This function is called when as an item is being moved, this is NOT required. |
55
+
|**onDragEnd**|`fn(e)`| This function is called when an item has finished its drag, this is NOT required. |
39
56
40
-
Creating a DisplayObject component
57
+
Your Component
41
58
------
42
-
displayObject component will receive `item`, `index` and `itemsLength` as props. Here's the simplest possible example:
43
-
44
-
import React from 'react';
45
-
46
-
export default class SampleDisplay extends React.Component {
47
-
48
-
render() {
49
-
// Supposing your item shape is something like {name: 'foo'}
50
-
const { item, index, itemsLength } = this.props;
51
-
return <div>Item {index} of {itemsLength}: {item.name}</div>;
52
-
}
53
-
}
59
+
Your component will receive `item`, `index` and `itemsLength` as props, as well as anything you pass into the createAbsoluteGrid function. Here's the simplest possible example:
54
60
55
-
Once you've created a display object, use it like this:
61
+
```javascript
62
+
importReactfrom'react';
56
63
57
-
var grid = (<AbsoluteGrid ... displayObject={(<SampleDisplay {...pass props normally} />)}/>);
64
+
exportdefaultfunctionSampleDisplay(props) {
65
+
// Supposing your item shape is something like {name: 'foo'}
66
+
const { item, index, itemsLength } = props;
67
+
return<div>Item {index} of {itemsLength}: {item.name}</div>;
68
+
}
69
+
```
58
70
59
71
What Makes AbsoluteGrid Unique?
60
72
----
61
-
The idea behind AbsoluteGrid is high performance. This is achieved by using Translate3d to position each item in the layout. Items are never removed from the DOM, instead they are hidden. For best performance you should avoid re-arranging or removing items which you pass into AbsoluteGrid, instead you can use the `filtered` and `sort` properties to hide or sort an item. Those properties are customizable using the `keyProp` and `filterProp` properties.
73
+
The idea behind AbsoluteGrid is high performance. This is achieved by using Translate3d to position each item in the layout. Items are never removed from the DOM, instead they are hidden. For best performance you should avoid re-arranging or removing items which you pass into AbsoluteGrid, instead you can use the `filtered` and `sort` properties to hide or sort an item. Those properties are customizable using the `keyProp` and `filterProp` properties. In addition, all data passed must be immutable so that we don't waste any renders.
62
74
63
-
DisplayObject props
75
+
Your Display Component props
64
76
----
65
-
Each DisplayObject component is passed the following props.
77
+
Each Component is passed the following props, as well as anything passed into the second parameter of `createAbsoluteGrid`
66
78
67
79
| Property | Description |
68
80
|---|:---|
69
81
|**item**| The data associated with the GridItem |
70
82
|**index**| The index of the item data in the `items` array |
71
83
|**itemsLength**| The total length of the `items` array |
72
-
84
+
|**...displayProps**| props passed into `createAbsoluteGrid`|
73
85
74
86
ToDo:
75
87
-----
88
+
* Tests
76
89
* Improve Drag & Drop browser support and reliability
77
90
78
91
Browser Compatibility
79
92
-----
80
93
This component should work in all browsers that [support CSS3 3D Transforms](http://caniuse.com/#feat=transforms3d). If you need IE9 support you can modify it to use transform rather than transform3d. Pull requests welcome!
81
94
82
95
Drag and Drop only works on IE11+ due to lack of pointer events, although there is a workaround coming soon.
96
+
97
+
Migrating from 2.x
98
+
-----
99
+
100
+
Instead of passing `displayObject` to the AbsoluteGrid component, pass the component directly into the composer function, `createAbsoluteGrid` which returns an AbsoluteGrid component. That's it!
0 commit comments