Skip to content

Commit c2e0085

Browse files
committed
Improve Grid imperative API example
1 parent 228ca3e commit c2e0085

21 files changed

+184
-278
lines changed

generated/examples/CellComponent.example.jsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
function CellComponent({ contacts, columnIndex, rowIndex, style }) {
2-
// Column and header rows shown for example purposes; (they aren't required)
3-
if (columnIndex === 0 && rowIndex === 0) {
4-
return null;
5-
} else if (rowIndex === 0) {
6-
return (
7-
<div className="text-sm font-bold" style={style}>
8-
Column {columnIndex}
9-
</div>
10-
);
11-
} else if (columnIndex === 0) {
12-
return (
13-
<div className="text-sm font-bold" style={style}>
14-
Row {rowIndex}
15-
</div>
16-
);
17-
}
18-
19-
const address = contacts[rowIndex - 1];
20-
const content = address[indexToColumn(columnIndex - 1)];
2+
const address = contacts[rowIndex];
3+
const content = address[indexToColumn(columnIndex)];
214

225
return (
236
<div className="truncate" style={style}>

generated/examples/CellComponent.example.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,8 @@ function CellComponent({
44
rowIndex,
55
style,
66
}: GridComponentProps<CellProps>) {
7-
// Column and header rows shown for example purposes; (they aren't required)
8-
if (columnIndex === 0 && rowIndex === 0) {
9-
return null;
10-
} else if (rowIndex === 0) {
11-
return (
12-
<div className="text-sm font-bold" style={style}>
13-
Column {columnIndex}
14-
</div>
15-
);
16-
} else if (columnIndex === 0) {
17-
return (
18-
<div className="text-sm font-bold" style={style}>
19-
Row {rowIndex}
20-
</div>
21-
);
22-
}
23-
24-
const address = contacts[rowIndex - 1];
25-
const content = address[indexToColumn(columnIndex - 1)];
7+
const address = contacts[rowIndex];
8+
const content = address[indexToColumn(columnIndex)];
269

2710
return (
2811
<div className="truncate" style={style}>

generated/examples/Grid.example.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ function Example({ contacts }) {
55
<Grid
66
cellComponent={CellComponent}
77
cellProps={{ contacts }}
8-
columnCount={11}
8+
columnCount={10}
99
columnWidth={columnWidth}
10-
rowCount={
11-
contacts.length + 1 // Extra header row
12-
}
10+
rowCount={contacts.length}
1311
rowHeight={25}
1412
/>
1513
);

generated/examples/Grid.example.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ function Example({ contacts }: { contacts: Contact[] }) {
99
<Grid
1010
cellComponent={CellComponent}
1111
cellProps={{ contacts }}
12-
columnCount={11}
12+
columnCount={10}
1313
columnWidth={columnWidth}
14-
rowCount={
15-
contacts.length + 1 // Extra header row
16-
}
14+
rowCount={contacts.length}
1715
rowHeight={25}
1816
/>
1917
);

generated/examples/GridImperativeApi.example.jsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

generated/examples/GridImperativeApi.example.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

generated/examples/ListImperativeAPI.example.jsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

generated/examples/ListImperativeAPI.example.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function rowHeight(index, { items }) {
2+
return items[index].type === "state" ? 35 : 20;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function rowHeight(index: number, { items }: RowProps) {
2+
return items[index].type === "state" ? 35 : 20;
3+
}

0 commit comments

Comments
 (0)