@@ -2,14 +2,7 @@ import { useCallback, useEffect, useState } from "react";
2
2
import { CellProps , GridContextMenuItemProps , SelectedRegion , SelectionFocus } from ".." ;
3
3
import { Grid as CUIGrid } from "./Grid" ;
4
4
5
- const Cell : CellProps = ( {
6
- type,
7
- rowIndex,
8
- columnIndex,
9
- isScrolling,
10
- width,
11
- ...props
12
- } ) => {
5
+ const Cell : CellProps = ( { type, rowIndex, columnIndex, isScrolling, width, ...props } ) => {
13
6
return (
14
7
< div
15
8
data-scrolling = { isScrolling }
@@ -27,6 +20,7 @@ interface Props {
27
20
row : number ;
28
21
column : number ;
29
22
} ;
23
+ autoheight ?: boolean ;
30
24
}
31
25
const Grid = ( { columnCount, rowCount, focus : focusProp , ...props } : Props ) => {
32
26
const [ focus , setFocus ] = useState ( focusProp ) ;
@@ -78,6 +72,7 @@ const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
78
72
} ) ;
79
73
} }
80
74
getMenuOptions = { getMenuOptions }
75
+ autoheight = { props . autoheight }
81
76
{ ...props }
82
77
/>
83
78
</ div >
@@ -128,3 +123,109 @@ export const Playground = {
128
123
} ,
129
124
} ,
130
125
} ;
126
+
127
+ export const AutoHeightWithVariableData = {
128
+ args : {
129
+ rowCount : 10 ,
130
+ columnCount : 5 ,
131
+ autoheight : true ,
132
+ rowStart : 0 ,
133
+ } ,
134
+ parameters : {
135
+ docs : {
136
+ source : {
137
+ transform : ( _ : string , story : { args : Props ; [ x : string ] : unknown } ) => {
138
+ const { rowCount, columnCount, autoheight, ...props } = story . args ;
139
+ return `
140
+ const VariableCell: CellProps = ({ type, rowIndex, columnIndex, isScrolling, width, ...props }) => {
141
+ let content = \`Row \${rowIndex}, Col \${columnIndex}\${rowIndex % 2 === 0 ? '\\nExtra line' : ''}\`;
142
+
143
+ if (rowIndex === 0 && columnIndex === 0) {
144
+ content = \`CREATE TABLE random_user_events (
145
+ user_id UInt32,
146
+ event_time DateTime,
147
+ event_type Enum8('click' = 1, 'view' = 2, 'purchase' = 3),
148
+ item_id String,
149
+ price Decimal(10,2),
150
+ quantity UInt16
151
+ ) ENGINE = MergeTree()
152
+ ORDER BY (user_id, event_time)
153
+ PARTITION BY toYYYYMM(event_time)
154
+ SETTINGS index_granularity = 8192;\`;
155
+ }
156
+
157
+ return (
158
+ <div
159
+ data-scrolling={isScrolling}
160
+ style={{
161
+ whiteSpace: 'pre-wrap',
162
+ padding: '8px',
163
+ borderBottom: '1px solid #ccc',
164
+ fontFamily: rowIndex === 0 && columnIndex === 0 ? 'monospace' : 'inherit',
165
+ fontSize: rowIndex === 0 && columnIndex === 0 ? '12px' : 'inherit',
166
+ }}
167
+ {...props}
168
+ >
169
+ {content}
170
+ </div>
171
+ );
172
+ };
173
+
174
+ <Grid
175
+ cell={VariableCell}
176
+ focus={{ row: 0, column: 0 }}
177
+ columnWidth={() => 300}
178
+ autoheight={${ autoheight } }
179
+ ${ Object . entries ( props )
180
+ . flatMap ( ( [ key , value ] ) =>
181
+ typeof value === "boolean"
182
+ ? value
183
+ ? ` ${ key } `
184
+ : [ ]
185
+ : ` ${ key } =${ typeof value == "string" ? `"${ value } "` : `{${ value } }` } `
186
+ )
187
+ . join ( "\n" ) }
188
+ />
189
+ ` ;
190
+ } ,
191
+ } ,
192
+ } ,
193
+ } ,
194
+ render : ( args ) => {
195
+ const VariableCell : CellProps = ( { type, rowIndex, columnIndex, isScrolling, width, ...props } ) => {
196
+ let content = `Row ${ rowIndex } , Col ${ columnIndex } ${ rowIndex % 2 === 0 ? '\nExtra line' : '' } ` ;
197
+
198
+ if ( rowIndex === 0 && columnIndex === 0 ) {
199
+ content = `CREATE TABLE random_user_events (
200
+ user_id UInt32,
201
+ event_time DateTime,
202
+ event_type Enum8('click' = 1, 'view' = 2, 'purchase' = 3),
203
+ item_id String,
204
+ price Decimal(10,2),
205
+ quantity UInt16
206
+ ) ENGINE = MergeTree()
207
+ ORDER BY (user_id, event_time)
208
+ PARTITION BY toYYYYMM(event_time)
209
+ SETTINGS index_granularity = 8192;` ;
210
+ }
211
+
212
+ return (
213
+ < div
214
+ data-scrolling = { isScrolling }
215
+ style = { {
216
+ whiteSpace : 'pre-wrap' ,
217
+ padding : '8px' ,
218
+ borderBottom : '1px solid #ccc' ,
219
+ fontFamily : rowIndex === 0 && columnIndex === 0 ? 'monospace' : 'inherit' ,
220
+ fontSize : rowIndex === 0 && columnIndex === 0 ? '12px' : 'inherit' ,
221
+ } }
222
+ { ...props }
223
+ >
224
+ { content }
225
+ </ div >
226
+ ) ;
227
+ } ;
228
+
229
+ return < Grid { ...args } cell = { VariableCell } columnWidth = { ( ) => 300 } /> ;
230
+ } ,
231
+ } ;
0 commit comments