MCPcopy Index your code
hub / github.com/adobe/react-spectrum / Table

Function Table

packages/react-aria/stories/table/example-docs.tsx:28–102  ·  view source on GitHub ↗
(
  props: TableProps<T> & {
    onResizeStart?: (columnKey: string) => void;
    onResize?: (columnKey: string, width: number) => void;
    onResizeEnd?: (columnKey: string, width: number) => void;
  }
)

Source from the content-addressed store, hash-verified

26import {useTableRowGroup} from '../../src/table/useTableRowGroup';
27
28export function Table<T extends object>(
29 props: TableProps<T> & {
30 onResizeStart?: (columnKey: string) => void;
31 onResize?: (columnKey: string, width: number) => void;
32 onResizeEnd?: (columnKey: string, width: number) => void;
33 }
34): JSX.Element {
35 let {onResizeStart, onResize, onResizeEnd, ...rest} = props;
36
37 let state = useTableState(rest);
38 let ref = useRef<HTMLTableElement | null>(null);
39 let {collection} = state;
40 let {gridProps} = useTable(
41 {
42 ...props,
43 // The table itself is scrollable rather than just the body
44 scrollRef: ref
45 },
46 state,
47 ref
48 );
49
50 let getDefaultMinWidth = useCallback(() => {
51 return 40;
52 }, []);
53
54 let layoutState = useTableColumnResizeState(
55 {
56 // Matches the width of the table itself
57 tableWidth: 300,
58 getDefaultMinWidth
59 },
60 state
61 );
62
63 return (
64 <table {...gridProps} ref={ref} className={classNames(ariaStyles, 'aria-table')}>
65 <ResizableTableRowGroup
66 type="thead"
67 className={classNames(ariaStyles, 'aria-table-rowGroupHeader')}>
68 {collection.headerRows.map(headerRow => (
69 <ResizableTableHeaderRow key={headerRow.key} item={headerRow} state={state}>
70 {[...headerRow.childNodes].map(column => (
71 <ResizableTableColumnHeader
72 key={column.key}
73 column={column}
74 state={state}
75 layoutState={layoutState}
76 onResizeStart={onResizeStart}
77 onResize={onResize}
78 onResizeEnd={onResizeEnd}
79 />
80 ))}
81 </ResizableTableHeaderRow>
82 ))}
83 </ResizableTableRowGroup>
84 <ResizableTableRowGroup
85 className={classNames(ariaStyles, 'aria-table-rowGroupBody')}

Callers

nothing calls this directly

Calls 4

useTableStateFunction · 0.90
useTableFunction · 0.90
classNamesFunction · 0.90

Tested by

no test coverage detected