diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx index c0f204abe..5e3f7834b 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx @@ -1,4 +1,4 @@ -import { Table, TableBody, TableCell, TableCellLayout, TableColumnDefinition, TableHeader, TableHeaderCell, TableRow, TableRowId, TableSelectionCell, createTableColumn, useArrowNavigationGroup, useTableFeatures, useTableSelection } from '@fluentui/react-components'; +import { Menu, MenuItem, MenuList, MenuPopover, MenuTrigger, Table, TableBody, TableCell, TableCellLayout, TableColumnDefinition, TableColumnSizingOptions, TableHeader, TableHeaderCell, TableRow, TableRowId, TableSelectionCell, createTableColumn, useArrowNavigationGroup, useTableColumnSizing_unstable, useTableFeatures, useTableSelection } from '@fluentui/react-components'; import React, { useEffect } from 'react'; export type DocumentsTableComponentItem = { @@ -12,50 +12,60 @@ export interface IDocumentsTableComponentProps { style?: React.CSSProperties; } +const columns: TableColumnDefinition[] = [ + createTableColumn({ + columnId: "id", + compare: (a, b) => { + return a.id.localeCompare(b.id); + }, + renderHeaderCell: () => { + return "id"; + }, + renderCell: (item) => { + return ( + {item.id} + ); + }, + }), + createTableColumn({ + columnId: "type", + compare: (a, b) => { + return a.type.localeCompare(b.type); + }, + renderHeaderCell: () => { + return "/type"; + }, + renderCell: (item) => { + return ( + {item.type} + ); + }, + }), +]; + export const DocumentsTableComponent: React.FC = ({ items, onSelectedItem, style, }: IDocumentsTableComponentProps) => { - const columns: TableColumnDefinition[] = [ - createTableColumn({ - columnId: "id", - compare: (a, b) => { - return a.id.localeCompare(b.id); - }, - renderHeaderCell: () => { - return "id"; - }, - renderCell: (item) => { - return ( - {item.id} - ); - }, - }), - createTableColumn({ - columnId: "type", - compare: (a, b) => { - return a.type.localeCompare(b.type); - }, - renderHeaderCell: () => { - return "/type"; - }, - renderCell: (item) => { - return ( - {item.type} - ); - }, - }), - ]; + const [columnSizingOptions, setColumnSizingOptions] = React.useState({ + id: { + idealWidth: 300, + minWidth: 273, + }, + type: { + minWidth: 110, + defaultWidth: 120, + }, + }); - // const [columnSizingOptions] = React.useState({ - // id: { - // idealWidth: 300, - // minWidth: 150, - // }, - // type: { - // minWidth: 110, - // defaultWidth: 250, - // }, - // }); + const onColumnResize = React.useCallback((_, { columnId, width }) => { + setColumnSizingOptions((state) => ({ + ...state, + [columnId]: { + ...state[columnId], + idealWidth: width, + }, + })); + }, []); const [selectedRows, setSelectedRows] = React.useState>( () => new Set([0]) @@ -63,8 +73,8 @@ export const DocumentsTableComponent: React.FC = const { getRows, - // columnSizing_unstable, - // tableRef, + columnSizing_unstable: columnSizing, + tableRef, selection: { allRowsSelected, someRowsSelected, @@ -78,7 +88,7 @@ export const DocumentsTableComponent: React.FC = items, }, [ - // useTableColumnSizing_unstable({ columnSizingOptions }), + useTableColumnSizing_unstable({ columnSizingOptions, onColumnResize }), useTableSelection({ selectionMode: "multiselect", selectedItems: selectedRows, @@ -126,10 +136,10 @@ export const DocumentsTableComponent: React.FC = const tableProps = { "aria-label": "Filtered documents table", role: "grid", + ...columnSizing.getTableProps(), ...keyboardNavAttr, - // ...columnSizing_unstable.getTableProps(), size: "extra-small", - // ref: tableRef, + ref: tableRef, ...style, }; @@ -145,8 +155,29 @@ export const DocumentsTableComponent: React.FC = onKeyDown={toggleAllKeydown} checkboxIndicator={{ "aria-label": "Select all rows " }} /> - id - /type + {columns.map((column, index) => ( + + + + {column.renderHeaderCell()} + + + + + + Keyboard Column Resizing + + + + + ))} @@ -164,12 +195,16 @@ export const DocumentsTableComponent: React.FC = onClick={onClick} onKeyDown={onKeyDown} /> - setSelectedRows(new Set([index]))} onKeyDown={onKeyDown}> - {item.id} - - - {item.type} - + {columns.map((column) => ( + setSelectedRows(new Set([index]))} + onKeyDown={onKeyDown} + {...columnSizing.getTableCellProps(column.columnId)} + > + {column.renderCell(item)} + + ))} ))}