-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Implement DataGrid virtualized by react-window #18
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
Merged
ling1726
merged 15 commits into
microsoft:main
from
ling1726:react-data-grid-react-window/feat/initial
Jul 5, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
be99bf9
feat: Implement DataGrid virtualized by react-window
ling1726 e5117fc
Change files
ling1726 35781be
install types
ling1726 df7fba7
merge main
ling1726 a61f517
fix formatting
ling1726 f22d7ba
Merge remote-tracking branch 'origin/main' into react-data-grid-react…
ling1726 1f18768
Merge remote-tracking branch 'origin/main' into react-data-grid-react…
ling1726 a64a39b
fix lint
ling1726 2ad7867
fix dep mismatch
ling1726 1b361ce
remove code from README
ling1726 09701d2
add jsx runtime
ling1726 39c2c8c
use getSlots instead of getSlotsNext
ling1726 c60123e
remove new slot architecture
ling1726 5504f8f
merge conflict
ling1726 a407191
remove devdep
ling1726 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
7 changes: 7 additions & 0 deletions
7
.../@fluentui-contrib-react-data-grid-react-window-0c9a0118-91c3-4265-a1cc-db06c58a2d84.json
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,7 @@ | ||
| { | ||
| "type": "major", | ||
| "comment": "feat: Implement DataGrid virtualized by react-window", | ||
| "packageName": "@fluentui-contrib/react-data-grid-react-window", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "extends": ["../../.eslintrc.json"], | ||
| "ignorePatterns": ["!**/*"], | ||
| "overrides": [ | ||
| { | ||
| "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.ts", "*.tsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["stories/**/*.tsx", "stories/**/*.ts"], | ||
| "rules": { | ||
| "@nx/enforce-module-boundaries": "off" | ||
| } | ||
| } | ||
| ] | ||
| } |
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,16 @@ | ||
| import type { StorybookConfig } from '@storybook/react-webpack5'; | ||
|
|
||
| const config: StorybookConfig = { | ||
| stories: ['../stories/**/index.stories.@(js|jsx|ts|tsx|mdx)'], | ||
| addons: ['@storybook/addon-essentials', '@nx/react/plugins/storybook'], | ||
| framework: { | ||
| name: '@storybook/react-webpack5', | ||
| options: {}, | ||
| }, | ||
| }; | ||
|
|
||
| export default config; | ||
|
|
||
| // To customize your webpack configuration you can use the webpackFinal field. | ||
| // Check https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config | ||
| // and https://nx.dev/packages/storybook/documents/custom-builder-configs |
17 changes: 17 additions & 0 deletions
17
packages/react-data-grid-react-window/.storybook/preview.tsx
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,17 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { Preview } from '@storybook/react'; | ||
|
|
||
| import { FluentProvider, webLightTheme } from '@fluentui/react-components'; | ||
|
|
||
| const preview: Preview = { | ||
| decorators: [ | ||
| (Story) => ( | ||
| <FluentProvider theme={webLightTheme}> | ||
| <Story /> | ||
| </FluentProvider> | ||
| ), | ||
| ], | ||
| }; | ||
|
|
||
| export default preview; |
27 changes: 27 additions & 0 deletions
27
packages/react-data-grid-react-window/.storybook/tsconfig.json
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,27 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "emitDecoratorMetadata": true, | ||
| "outDir": "" | ||
| }, | ||
| "files": [ | ||
| "../../../node_modules/@nx/react/typings/styled-jsx.d.ts", | ||
| "../../../node_modules/@nx/react/typings/cssmodule.d.ts", | ||
| "../../../node_modules/@nx/react/typings/image.d.ts" | ||
| ], | ||
| "exclude": [ | ||
| "../**/*.spec.ts", | ||
| "../**/*.spec.js", | ||
| "../**/*.spec.tsx", | ||
| "../**/*.spec.jsx" | ||
| ], | ||
| "include": [ | ||
| "../stories/**/*.stories.ts", | ||
| "../stories/**/*.stories.js", | ||
| "../stories/**/*.stories.jsx", | ||
| "../stories/**/*.stories.tsx", | ||
| "../stories/**/*.stories.mdx", | ||
| "*.ts", | ||
| "*.js" | ||
| ] | ||
| } |
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,30 @@ | ||
| { | ||
| "jsc": { | ||
| "target": "es2020", | ||
| "parser": { | ||
| "syntax": "typescript", | ||
| "tsx": true, | ||
| "decorators": false, | ||
| "dynamicImport": false | ||
| }, | ||
| "transform": { | ||
| "react": { | ||
| "runtime": "classic", | ||
| "useSpread": true | ||
| } | ||
| }, | ||
| "keepClassNames": true, | ||
| "externalHelpers": true, | ||
| "loose": true | ||
| }, | ||
| "sourceMaps": true, | ||
| "exclude": [ | ||
| "jest.config.ts", | ||
| ".*\\.spec.tsx?$", | ||
| ".*\\.test.tsx?$", | ||
| "./src/jest-setup.ts$", | ||
| "./**/jest-setup.ts$", | ||
| ".*.js$" | ||
| ], | ||
| "$schema": "https://json.schemastore.org/swcrc" | ||
| } |
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,14 @@ | ||
| # @fluentui-contrib/react-chat | ||
|
|
||
| A variant of the Fluent UI [DataGrid](https://react.fluentui.dev/?path=/docs/components-datagrid--default) that is | ||
| virtualized using [react-window](https://react-window.vercel.app/#/examples/list/fixed-size). | ||
|
|
||
| ## Try it out | ||
|
|
||
| ```sh | ||
| yarn add @fluentui-contrib/react-data-grid-react-window | ||
|
|
||
| npm install @fluentui-contrib/react-data-grid-react-window | ||
| ``` | ||
|
|
||
| For a full usage example please take a look at [The documentation sample](https://github.com/microsoft/fluentui-contrib/blob/main/stories/DataGrid/VirtualizedDataGrid.stories.tsx). |
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,29 @@ | ||
| /* eslint-disable */ | ||
| import { readFileSync } from 'fs'; | ||
|
|
||
| // Reading the SWC compilation config and remove the "exclude" | ||
| // for the test files to be compiled by SWC | ||
| const { exclude: _, ...swcJestConfig } = JSON.parse( | ||
| readFileSync(`${__dirname}/.swcrc`, 'utf-8') | ||
| ); | ||
|
|
||
| // disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. | ||
| // If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" | ||
| if (swcJestConfig.swcrc === undefined) { | ||
| swcJestConfig.swcrc = false; | ||
| } | ||
|
|
||
| // Uncomment if using global setup/teardown files being transformed via swc | ||
| // https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries | ||
| // jest needs EsModule Interop to find the default exported setup/teardown functions | ||
| // swcJestConfig.module.noInterop = false; | ||
|
|
||
| export default { | ||
| displayName: 'button', | ||
| preset: '../../jest.preset.js', | ||
| transform: { | ||
| '^.+\\.[tj]sx?$': ['@swc/jest', swcJestConfig], | ||
| }, | ||
| moduleFileExtensions: ['js', 'ts', 'tsx', 'html'], | ||
| coverageDirectory: '../../coverage/packages/button', | ||
| }; |
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,11 @@ | ||
| { | ||
| "name": "@fluentui-contrib/react-data-grid-react-window", | ||
| "version": "0.0.1", | ||
| "dependencies": { | ||
| "react-window": "^1.8.5" | ||
| }, | ||
| "peerDependencies": { | ||
| "@fluentui/react-components": ">=9.25.1 <10.0.0", | ||
| "react": ">=16.8.0 <19.0.0" | ||
| } | ||
| } | ||
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,68 @@ | ||
| { | ||
| "name": "react-data-grid-react-window", | ||
| "$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "packages/react-data-grid-react-window/src", | ||
| "projectType": "library", | ||
| "targets": { | ||
| "build": { | ||
| "executor": "@fluentui-contrib/nx-plugin:build" | ||
| }, | ||
| "publish": { | ||
| "command": "node tools/scripts/publish.mjs react-data-grid-react-window {args.ver} {args.tag}", | ||
| "dependsOn": ["build"] | ||
| }, | ||
| "lint": { | ||
| "executor": "@nx/linter:eslint", | ||
| "outputs": ["{options.outputFile}"], | ||
| "options": { | ||
| "lintFilePatterns": [ | ||
| "packages/react-data-grid-react-window/**/*.ts", | ||
| "packages/react-data-grid-react-window/**/*.tsx" | ||
| ] | ||
| } | ||
| }, | ||
| "test": { | ||
| "executor": "@nx/jest:jest", | ||
| "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
| "options": { | ||
| "jestConfig": "packages/react-data-grid-react-window/jest.config.ts", | ||
| "passWithNoTests": true | ||
| }, | ||
| "configurations": { | ||
| "ci": { | ||
| "ci": true, | ||
| "codeCoverage": true | ||
| } | ||
| } | ||
| }, | ||
| "type-check": { | ||
| "executor": "@fluentui-contrib/nx-plugin:type-check" | ||
| }, | ||
| "storybook": { | ||
| "executor": "@nx/storybook:storybook", | ||
| "options": { | ||
| "port": 4400, | ||
| "configDir": "packages/react-data-grid-react-window/.storybook" | ||
| }, | ||
| "configurations": { | ||
| "ci": { | ||
| "quiet": true | ||
| } | ||
| } | ||
| }, | ||
| "build-storybook": { | ||
| "executor": "@nx/storybook:build", | ||
| "outputs": ["{options.outputDir}"], | ||
| "options": { | ||
| "outputDir": "dist/storybook/react-data-grid-react-window", | ||
| "configDir": "packages/react-data-grid-react-window/.storybook" | ||
| }, | ||
| "configurations": { | ||
| "ci": { | ||
| "quiet": true | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "tags": [] | ||
| } |
23 changes: 23 additions & 0 deletions
23
packages/react-data-grid-react-window/src/components/DataGrid/DataGrid.tsx
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,23 @@ | ||
| import * as React from 'react'; | ||
| import { useDataGrid_unstable } from './useDataGrid'; | ||
| import { | ||
| renderDataGrid_unstable, | ||
| useDataGridStyles_unstable, | ||
| useDataGridContextValues_unstable, | ||
| DataGridProps, | ||
| } from '@fluentui/react-components'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
|
||
| export const DataGrid: ForwardRefComponent<DataGridProps> = React.forwardRef( | ||
| (props, ref) => { | ||
| const state = useDataGrid_unstable(props, ref); | ||
|
|
||
| useDataGridStyles_unstable(state); | ||
| return renderDataGrid_unstable( | ||
| state, | ||
| useDataGridContextValues_unstable(state) | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| DataGrid.displayName = 'DataGrid'; |
2 changes: 2 additions & 0 deletions
2
packages/react-data-grid-react-window/src/components/DataGrid/index.ts
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,2 @@ | ||
| export * from './DataGrid'; | ||
| export * from './useDataGrid'; |
40 changes: 40 additions & 0 deletions
40
packages/react-data-grid-react-window/src/components/DataGrid/useDataGrid.ts
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,40 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| useDataGrid_unstable as useBaseState, | ||
| DataGridProps, | ||
| DataGridState, | ||
| } from '@fluentui/react-components'; | ||
| import { useFluent, useScrollbarWidth } from '@fluentui/react-components'; | ||
|
|
||
| const TABLE_SELECTION_CELL_WIDTH = 44; | ||
|
|
||
| /** | ||
| * Create the state required to render DataGrid. | ||
| * | ||
| * The returned state can be modified with hooks such as useDataGridStyles_unstable, | ||
| * before being passed to renderDataGrid_unstable. | ||
| * | ||
| * @param props - props from this instance of DataGrid | ||
| * @param ref - reference to root HTMLElement of DataGrid | ||
| */ | ||
| export const useDataGrid_unstable = ( | ||
| props: DataGridProps, | ||
| ref: React.Ref<HTMLElement> | ||
| ): DataGridState => { | ||
| const { targetDocument } = useFluent(); | ||
| const scrollbarWidth = useScrollbarWidth({ targetDocument }); | ||
|
|
||
| let containerWidthOffset = props.containerWidthOffset; | ||
|
|
||
| if (containerWidthOffset === undefined) { | ||
| containerWidthOffset = props.selectionMode | ||
| ? -TABLE_SELECTION_CELL_WIDTH | ||
| : 0; | ||
| containerWidthOffset -= scrollbarWidth || 0; | ||
| } | ||
|
|
||
| return useBaseState( | ||
| { ...props, 'aria-rowcount': props.items.length, containerWidthOffset }, | ||
| ref | ||
| ); | ||
| }; |
22 changes: 22 additions & 0 deletions
22
packages/react-data-grid-react-window/src/components/DataGridBody/DataGridBody.tsx
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,22 @@ | ||
| import * as React from 'react'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-components'; | ||
| import { useDataGridBodyStyles_unstable } from './useDataGridBodyStyles.styles'; | ||
| import { useDataGridBody_unstable } from './useDataGridBody'; | ||
| import { renderDataGridBody_unstable } from './renderDataGridBody'; | ||
| import type { DataGridBodyProps } from './DataGridBody.types'; | ||
|
|
||
| /** | ||
| * DataGridBody component | ||
| */ | ||
| export const DataGridBody: ForwardRefComponent<DataGridBodyProps> & | ||
| (<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element) = React.forwardRef( | ||
| (props, ref) => { | ||
| const state = useDataGridBody_unstable(props, ref); | ||
|
|
||
| useDataGridBodyStyles_unstable(state); | ||
| return renderDataGridBody_unstable(state); | ||
| } | ||
| ) as ForwardRefComponent<DataGridBodyProps> & | ||
| (<TItem>(props: DataGridBodyProps<TItem>) => JSX.Element); | ||
|
|
||
| DataGridBody.displayName = 'DataGridBody'; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.