-
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: Implement child render function for DataGrid rows (#25476)
* feat: Implement child render function for DataGrid rows * changefile * update package.json * update unit tests
- Loading branch information
Showing
18 changed files
with
364 additions
and
28 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-350ae095-7533-4307-a31f-6d9cbb178cb8.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: Implement child render function for DataGrid rows", | ||
"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
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
14 changes: 11 additions & 3 deletions
14
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 |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { TableContextValues, TableProps, TableSlots, TableState } from '../Table/Table.types'; | ||
import { TableState as HeadlessTableState } from '../../hooks'; | ||
|
||
export type DataGridSlots = TableSlots; | ||
|
||
export type DataGridContextValues = TableContextValues; | ||
export type DataGridContextValues = TableContextValues & { | ||
dataGrid: DataGridContextValue; | ||
}; | ||
|
||
// Use any here since we can't know the user types | ||
// The user is responsible for narrowing the type downstream | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type DataGridContextValue = HeadlessTableState<any>; | ||
|
||
/** | ||
* DataGrid Props | ||
*/ | ||
export type DataGridProps = TableProps; | ||
export type DataGridProps = TableProps & Pick<DataGridContextValue, 'items' | 'columns'>; | ||
|
||
/** | ||
* State used in rendering DataGrid | ||
*/ | ||
export type DataGridState = TableState; | ||
export type DataGridState = TableState & { tableState: HeadlessTableState<unknown> }; |
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
8 changes: 7 additions & 1 deletion
8
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import * as React from 'react'; | ||
import type { DataGridContextValues, DataGridState } from './DataGrid.types'; | ||
import { renderTable_unstable } from '../Table/renderTable'; | ||
import { DataGridContextProvider } from '../../contexts/dataGridContext'; | ||
|
||
/** | ||
* Render the final JSX of DataGrid | ||
*/ | ||
export const renderDataGrid_unstable = (state: DataGridState, contextValues: DataGridContextValues) => { | ||
return renderTable_unstable(state, contextValues); | ||
return ( | ||
<DataGridContextProvider value={contextValues.dataGrid}> | ||
{renderTable_unstable(state, contextValues)} | ||
</DataGridContextProvider> | ||
); | ||
}; |
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
12 changes: 9 additions & 3 deletions
12
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { useTableContextValues_unstable } from '../Table/useTableContextValues'; | ||
import { DataGridState } from './DataGrid.types'; | ||
import { DataGridContextValues, DataGridState } from './DataGrid.types'; | ||
|
||
export function useDataGridContextValues_unstable(state: DataGridState) { | ||
return useTableContextValues_unstable(state); | ||
export function useDataGridContextValues_unstable(state: DataGridState): DataGridContextValues { | ||
const tableContextValues = useTableContextValues_unstable(state); | ||
return { | ||
...tableContextValues, | ||
dataGrid: { | ||
...state.tableState, | ||
}, | ||
}; | ||
} |
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
16 changes: 14 additions & 2 deletions
16
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
6 changes: 2 additions & 4 deletions
6
...mponents/react-table/src/components/DataGridBody/__snapshots__/DataGridBody.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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DataGridBody renders a default state 1`] = ` | ||
exports[`DataGridBody renders items from render function 1`] = ` | ||
<div> | ||
<div | ||
class="fui-DataGridBody fui-TableBody" | ||
role="rowgroup" | ||
> | ||
Default DataGridBody | ||
</div> | ||
/> | ||
</div> | ||
`; |
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
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-table/src/contexts/dataGridContext.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 { createContext, useContextSelector } from '@fluentui/react-context-selector'; | ||
import type { ContextSelector } from '@fluentui/react-context-selector'; | ||
import { DataGridContextValue } from '../components/DataGrid/DataGrid.types'; | ||
import { defaultTableState } from '../hooks'; | ||
|
||
const dataGridContext = createContext<DataGridContextValue | undefined>(undefined); | ||
|
||
const dataGridContextDefaultValue: DataGridContextValue = { | ||
...defaultTableState, | ||
}; | ||
|
||
export const DataGridContextProvider = dataGridContext.Provider; | ||
|
||
export const useDataGridContext_unstable = <T>(selector: ContextSelector<DataGridContextValue, T>) => | ||
useContextSelector(dataGridContext, (ctx = dataGridContextDefaultValue) => selector(ctx)); |
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
Oops, something went wrong.