Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Grid table virtualization #93

Merged
merged 24 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
"change-case": "^4.1.2",
"date-fns": "^2.21.3",
"framer-motion": "^4.1.11",
"memoize-one": "^5.2.1",
"react-aria": "^3.6.0",
"react-day-picker": "^7.4.10",
"react-popper": "^2.2.5",
"react-stately": "^3.5.0",
"react-virtuoso": "^1.9.0",
"tributejs": "^5.1.3",
"trix": "^1.3.1",
"react-popper": "^2.2.5"
"trix": "^1.3.1"
},
"peerDependencies": {
"@emotion/react": ">=11",
Expand Down
44 changes: 28 additions & 16 deletions src/components/GridTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,44 @@ export const Hovering = newStory(
);

export function Filtering() {
const nameColumn: GridColumn<Row> = { header: "Name", data: ({ name }) => name };
const valueColumn: GridColumn<Row> = { header: "Value", data: ({ value }) => value };
const actionColumn: GridColumn<Row> = { header: "Action", data: () => <div>Actions</div>, sort: false };
const rows: GridDataRow<Row>[] = useMemo(
() => [
{ kind: "header", id: "header" },
{ kind: "data", id: "1", name: "c", value: 1 },
{ kind: "data", id: "2", name: "b", value: 2 },
{ kind: "data", id: "3", name: "a", value: 3 },
...zeroTo(1_000).map((i) => ({ kind: "data" as const, id: String(i), name: `ccc ${i}`, value: i })),
],
[],
);
const columns: GridColumn<Row>[] = useMemo(
() => [
{ header: "Name", data: ({ name }) => name },
{ header: "Value", data: ({ value }) => value },
{ header: "Action", data: () => <div>Actions</div>, sort: false },
],
[],
);
const [filter, setFilter] = useState<string | undefined>();
return (
<div>
<input type="text" value={filter || ""} onChange={(e) => setFilter(e.target.value)} css={Css.ba.bGray900.$} />
<GridTable
columns={[nameColumn, valueColumn, actionColumn]}
sorting={"client-side"}
filter={filter}
rows={rows}
/>
<div css={Css.df.flexColumn.add({ height: heightWithoutStorybookPadding }).$}>
<div>
<input type="text" value={filter || ""} onChange={(e) => setFilter(e.target.value)} css={Css.ba.bGray900.$} />
</div>
<div css={Css.fg1.$}>
<GridTable
as="virtual"
columns={columns}
sorting={"client-side"}
filter={filter}
stickyHeader={true}
rows={rows}
/>
</div>
</div>
);
}

// .sb-main-padded adds 1rem on top/bottom
const heightWithoutStorybookPadding = "calc(100vh - 2rem)";

export function NoRowsFallback() {
const nameColumn: GridColumn<Row> = { header: "Name", data: ({ name }) => name };
const valueColumn: GridColumn<Row> = { header: "Value", data: ({ value }) => value };
Expand Down Expand Up @@ -214,14 +226,14 @@ export function StickyHeader() {
sort: false,
};
return (
<div>
<div style={{ height: heightWithoutStorybookPadding }}>
some other top of page content
<GridTable
columns={[nameColumn, valueColumn, actionColumn]}
stickyHeader={true}
rows={[
{ kind: "header", id: "header" },
...zeroTo(20).map((i) => ({ kind: "data" as const, id: "1", name: "c", value: 1 })),
...zeroTo(200).map((i) => ({ kind: "data" as const, id: `${i}`, name: `row ${i}`, value: i })),
]}
/>
</div>
Expand Down
Loading