-
-
Notifications
You must be signed in to change notification settings - Fork 86
Implement basic functionality for virtualization #690
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
Open
lukasbash
wants to merge
1
commit into
icflorescu:main
Choose a base branch
from
lukasbash:feat/virtualization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/examples/virtualization/VirtualizationExample.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| .buttons { | ||
| width: 100%; | ||
| display: flex; | ||
| gap: var(--mantine-spacing-md); | ||
| flex-direction: column; | ||
| @media (min-width: rem(400px)) { | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| } | ||
| } | ||
|
|
||
| .button { | ||
| width: 100%; | ||
| @media (min-width: rem(400px)) { | ||
| width: calc(50% - (var(--mantine-spacing-md) / 2)); | ||
| } | ||
| @media (min-width: rem(660px)) { | ||
| width: calc((100% - var(--mantine-spacing-md) * 3) / 4); | ||
| } | ||
| @media (min-width: $mantine-breakpoint-sm) { | ||
| width: calc(50% - (var(--mantine-spacing-md) / 2)); | ||
| } | ||
| @media (min-width: $mantine-breakpoint-md) { | ||
| width: calc((100% - var(--mantine-spacing-md) * 3) / 4); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| 'use client'; | ||
|
|
||
| import { faker } from '@faker-js/faker'; | ||
| import { Button, Center, Paper } from '@mantine/core'; | ||
| import { DataTable } from '__PACKAGE__'; | ||
| import { useState } from 'react'; | ||
| import classes from './VirtualizationExample.module.css'; | ||
|
|
||
| type User = { | ||
| id: string; | ||
| name: string; | ||
| age: number; | ||
| }; | ||
|
|
||
| const userData: User[] = Array.from({ length: 2000 }, () => ({ | ||
| id: faker.string.uuid(), | ||
| name: faker.person.fullName(), | ||
| age: faker.number.int({ min: 18, max: 65 }), | ||
| })); | ||
|
|
||
| export function VirtualizationExample() { | ||
| const [virtualized, setVirtualized] = useState(false); | ||
|
|
||
| const toggleVirtualized = () => setVirtualized((current) => !current); | ||
|
|
||
| // example-start | ||
| // ... | ||
|
|
||
| return ( | ||
| <> | ||
| <DataTable | ||
| virtualize={virtualized} | ||
| borderRadius="sm" | ||
| withTableBorder | ||
| minHeight={200} | ||
| columns={[{ accessor: 'id' }, { accessor: 'name' }, { accessor: 'age' }]} | ||
| records={userData} | ||
| height={400} | ||
| rowExpansion={{ | ||
| content: ({ record }) => ( | ||
| <div style={{ padding: 10 }}> | ||
| <div>ID: {record.id}</div> | ||
| <div>Name: {record.name}</div> | ||
| <div>Age: {record.age}</div> | ||
| </div> | ||
| ), | ||
| }} | ||
| /> | ||
| {/* example-skip */} | ||
| <Paper p="md" mt="sm" withBorder> | ||
| <Center> | ||
| <div className={classes.buttons}> | ||
| <Button className={classes.button} color="green" onClick={toggleVirtualized}> | ||
| {virtualized ? 'Disable' : 'Enable'} virtualization | ||
| </Button> | ||
| </div> | ||
| </Center> | ||
| </Paper> | ||
| {/* example-resume */} | ||
| </> | ||
| ); | ||
| // example-end | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { Code } from '@mantine/core'; | ||
| import type { Route } from 'next'; | ||
| import { CodeBlock } from '~/components/CodeBlock'; | ||
| import { ExternalLink } from '~/components/ExternalLink'; | ||
| import { PageNavigation } from '~/components/PageNavigation'; | ||
| import { PageTitle } from '~/components/PageTitle'; | ||
| import { Txt } from '~/components/Txt'; | ||
| import { readCodeFile } from '~/lib/code'; | ||
| import { getRouteMetadata } from '~/lib/utils'; | ||
| import { VirtualizationExample } from './VirtualizationExample'; | ||
|
|
||
| const PATH: Route = '/examples/virtualization'; | ||
|
|
||
| export const metadata = getRouteMetadata(PATH); | ||
|
|
||
| export default async function VirtualizationExamplePage() { | ||
| const code = await readCodeFile<string>(`${PATH}/VirtualizationExample.tsx`); | ||
|
|
||
| return ( | ||
| <> | ||
| <PageTitle of={PATH} /> | ||
| <Txt> | ||
| The <Code>DataTable</Code> component exposes a <Code>bodyRef</Code> property that can be used to pass a ref to | ||
| the underlying table <Code>tbody</Code> element. This ref can be passed to the <Code>useAutoAnimate()</Code>{' '} | ||
| hook from the excellent <ExternalLink to="https://auto-animate.formkit.com/">AutoAnimate</ExternalLink> library | ||
| to animate table rows when they are added, removed or reordered. | ||
| </Txt> | ||
| <VirtualizationExample /> | ||
| <Txt>Here is the code:</Txt> | ||
| <CodeBlock code={code} /> | ||
| <Txt>Head over to the next example to learn more.</Txt> | ||
| <PageNavigation of={PATH} /> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -835,6 +835,18 @@ | |
| dependencies: | ||
| "@tanstack/query-core" "5.62.8" | ||
|
|
||
| "@tanstack/react-virtual@^3.10.8": | ||
| version "3.10.8" | ||
| resolved "https://registry.yarnpkg.com/@tanstack/react-virtual/-/react-virtual-3.10.8.tgz#bf4b06f157ed298644a96ab7efc1a2b01ab36e3c" | ||
| integrity sha512-VbzbVGSsZlQktyLrP5nxE+vE1ZR+U0NFAWPbJLoG2+DKPwd2D7dVICTVIIaYlJqX1ZCEnYDbaOpmMwbsyhBoIA== | ||
| dependencies: | ||
| "@tanstack/virtual-core" "3.10.8" | ||
|
|
||
| "@tanstack/[email protected]": | ||
| version "3.10.8" | ||
| resolved "https://registry.yarnpkg.com/@tanstack/virtual-core/-/virtual-core-3.10.8.tgz#975446a667755222f62884c19e5c3c66d959b8b4" | ||
| integrity sha512-PBu00mtt95jbKFi6Llk9aik8bnR3tR/oQP1o3TSi+iG//+Q2RTIzCEgKkHG8BB86kxMNW6O8wku+Lmi+QFR6jA== | ||
|
|
||
| "@trysound/[email protected]": | ||
| version "0.2.0" | ||
| resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably remove the commented code that was left in.