Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Packages
packages/react-chat/ @microsoft/teams-prg
packages/react-data-grid-react-window/ @microsoft/teams-prg
packages/react-shadow/ @microsoft/teams-prg
packages/nx-plugin/ @microsoft/teams-prg

Expand Down
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"
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@nx/storybook": "16.1.4",
"@nx/webpack": "16.1.4",
"@nx/workspace": "16.1.4",
"@storybook/addon-storysource": "^7.0.26",
"@storybook/core-common": "^7.0.9",
"@storybook/core-server": "7.0.12",
"@storybook/react-webpack5": "7.0.12",
Expand All @@ -43,6 +44,7 @@
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.4.0",
"@types/node": "16.11.7",
"@types/react-window": "^1.8.5",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"beachball": "^2.33.2",
Expand All @@ -58,14 +60,12 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-shadow": "^20.3.0",
"react-window": "^1.8.9",
"semver": "^7.5.2",
"syncpack": "^9.8.6",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"tslib": "^2.3.0",
"typescript": "~5.0.2"
},
"dependencies": {
"@storybook/addon-storysource": "^7.0.26"
}
}
24 changes: 24 additions & 0 deletions packages/react-data-grid-react-window/.eslintrc.json
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"
}
}
]
}
16 changes: 16 additions & 0 deletions packages/react-data-grid-react-window/.storybook/main.ts
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 packages/react-data-grid-react-window/.storybook/preview.tsx
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 packages/react-data-grid-react-window/.storybook/tsconfig.json
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"
]
}
30 changes: 30 additions & 0 deletions packages/react-data-grid-react-window/.swcrc
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"
}
14 changes: 14 additions & 0 deletions packages/react-data-grid-react-window/README.md
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).
29 changes: 29 additions & 0 deletions packages/react-data-grid-react-window/jest.config.ts
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',
};
11 changes: 11 additions & 0 deletions packages/react-data-grid-react-window/package.json
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"
}
}
68 changes: 68 additions & 0 deletions packages/react-data-grid-react-window/project.json
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": []
}
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './DataGrid';
export * from './useDataGrid';
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
);
};
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';
Loading