@@ -18,31 +18,35 @@ Welcome to give any suggestions and ideas, you can submit an issue or contact me
18
18
19
19
## Usage
20
20
21
+ This is not an npm package, it's just a demo project. Please copy the ` src/lib ` code to your project to use it.
22
+
21
23
** Simple**
22
24
23
25
Render item with widget id selector.
24
26
27
+ Code here: [ src/examples/001-simple/index.tsx] ( src/examples/001-simple/index.tsx )
28
+
25
29
``` tsx
26
- function App () {
27
- const [uncontrolledInitialOptions] = useState <GridStackOptions >({
28
- // ...
30
+ function Simple () {
31
+ const [uncontrolledInitialOptions] = useState <GridStackOptions >(() => ( {
32
+ ... defaultGridOptions ,
29
33
children: [
30
34
{ id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 },
31
35
{ id: " item2" , h: 2 , w: 2 , x: 2 , y: 0 },
32
36
],
33
- });
37
+ })) ;
34
38
35
39
return (
36
40
<GridStackProvider initialOptions = { uncontrolledInitialOptions } >
37
41
<Toolbar />
38
42
39
- <GridStackRender >
43
+ <GridStackRender renderRawContent >
40
44
<GridStackItem id = " item1" >
41
- <div >hello</div >
45
+ <div style = { { color: " yellow " } } >hello</div >
42
46
</GridStackItem >
43
47
44
48
<GridStackItem id = " item2" >
45
- <div >grid</div >
49
+ <div style = { { color: " blue " } } >grid</div >
46
50
</GridStackItem >
47
51
</GridStackRender >
48
52
</GridStackProvider >
@@ -56,20 +60,59 @@ Render item with widget map component info.
56
60
57
61
_ ComponentInfoMap is just an example, you can use any way you want to store and retrieve component information._
58
62
63
+ Code here: [ src/examples/009-advanced/index.tsx] ( src/examples/009-advanced/index.tsx )
64
+
59
65
``` tsx
60
- function App() {
61
- const [uncontrolledInitialOptions] = useState <GridStackOptions >({
62
- // ...
66
+ function Advanced() {
67
+ // Data about layout by gridstack option
68
+ const [uncontrolledInitialOptions] = useState <GridStackOptions >(() => ({
69
+ ... defaultGridOptions ,
63
70
children: [
64
71
{ id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 },
65
72
{ id: " item2" , h: 2 , w: 2 , x: 2 , y: 0 },
73
+ {
74
+ id: " sub-grid-1" ,
75
+ h: 5 ,
76
+ sizeToContent: true ,
77
+ subGridOpts: {
78
+ children: [
79
+ {
80
+ id: " sub-grid-1-title" ,
81
+ locked: true ,
82
+ noMove: true ,
83
+ noResize: true ,
84
+ w: 12 ,
85
+ x: 0 ,
86
+ y: 0 ,
87
+ content: " Sub Grid 1" ,
88
+ },
89
+ { id: " item3" , h: 2 , w: 2 , x: 0 , y: 1 },
90
+ { id: " item4" , h: 2 , w: 2 , x: 2 , y: 0 },
91
+ ],
92
+ },
93
+ w: 4 ,
94
+ x: 0 ,
95
+ y: 2 ,
96
+ },
97
+ { id: " item5" , w: 4 , h: 4 , x: 0 , y: 2 },
66
98
],
67
- });
99
+ })) ;
68
100
101
+ // Data about every content
69
102
const [initialComponentInfoMap] = useState <Record <string , ComponentInfo >>(
70
103
() => ({
71
104
item1: { component: " Text" , serializableProps: { content: " Text" } },
72
- item2: {
105
+ item2: { component: " Text" , serializableProps: { content: " Text" } },
106
+ " sub-grid-1-title" : {
107
+ component: " Text" ,
108
+ serializableProps: { content: " Sub Grid 1" },
109
+ },
110
+ item3: { component: " Text" , serializableProps: { content: " Text" } },
111
+ item4: {
112
+ component: " Counter" ,
113
+ serializableProps: { label: " Click me" },
114
+ },
115
+ item5: {
73
116
component: " ComplexCard" ,
74
117
serializableProps: { title: " Complex Card" , color: " red" },
75
118
},
@@ -89,7 +132,7 @@ function App() {
89
132
);
90
133
}
91
134
92
- export function DynamicGridStackItems() {
135
+ function DynamicGridStackItems() {
93
136
const { componentInfoMap } = useComponentInfoMap ();
94
137
95
138
return (
@@ -117,6 +160,8 @@ export function DynamicGridStackItems() {
117
160
);
118
161
}
119
162
163
+ // ... more render conditions here
164
+
120
165
return (
121
166
<GridStackItem key = { widgetId } id = { widgetId } >
122
167
<Component { ... props } key = { ` component-${widgetId } ` } />
@@ -133,14 +178,32 @@ export function DynamicGridStackItems() {
133
178
134
179
Render item with custom handle.
135
180
181
+ Code here: [ src/examples/003-custom-handle/index.tsx] ( src/examples/003-custom-handle/index.tsx )
182
+
136
183
``` tsx
137
- <GridStackItem id = " xxx" >
138
- <GridStackHandleReInitializer >
139
- <button className = { CUSTOM_DRAGGABLE_HANDLE_CLASSNAME } >
140
- Handle ONLY HERE
141
- </button >
142
- </GridStackHandleReInitializer >
143
- </GridStackItem >
184
+ function CustomHandle() {
185
+ const [uncontrolledInitialOptions] = useState <GridStackOptions >(() => ({
186
+ ... defaultGridOptions ,
187
+ children: [{ id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 }],
188
+ }));
189
+
190
+ return (
191
+ <GridStackProvider initialOptions = { uncontrolledInitialOptions } >
192
+ <GridStackRender renderRawContent >
193
+ <GridStackItem id = " item1" >
194
+ <div >Custom Handle</div >
195
+
196
+ { /* Experimental: Render item with custom handle */ }
197
+ <GridStackHandleReInitializer >
198
+ <button className = { CUSTOM_DRAGGABLE_HANDLE_CLASSNAME } >
199
+ Handle ONLY HERE
200
+ </button >
201
+ </GridStackHandleReInitializer >
202
+ </GridStackItem >
203
+ </GridStackRender >
204
+ </GridStackProvider >
205
+ );
206
+ }
144
207
```
145
208
146
209
## API Reference
0 commit comments