@@ -14,8 +14,6 @@ Open in [CodeSandbox](https://codesandbox.io/p/sandbox/github/gridstack/gridstac
14
14
- [x] Custom handle
15
15
- [x] Drag between two grid stacks
16
16
17
- Welcome to give any suggestions and ideas, you can submit an issue or contact me by email. :)
18
-
19
17
## Usage
20
18
21
19
This is not an npm package, it's just a demo project. Please copy the ` src/lib ` code to your project to use it.
@@ -24,6 +22,37 @@ This is not an npm package, it's just a demo project. Please copy the `src/lib`
24
22
25
23
Render item with widget id selector.
26
24
25
+ Code here: [ src/examples/000-simple/index.tsx] ( src/examples/000-simple/index.tsx )
26
+
27
+ ``` tsx
28
+ function Simple() {
29
+ const [uncontrolledInitialOptions] = useState <GridStackOptions >(() => ({
30
+ ... defaultGridOptions ,
31
+ children: [
32
+ { id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 },
33
+ { id: " item2" , h: 2 , w: 2 , x: 2 , y: 0 },
34
+ ],
35
+ }));
36
+
37
+ return (
38
+ <GridStackContainer
39
+ initialOptions = { uncontrolledInitialOptions }
40
+ renderRawContent
41
+ >
42
+ <GridStackItem id = " item1" >
43
+ <div style = { { color: " yellow" }} >hello</div >
44
+ </GridStackItem >
45
+
46
+ <GridStackItem id = " item2" >
47
+ <div style = { { color: " blue" }} >grid</div >
48
+ </GridStackItem >
49
+ </GridStackContainer >
50
+ );
51
+ }
52
+ ```
53
+
54
+ Or split the grid stack container to provide grid stack context and render component for access to grid stack context.
55
+
27
56
Code here: [ src/examples/001-simple/index.tsx] ( src/examples/001-simple/index.tsx )
28
57
29
58
``` tsx
@@ -38,6 +67,7 @@ function Simple() {
38
67
39
68
return (
40
69
<GridStackProvider initialOptions = { uncontrolledInitialOptions } >
70
+ { /* Custom toolbar component. Access to grid stack context by useGridStackContext hook. */ }
41
71
<Toolbar />
42
72
43
73
<GridStackRender renderRawContent >
@@ -210,6 +240,17 @@ function CustomHandle() {
210
240
211
241
### Components
212
242
243
+ #### GridStackContainer
244
+
245
+ Top-level component that provides GridStack context and GridStack root container. Equivalent to ` GridStackProvider ` and ` GridStackRender ` combined.
246
+
247
+ ``` typescript
248
+ type GridStackContainerProps = {
249
+ initialOptions: GridStackOptions ; // GridStack initialization options
250
+ children: React .ReactNode ;
251
+ };
252
+ ```
253
+
213
254
#### GridStackProvider
214
255
215
256
Top-level component that provides GridStack context.
0 commit comments