@@ -18,31 +18,35 @@ Welcome to give any suggestions and ideas, you can submit an issue or contact me
1818
1919## Usage
2020
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+
2123** Simple**
2224
2325Render item with widget id selector.
2426
27+ Code here: [ src/examples/001-simple/index.tsx] ( src/examples/001-simple/index.tsx )
28+
2529``` tsx
26- function App () {
27- const [uncontrolledInitialOptions] = useState <GridStackOptions >({
28- // ...
30+ function Simple () {
31+ const [uncontrolledInitialOptions] = useState <GridStackOptions >(() => ( {
32+ ... defaultGridOptions ,
2933 children: [
3034 { id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 },
3135 { id: " item2" , h: 2 , w: 2 , x: 2 , y: 0 },
3236 ],
33- });
37+ })) ;
3438
3539 return (
3640 <GridStackProvider initialOptions = { uncontrolledInitialOptions } >
3741 <Toolbar />
3842
39- <GridStackRender >
43+ <GridStackRender renderRawContent >
4044 <GridStackItem id = " item1" >
41- <div >hello</div >
45+ <div style = { { color: " yellow " } } >hello</div >
4246 </GridStackItem >
4347
4448 <GridStackItem id = " item2" >
45- <div >grid</div >
49+ <div style = { { color: " blue " } } >grid</div >
4650 </GridStackItem >
4751 </GridStackRender >
4852 </GridStackProvider >
@@ -56,20 +60,59 @@ Render item with widget map component info.
5660
5761_ ComponentInfoMap is just an example, you can use any way you want to store and retrieve component information._
5862
63+ Code here: [ src/examples/009-advanced/index.tsx] ( src/examples/009-advanced/index.tsx )
64+
5965``` 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 ,
6370 children: [
6471 { id: " item1" , h: 2 , w: 2 , x: 0 , y: 0 },
6572 { 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 },
6698 ],
67- });
99+ })) ;
68100
101+ // Data about every content
69102 const [initialComponentInfoMap] = useState <Record <string , ComponentInfo >>(
70103 () => ({
71104 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: {
73116 component: " ComplexCard" ,
74117 serializableProps: { title: " Complex Card" , color: " red" },
75118 },
@@ -89,7 +132,7 @@ function App() {
89132 );
90133}
91134
92- export function DynamicGridStackItems() {
135+ function DynamicGridStackItems() {
93136 const { componentInfoMap } = useComponentInfoMap ();
94137
95138 return (
@@ -117,6 +160,8 @@ export function DynamicGridStackItems() {
117160 );
118161 }
119162
163+ // ... more render conditions here
164+
120165 return (
121166 <GridStackItem key = { widgetId } id = { widgetId } >
122167 <Component { ... props } key = { ` component-${widgetId } ` } />
@@ -133,14 +178,32 @@ export function DynamicGridStackItems() {
133178
134179Render item with custom handle.
135180
181+ Code here: [ src/examples/003-custom-handle/index.tsx] ( src/examples/003-custom-handle/index.tsx )
182+
136183``` 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+ }
144207```
145208
146209## API Reference
0 commit comments