-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initialize DataGrid components (#25442)
* feat: Initialize DataGrid components Initializes `DataGrid` components as simple recomposition of existing `Table` primitives * changefile
- Loading branch information
Showing
67 changed files
with
1,143 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-ac2472bc-2d1f-4c4d-8800-0224ac8968ca.json
This file contains 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": "prerelease", | ||
"comment": "feat: Initialize DataGrid components", | ||
"packageName": "@fluentui/react-table", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains 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 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 @@ | ||
export * from './components/DataGrid/index'; |
This file contains 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 @@ | ||
export * from './components/DataGridBody/index'; |
This file contains 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 @@ | ||
export * from './components/DataGridCell/index'; |
This file contains 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 @@ | ||
export * from './components/DataGridHeader/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-table/src/DataGridHeaderCell.ts
This file contains 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 @@ | ||
export * from './components/DataGridHeaderCell/index'; |
This file contains 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 @@ | ||
export * from './components/DataGridRow/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-table/src/DataGridSelectionCell.ts
This file contains 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 @@ | ||
export * from './components/DataGridSelectionCell/index'; |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-table/src/components/DataGrid/DataGrid.test.tsx
This file contains 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,19 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { DataGrid } from './DataGrid'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { DataGridProps } from './DataGrid.types'; | ||
|
||
describe('DataGrid', () => { | ||
isConformant<DataGridProps>({ | ||
Component: DataGrid, | ||
displayName: 'DataGrid', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<DataGrid>Default DataGrid</DataGrid>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-table/src/components/DataGrid/DataGrid.tsx
This file contains 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,19 @@ | ||
import * as React from 'react'; | ||
import { useDataGrid_unstable } from './useDataGrid'; | ||
import { renderDataGrid_unstable } from './renderDataGrid'; | ||
import { useDataGridStyles_unstable } from './useDataGridStyles'; | ||
import type { DataGridProps } from './DataGrid.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
import { useDataGridContextValues_unstable } from './useDataGridContextValues'; | ||
|
||
/** | ||
* DataGrid component - TODO: add more docs | ||
*/ | ||
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'; |
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts
This file contains 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,15 @@ | ||
import { TableContextValues, TableProps, TableSlots, TableState } from '../Table/Table.types'; | ||
|
||
export type DataGridSlots = TableSlots; | ||
|
||
export type DataGridContextValues = TableContextValues; | ||
|
||
/** | ||
* DataGrid Props | ||
*/ | ||
export type DataGridProps = TableProps; | ||
|
||
/** | ||
* State used in rendering DataGrid | ||
*/ | ||
export type DataGridState = TableState; |
12 changes: 12 additions & 0 deletions
12
...react-components/react-table/src/components/DataGrid/__snapshots__/DataGrid.test.tsx.snap
This file contains 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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DataGrid renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-DataGrid fui-Table" | ||
role="table" | ||
> | ||
Default DataGrid | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-table/src/components/DataGrid/index.ts
This file contains 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,5 @@ | ||
export * from './DataGrid'; | ||
export * from './DataGrid.types'; | ||
export * from './renderDataGrid'; | ||
export * from './useDataGrid'; | ||
export * from './useDataGridStyles'; |
9 changes: 9 additions & 0 deletions
9
packages/react-components/react-table/src/components/DataGrid/renderDataGrid.tsx
This file contains 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,9 @@ | ||
import type { DataGridContextValues, DataGridState } from './DataGrid.types'; | ||
import { renderTable_unstable } from '../Table/renderTable'; | ||
|
||
/** | ||
* Render the final JSX of DataGrid | ||
*/ | ||
export const renderDataGrid_unstable = (state: DataGridState, contextValues: DataGridContextValues) => { | ||
return renderTable_unstable(state, contextValues); | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/react-components/react-table/src/components/DataGrid/useDataGrid.ts
This file contains 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 * as React from 'react'; | ||
import type { DataGridProps, DataGridState } from './DataGrid.types'; | ||
import { useTable_unstable } from '../Table/useTable'; | ||
|
||
/** | ||
* 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 => { | ||
return useTable_unstable({ ...props, as: 'div' }, ref); | ||
}; |
6 changes: 6 additions & 0 deletions
6
packages/react-components/react-table/src/components/DataGrid/useDataGridContextValues.ts
This file contains 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,6 @@ | ||
import { useTableContextValues_unstable } from '../Table/useTableContextValues'; | ||
import { DataGridState } from './DataGrid.types'; | ||
|
||
export function useDataGridContextValues_unstable(state: DataGridState) { | ||
return useTableContextValues_unstable(state); | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-table/src/components/DataGrid/useDataGridStyles.ts
This file contains 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,18 @@ | ||
import { mergeClasses } from '@griffel/react'; | ||
import type { DataGridSlots, DataGridState } from './DataGrid.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import { useTableStyles_unstable } from '../Table/useTableStyles'; | ||
|
||
export const dataGridClassNames: SlotClassNames<DataGridSlots> = { | ||
root: 'fui-DataGrid', | ||
}; | ||
|
||
/** | ||
* Apply styling to the DataGrid slots based on the state | ||
*/ | ||
export const useDataGridStyles_unstable = (state: DataGridState): DataGridState => { | ||
useTableStyles_unstable(state); | ||
state.root.className = mergeClasses(dataGridClassNames.root, state.root.className); | ||
|
||
return state; | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-table/src/components/DataGridBody/DataGridBody.test.tsx
This file contains 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,19 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { DataGridBody } from './DataGridBody'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { DataGridBodyProps } from './DataGridBody.types'; | ||
|
||
describe('DataGridBody', () => { | ||
isConformant<DataGridBodyProps>({ | ||
Component: DataGridBody, | ||
displayName: 'DataGridBody', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<DataGridBody>Default DataGridBody</DataGridBody>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-table/src/components/DataGridBody/DataGridBody.tsx
This file contains 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,18 @@ | ||
import * as React from 'react'; | ||
import { useDataGridBody_unstable } from './useDataGridBody'; | ||
import { renderDataGridBody_unstable } from './renderDataGridBody'; | ||
import { useDataGridBodyStyles_unstable } from './useDataGridBodyStyles'; | ||
import type { DataGridBodyProps } from './DataGridBody.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* DataGridBody component - TODO: add more docs | ||
*/ | ||
export const DataGridBody: ForwardRefComponent<DataGridBodyProps> = React.forwardRef((props, ref) => { | ||
const state = useDataGridBody_unstable(props, ref); | ||
|
||
useDataGridBodyStyles_unstable(state); | ||
return renderDataGridBody_unstable(state); | ||
}); | ||
|
||
DataGridBody.displayName = 'DataGridBody'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-table/src/components/DataGridBody/DataGridBody.types.ts
This file contains 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,13 @@ | ||
import { TableBodySlots, TableBodyProps, TableBodyState } from '../TableBody/TableBody.types'; | ||
|
||
export type DataGridBodySlots = TableBodySlots; | ||
|
||
/** | ||
* DataGridBody Props | ||
*/ | ||
export type DataGridBodyProps = TableBodyProps; | ||
|
||
/** | ||
* State used in rendering DataGridBody | ||
*/ | ||
export type DataGridBodyState = TableBodyState; |
Oops, something went wrong.