Skip to content

Commit c8b1668

Browse files
Adds rowHeight story.
1 parent acc1208 commit c8b1668

File tree

1 file changed

+109
-8
lines changed

1 file changed

+109
-8
lines changed

src/components/Grid/Grid.stories.tsx

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import { useCallback, useEffect, useState } from "react";
22
import { CellProps, GridContextMenuItemProps, SelectedRegion, SelectionFocus } from "..";
33
import { Grid as CUIGrid } from "./Grid";
44

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 }) => {
136
return (
147
<div
158
data-scrolling={isScrolling}
@@ -27,6 +20,7 @@ interface Props {
2720
row: number;
2821
column: number;
2922
};
23+
autoheight?: boolean;
3024
}
3125
const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
3226
const [focus, setFocus] = useState(focusProp);
@@ -78,6 +72,7 @@ const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
7872
});
7973
}}
8074
getMenuOptions={getMenuOptions}
75+
autoheight={props.autoheight}
8176
{...props}
8277
/>
8378
</div>
@@ -128,3 +123,109 @@ export const Playground = {
128123
},
129124
},
130125
};
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

Comments
 (0)