@veeqo/ui 9.9.1 → 9.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DataGrid/DataGrid.cjs +40 -8
- package/dist/components/DataGrid/DataGrid.cjs.map +1 -1
- package/dist/components/DataGrid/DataGrid.d.ts +1 -1
- package/dist/components/DataGrid/DataGrid.js +40 -8
- package/dist/components/DataGrid/DataGrid.js.map +1 -1
- package/dist/components/DataGrid/columns/SelectionColumnDefinition.cjs +36 -0
- package/dist/components/DataGrid/columns/SelectionColumnDefinition.cjs.map +1 -0
- package/dist/components/DataGrid/columns/SelectionColumnDefinition.d.ts +2 -0
- package/dist/components/DataGrid/columns/SelectionColumnDefinition.js +30 -0
- package/dist/components/DataGrid/columns/SelectionColumnDefinition.js.map +1 -0
- package/dist/components/DataGrid/columns/index.d.ts +1 -0
- package/dist/components/DataGrid/constants.cjs +2 -0
- package/dist/components/DataGrid/constants.cjs.map +1 -1
- package/dist/components/DataGrid/constants.d.ts +1 -0
- package/dist/components/DataGrid/constants.js +2 -1
- package/dist/components/DataGrid/constants.js.map +1 -1
- package/dist/components/DataGrid/hooks/index.d.ts +1 -0
- package/dist/components/DataGrid/hooks/useKeyboardNavigation.cjs +112 -0
- package/dist/components/DataGrid/hooks/useKeyboardNavigation.cjs.map +1 -0
- package/dist/components/DataGrid/hooks/useKeyboardNavigation.d.ts +14 -0
- package/dist/components/DataGrid/hooks/useKeyboardNavigation.js +110 -0
- package/dist/components/DataGrid/hooks/useKeyboardNavigation.js.map +1 -0
- package/dist/components/DataGrid/hooks/useSelectionState.cjs +51 -0
- package/dist/components/DataGrid/hooks/useSelectionState.cjs.map +1 -0
- package/dist/components/DataGrid/hooks/useSelectionState.d.ts +18 -0
- package/dist/components/DataGrid/hooks/useSelectionState.js +49 -0
- package/dist/components/DataGrid/hooks/useSelectionState.js.map +1 -0
- package/dist/components/DataGrid/types/DataGridProps.d.ts +23 -1
- package/dist/components/DataGrid/types/enums.d.ts +1 -0
- package/dist/components/DataGrid/types/index.d.ts +1 -1
- package/dist/components/DataGrid/utils/getAriaRoles.cjs +9 -3
- package/dist/components/DataGrid/utils/getAriaRoles.cjs.map +1 -1
- package/dist/components/DataGrid/utils/getAriaRoles.d.ts +1 -1
- package/dist/components/DataGrid/utils/getAriaRoles.js +9 -3
- package/dist/components/DataGrid/utils/getAriaRoles.js.map +1 -1
- package/dist/components/Popover/hooks/useHandleFocus.cjs +4 -4
- package/dist/components/Popover/hooks/useHandleFocus.cjs.map +1 -1
- package/dist/components/Popover/hooks/useHandleFocus.js +1 -1
- package/dist/components/Popover/hooks/useHandleFocus.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +2 -2
- package/dist/components/Radio/Radio.cjs.map +1 -1
- package/dist/components/Radio/Radio.d.ts +2 -2
- package/dist/components/Radio/Radio.js +2 -2
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/utils/tabbableSelectors.cjs +6 -0
- package/dist/utils/tabbableSelectors.cjs.map +1 -0
- package/dist/utils/tabbableSelectors.d.ts +1 -0
- package/dist/utils/tabbableSelectors.js +4 -0
- package/dist/utils/tabbableSelectors.js.map +1 -0
- package/package.json +1 -1
|
@@ -15,6 +15,10 @@ var Footer = require('./components/Footer/Footer.cjs');
|
|
|
15
15
|
var GridContainer = require('./components/GridContainer/GridContainer.cjs');
|
|
16
16
|
var useSortingState = require('./hooks/useSortingState.cjs');
|
|
17
17
|
var usePinnedColumnLayout = require('./hooks/usePinnedColumnLayout.cjs');
|
|
18
|
+
var useKeyboardNavigation = require('./hooks/useKeyboardNavigation.cjs');
|
|
19
|
+
var useSelectionState = require('./hooks/useSelectionState.cjs');
|
|
20
|
+
var constants = require('./constants.cjs');
|
|
21
|
+
var SelectionColumnDefinition = require('./columns/SelectionColumnDefinition.cjs');
|
|
18
22
|
|
|
19
23
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
20
24
|
|
|
@@ -38,20 +42,33 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
38
42
|
*
|
|
39
43
|
* *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*
|
|
40
44
|
*/
|
|
41
|
-
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, 'aria-label': ariaLabel, }) => {
|
|
45
|
+
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, enableKeyboardNavigation = false, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, 'aria-label': ariaLabel, }) => {
|
|
42
46
|
const containerRef = React.useRef(null);
|
|
47
|
+
const tableRef = React.useRef(null);
|
|
43
48
|
const showFooter = React.useMemo(() => columns.some((column) => column.renderFooter), [columns]);
|
|
44
|
-
const ariaRoles = React.useMemo(() => getAriaRoles.getAriaRoles(), []);
|
|
49
|
+
const ariaRoles = React.useMemo(() => getAriaRoles.getAriaRoles(enableKeyboardNavigation), [enableKeyboardNavigation]);
|
|
45
50
|
const enableColumnResizing = React.useMemo(() => resizeMode !== 'off', [resizeMode]);
|
|
51
|
+
/**
|
|
52
|
+
* Hooks to handle state for selection and sorting.
|
|
53
|
+
*/
|
|
54
|
+
const { enableRowSelection, enableMultiRowSelection, rowSelection, onRowSelectionChange } = useSelectionState.useSelectionState({
|
|
55
|
+
selectionMode,
|
|
56
|
+
selectedRows,
|
|
57
|
+
disabledRows,
|
|
58
|
+
onSelectionChanged,
|
|
59
|
+
});
|
|
60
|
+
const { enableSorting, enableMultiRemove, enableSortingRemoval, manualSorting, sorting, onSortingChange, } = useSortingState.useSortingState({ columns, sortState, onSortChanged });
|
|
46
61
|
/**
|
|
47
62
|
* Mapping of column definitions.
|
|
48
63
|
*/
|
|
49
64
|
const columnMapper = React.useRef(new ColumnMapper.ColumnMapper());
|
|
50
65
|
const mappedColumnDefinitions = React.useMemo(() => {
|
|
51
66
|
const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));
|
|
67
|
+
if (enableRowSelection) {
|
|
68
|
+
mappedColumns.unshift(SelectionColumnDefinition.SelectionColumnDefinition);
|
|
69
|
+
}
|
|
52
70
|
return mappedColumns;
|
|
53
|
-
}, [columns]);
|
|
54
|
-
const { enableSorting, enableMultiRemove, enableSortingRemoval, manualSorting, sorting, onSortingChange, } = useSortingState.useSortingState({ columns, sortState, onSortChanged });
|
|
71
|
+
}, [columns, enableRowSelection]);
|
|
55
72
|
/**
|
|
56
73
|
* Stable references for column states (visibility, order, pinning).
|
|
57
74
|
*/
|
|
@@ -60,8 +77,12 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
60
77
|
if (!columnOrdering || columnOrdering.length === 0) {
|
|
61
78
|
return undefined;
|
|
62
79
|
}
|
|
80
|
+
// If we have a custom column order, we need to make sure the selection column always appears first.
|
|
81
|
+
if (enableRowSelection) {
|
|
82
|
+
return ['selection', ...columnOrdering];
|
|
83
|
+
}
|
|
63
84
|
return columnOrdering;
|
|
64
|
-
}, [columnOrdering]);
|
|
85
|
+
}, [columnOrdering, enableRowSelection]);
|
|
65
86
|
// Column visibiilty - record of column ID's to visibility, where false/no value = hidden.
|
|
66
87
|
const columnVisibility = React.useMemo(() => {
|
|
67
88
|
// We can't have no columns visible - if the array is empty we show them all.
|
|
@@ -76,11 +97,16 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
76
97
|
// Pinned columns
|
|
77
98
|
const columnPinning = React.useMemo(() => {
|
|
78
99
|
var _a, _b;
|
|
100
|
+
let left = (_a = pinnedColumns === null || pinnedColumns === undefined ? undefined : pinnedColumns.left) !== null && _a !== undefined ? _a : [];
|
|
101
|
+
// If we have any left-pinned columns, we need to include the selection column as it should appear first.
|
|
102
|
+
if (enableRowSelection && left.length > 0) {
|
|
103
|
+
left = [constants.SELECTION_COLUMN_ID, ...left];
|
|
104
|
+
}
|
|
79
105
|
return {
|
|
80
|
-
left
|
|
106
|
+
left,
|
|
81
107
|
right: (_b = pinnedColumns === null || pinnedColumns === undefined ? undefined : pinnedColumns.right) !== null && _b !== undefined ? _b : [],
|
|
82
108
|
};
|
|
83
|
-
}, [pinnedColumns]);
|
|
109
|
+
}, [pinnedColumns, enableRowSelection]);
|
|
84
110
|
/**
|
|
85
111
|
* Setup the TanStack table, including mapped column definitions, row data, and any additional state such as
|
|
86
112
|
* column visibility and ordering.
|
|
@@ -102,12 +128,17 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
102
128
|
onSortingChange,
|
|
103
129
|
// Pinning
|
|
104
130
|
enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,
|
|
131
|
+
// Selection
|
|
132
|
+
enableRowSelection,
|
|
133
|
+
enableMultiRowSelection,
|
|
134
|
+
onRowSelectionChange,
|
|
105
135
|
// Inject external table state
|
|
106
136
|
state: {
|
|
107
137
|
columnOrder,
|
|
108
138
|
columnVisibility,
|
|
109
139
|
columnPinning,
|
|
110
140
|
sorting,
|
|
141
|
+
rowSelection,
|
|
111
142
|
},
|
|
112
143
|
});
|
|
113
144
|
/**
|
|
@@ -118,7 +149,8 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
118
149
|
* Other hooks
|
|
119
150
|
*/
|
|
120
151
|
useDragToScroll.useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });
|
|
121
|
-
|
|
152
|
+
useKeyboardNavigation.useKeyboardNavigation({ tableRef, enableKeyboardNavigation });
|
|
153
|
+
return (React__default.default.createElement(GridContainer.GridContainer, { containerRef: containerRef, tableRef: tableRef, borderMode: borderMode, containerStyles: { ...containerStyle, ...pinnedColumnLayoutStyles }, ariaRoles: ariaRoles, enableResizeableColumns: enableColumnResizing, density: density, table: table, "aria-label": ariaLabel },
|
|
122
154
|
enableColumnResizing && React__default.default.createElement(Columns.Columns, { table: table }),
|
|
123
155
|
React__default.default.createElement(Header.Header, { table: table }),
|
|
124
156
|
table.getState().columnSizingInfo.isResizingColumn ? (React__default.default.createElement(Body.MemoizedBody, { table: table, ariaRoles: ariaRoles, striped: striped })) : (React__default.default.createElement(Body.Body, { table: table, ariaRoles: ariaRoles, striped: striped })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.cjs","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { ColumnMapper, getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { MemoizedBody } from './components/Body';\n\nimport { usePinnedColumnLayout, useSortingState } from './hooks';\n\n/**\n * [WIP]\n *\n * A DataGrid component which renders data in a two-dimensional format, with columns and rows. Unlike the `DataTable`\n * component, the `DataGrid` supports both flat and hierarchical (tree) data.\n *\n * Under the hood, it uses [TanStack Table](http://tanstack.com/table/) for table management, and aims to replicate functionality\n * available in major third party grid components such as CloudScape's Table component, AgGrid, etc.\n *\n * Supported features include:\n * - Pinning, resizing (incl. smooth resizing), reordering, and hiding of columns\n * - Selection (single and multiple) and disabling of rows.\n * - Rendering of arbitrarily nested data, expanding/collapsing, and custom full-width 'group' rows.\n * - In-built keyboard navigation with arrow keys, and drag to scroll.\n * - Configurable density.\n *\n * *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*\n */\nexport const DataGrid = ({\n density = 'base',\n striped = true,\n borderMode = 'full',\n resizeMode = 'off',\n containerStyle,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n\n sortState,\n onSortChanged,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n const containerRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(() => columns.some((column) => column.renderFooter), [columns]);\n const ariaRoles = useMemo(() => getAriaRoles(), []);\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Mapping of column definitions.\n */\n const columnMapper = useRef(new ColumnMapper());\n const mappedColumnDefinitions = useMemo(() => {\n const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));\n return mappedColumns;\n }, [columns]);\n\n const {\n enableSorting,\n enableMultiRemove,\n enableSortingRemoval,\n manualSorting,\n sorting,\n onSortingChange,\n } = useSortingState({ columns, sortState, onSortChanged });\n\n /**\n * Stable references for column states (visibility, order, pinning).\n */\n\n // Column render order - the order of the array indicates the order on screen.\n const columnOrder = useMemo(() => {\n if (!columnOrdering || columnOrdering.length === 0) {\n return undefined;\n }\n\n return columnOrdering;\n }, [columnOrdering]);\n\n // Column visibiilty - record of column ID's to visibility, where false/no value = hidden.\n const columnVisibility = useMemo(() => {\n // We can't have no columns visible - if the array is empty we show them all.\n if (!hiddenColumns || hiddenColumns.length === columns.length) {\n return undefined;\n }\n\n return columns.reduce(\n (acc, column) => ({\n ...acc,\n [column.id]: !hiddenColumns.includes(column.id),\n }),\n {},\n );\n }, [hiddenColumns, columns]);\n\n // Pinned columns\n const columnPinning = useMemo(() => {\n return {\n left: pinnedColumns?.left ?? [],\n right: pinnedColumns?.right ?? [],\n };\n }, [pinnedColumns]);\n\n /**\n * Setup the TanStack table, including mapped column definitions, row data, and any additional state such as\n * column visibility and ordering.\n */\n const table = useReactTable<any>({\n data,\n columns: mappedColumnDefinitions,\n\n // Column settings\n columnResizeMode: resizeMode === 'off' ? undefined : resizeMode,\n enableColumnResizing,\n\n // Row model\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n\n // Sorting\n enableSorting,\n enableSortingRemoval,\n enableMultiRemove,\n manualSorting,\n onSortingChange,\n\n // Pinning\n enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n },\n });\n\n /**\n * Pinned column layout\n */\n const { pinnedColumnLayoutStyles } = usePinnedColumnLayout({ table });\n\n /**\n * Other hooks\n */\n useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });\n\n return (\n <GridContainer\n containerRef={containerRef}\n borderMode={borderMode}\n containerStyles={{ ...containerStyle, ...pinnedColumnLayoutStyles }}\n ariaRoles={ariaRoles}\n enableResizeableColumns={enableColumnResizing}\n density={density}\n table={table}\n aria-label={ariaLabel}\n >\n {/* Columns */}\n {enableColumnResizing && <Columns table={table} />}\n\n {/* Header */}\n <Header table={table} />\n\n {/* Body */}\n {table.getState().columnSizingInfo.isResizingColumn ? (\n <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />\n ) : (\n <Body table={table} ariaRoles={ariaRoles} striped={striped} />\n )}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["useRef","useMemo","getAriaRoles","ColumnMapper","useSortingState","useReactTable","getCoreRowModel","usePinnedColumnLayout","useDragToScroll","React","GridContainer","Columns","Header","MemoizedBody","Body","Footer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;AAiBG;MACU,QAAQ,GAAG,CAAC,EACvB,OAAO,GAAG,MAAM,EAChB,OAAO,GAAG,IAAI,EACd,UAAU,GAAG,MAAM,EACnB,UAAU,GAAG,KAAK,EAClB,cAAc,EAEd,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EAEb,IAAI,EACJ,QAAQ,EAER,SAAS,EACT,aAAa,EAEb,YAAY,EAAE,SAAS,GACT,KAAI;AAClB,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAmB,IAAI,CAAC;IAEnD,MAAM,UAAU,GAAGC,aAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAA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zF,IAAA,QACEC,sBAAC,CAAA,aAAA,CAAAC,2BAAa,EACZ,EAAA,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,wBAAwB,EAAE,EACnE,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,oBAAoB,EAC7C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,gBACA,SAAS,EAAA;AAGpB,QAAA,oBAAoB,IAAID,sBAAC,CAAA,aAAA,CAAAE,eAAO,IAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGlD,QAAAF,sBAAA,CAAA,aAAA,CAACG,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAI,CAAA;QAGvB,KAAK,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,IACjDH,sBAAC,CAAA,aAAA,CAAAI,iBAAY,IAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,KAEtEJ,sBAAA,CAAA,aAAA,CAACK,SAAI,EAAC,EAAA,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,CAC/D;AAGA,QAAA,UAAU,IAAIL,sBAAA,CAAA,aAAA,CAACM,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAI,CAAA,CAC/C;AAEpB;;;;"}
|
|
1
|
+
{"version":3,"file":"DataGrid.cjs","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { ColumnMapper, getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { MemoizedBody } from './components/Body';\n\nimport { usePinnedColumnLayout, useSortingState, useKeyboardNavigation } from './hooks';\n\nimport { useSelectionState } from './hooks/useSelectionState';\nimport { SELECTION_COLUMN_ID } from './constants';\nimport { SelectionColumnDefinition } from './columns';\n\n/**\n * [WIP]\n *\n * A DataGrid component which renders data in a two-dimensional format, with columns and rows. Unlike the `DataTable`\n * component, the `DataGrid` supports both flat and hierarchical (tree) data.\n *\n * Under the hood, it uses [TanStack Table](http://tanstack.com/table/) for table management, and aims to replicate functionality\n * available in major third party grid components such as CloudScape's Table component, AgGrid, etc.\n *\n * Supported features include:\n * - Pinning, resizing (incl. smooth resizing), reordering, and hiding of columns\n * - Selection (single and multiple) and disabling of rows.\n * - Rendering of arbitrarily nested data, expanding/collapsing, and custom full-width 'group' rows.\n * - In-built keyboard navigation with arrow keys, and drag to scroll.\n * - Configurable density.\n *\n * *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*\n */\nexport const DataGrid = ({\n density = 'base',\n striped = true,\n borderMode = 'full',\n resizeMode = 'off',\n containerStyle,\n enableKeyboardNavigation = false,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n\n sortState,\n onSortChanged,\n\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(() => columns.some((column) => column.renderFooter), [columns]);\n const ariaRoles = useMemo(\n () => getAriaRoles(enableKeyboardNavigation),\n [enableKeyboardNavigation],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection and sorting.\n */\n\n const { enableRowSelection, enableMultiRowSelection, rowSelection, onRowSelectionChange } =\n useSelectionState({\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n });\n\n const {\n enableSorting,\n enableMultiRemove,\n enableSortingRemoval,\n manualSorting,\n sorting,\n onSortingChange,\n } = useSortingState({ columns, sortState, onSortChanged });\n\n /**\n * Mapping of column definitions.\n */\n const columnMapper = useRef(new ColumnMapper());\n const mappedColumnDefinitions = useMemo(() => {\n const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));\n\n if (enableRowSelection) {\n mappedColumns.unshift(SelectionColumnDefinition);\n }\n\n return mappedColumns;\n }, [columns, enableRowSelection]);\n\n /**\n * Stable references for column states (visibility, order, pinning).\n */\n\n // Column render order - the order of the array indicates the order on screen.\n const columnOrder = useMemo(() => {\n if (!columnOrdering || columnOrdering.length === 0) {\n return undefined;\n }\n\n // If we have a custom column order, we need to make sure the selection column always appears first.\n if (enableRowSelection) {\n return ['selection', ...columnOrdering];\n }\n\n return columnOrdering;\n }, [columnOrdering, enableRowSelection]);\n\n // Column visibiilty - record of column ID's to visibility, where false/no value = hidden.\n const columnVisibility = useMemo(() => {\n // We can't have no columns visible - if the array is empty we show them all.\n if (!hiddenColumns || hiddenColumns.length === columns.length) {\n return undefined;\n }\n\n return columns.reduce(\n (acc, column) => ({\n ...acc,\n [column.id]: !hiddenColumns.includes(column.id),\n }),\n {},\n );\n }, [hiddenColumns, columns]);\n\n // Pinned columns\n const columnPinning = useMemo(() => {\n let left = pinnedColumns?.left ?? [];\n\n // If we have any left-pinned columns, we need to include the selection column as it should appear first.\n if (enableRowSelection && left.length > 0) {\n left = [SELECTION_COLUMN_ID, ...left];\n }\n\n return {\n left,\n right: pinnedColumns?.right ?? [],\n };\n }, [pinnedColumns, enableRowSelection]);\n\n /**\n * Setup the TanStack table, including mapped column definitions, row data, and any additional state such as\n * column visibility and ordering.\n */\n const table = useReactTable<any>({\n data,\n columns: mappedColumnDefinitions,\n\n // Column settings\n columnResizeMode: resizeMode === 'off' ? undefined : resizeMode,\n enableColumnResizing,\n\n // Row model\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n\n // Sorting\n enableSorting,\n enableSortingRemoval,\n enableMultiRemove,\n manualSorting,\n onSortingChange,\n\n // Pinning\n enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,\n\n // Selection\n enableRowSelection,\n enableMultiRowSelection,\n onRowSelectionChange,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n },\n });\n\n /**\n * Pinned column layout\n */\n const { pinnedColumnLayoutStyles } = usePinnedColumnLayout({ table });\n\n /**\n * Other hooks\n */\n useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });\n useKeyboardNavigation({ tableRef, enableKeyboardNavigation });\n\n return (\n <GridContainer\n containerRef={containerRef}\n tableRef={tableRef}\n borderMode={borderMode}\n containerStyles={{ ...containerStyle, ...pinnedColumnLayoutStyles }}\n ariaRoles={ariaRoles}\n enableResizeableColumns={enableColumnResizing}\n density={density}\n table={table}\n aria-label={ariaLabel}\n >\n {/* Columns */}\n {enableColumnResizing && <Columns table={table} />}\n\n {/* Header */}\n <Header table={table} />\n\n {/* Body */}\n {table.getState().columnSizingInfo.isResizingColumn ? (\n <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />\n ) : (\n <Body table={table} ariaRoles={ariaRoles} striped={striped} />\n )}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["useRef","useMemo","getAriaRoles","useSelectionState","useSortingState","ColumnMapper","SelectionColumnDefinition","SELECTION_COLUMN_ID","useReactTable","getCoreRowModel","usePinnedColumnLayout","useDragToScroll","useKeyboardNavigation","React","GridContainer","Columns","Header","MemoizedBody","Body","Footer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,QAAQ,GAAG,CAAC,EACvB,OAAO,GAAG,MAAM,EAChB,OAAO,GAAG,IAAI,EACd,UAAU,GAAG,MAAM,EACnB,UAAU,GAAG,KAAK,EAClB,cAAc,EACd,wBAAwB,GAAG,KAAK,EAEh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,EAClB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,wBAAwB,EAAE,EACnE,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,oBAAoB,EAC7C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,gBACA,SAAS,EAAA;AAGpB,QAAA,oBAAoB,IAAID,sBAAC,CAAA,aAAA,CAAAE,eAAO,IAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGlD,QAAAF,sBAAA,CAAA,aAAA,CAACG,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAI,CAAA;QAGvB,KAAK,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,IACjDH,sBAAC,CAAA,aAAA,CAAAI,iBAAY,IAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,KAEtEJ,sBAAA,CAAA,aAAA,CAACK,SAAI,EAAC,EAAA,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,CAC/D;AAGA,QAAA,UAAU,IAAIL,sBAAA,CAAA,aAAA,CAACM,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAI,CAAA,CAC/C;AAEpB;;;;"}
|
|
@@ -18,4 +18,4 @@ import { DataGridProps } from './types';
|
|
|
18
18
|
*
|
|
19
19
|
* *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*
|
|
20
20
|
*/
|
|
21
|
-
export declare const DataGrid: ({ density, striped, borderMode, resizeMode, containerStyle, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, "aria-label": ariaLabel, }: DataGridProps) => React.JSX.Element;
|
|
21
|
+
export declare const DataGrid: ({ density, striped, borderMode, resizeMode, containerStyle, enableKeyboardNavigation, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, "aria-label": ariaLabel, }: DataGridProps) => React.JSX.Element;
|
|
@@ -13,6 +13,10 @@ import { Footer } from './components/Footer/Footer.js';
|
|
|
13
13
|
import { GridContainer } from './components/GridContainer/GridContainer.js';
|
|
14
14
|
import { useSortingState } from './hooks/useSortingState.js';
|
|
15
15
|
import { usePinnedColumnLayout } from './hooks/usePinnedColumnLayout.js';
|
|
16
|
+
import { useKeyboardNavigation } from './hooks/useKeyboardNavigation.js';
|
|
17
|
+
import { useSelectionState } from './hooks/useSelectionState.js';
|
|
18
|
+
import { SELECTION_COLUMN_ID } from './constants.js';
|
|
19
|
+
import { SelectionColumnDefinition } from './columns/SelectionColumnDefinition.js';
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* [WIP]
|
|
@@ -32,20 +36,33 @@ import { usePinnedColumnLayout } from './hooks/usePinnedColumnLayout.js';
|
|
|
32
36
|
*
|
|
33
37
|
* *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*
|
|
34
38
|
*/
|
|
35
|
-
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, 'aria-label': ariaLabel, }) => {
|
|
39
|
+
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, enableKeyboardNavigation = false, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, 'aria-label': ariaLabel, }) => {
|
|
36
40
|
const containerRef = useRef(null);
|
|
41
|
+
const tableRef = useRef(null);
|
|
37
42
|
const showFooter = useMemo(() => columns.some((column) => column.renderFooter), [columns]);
|
|
38
|
-
const ariaRoles = useMemo(() => getAriaRoles(), []);
|
|
43
|
+
const ariaRoles = useMemo(() => getAriaRoles(enableKeyboardNavigation), [enableKeyboardNavigation]);
|
|
39
44
|
const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);
|
|
45
|
+
/**
|
|
46
|
+
* Hooks to handle state for selection and sorting.
|
|
47
|
+
*/
|
|
48
|
+
const { enableRowSelection, enableMultiRowSelection, rowSelection, onRowSelectionChange } = useSelectionState({
|
|
49
|
+
selectionMode,
|
|
50
|
+
selectedRows,
|
|
51
|
+
disabledRows,
|
|
52
|
+
onSelectionChanged,
|
|
53
|
+
});
|
|
54
|
+
const { enableSorting, enableMultiRemove, enableSortingRemoval, manualSorting, sorting, onSortingChange, } = useSortingState({ columns, sortState, onSortChanged });
|
|
40
55
|
/**
|
|
41
56
|
* Mapping of column definitions.
|
|
42
57
|
*/
|
|
43
58
|
const columnMapper = useRef(new ColumnMapper());
|
|
44
59
|
const mappedColumnDefinitions = useMemo(() => {
|
|
45
60
|
const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));
|
|
61
|
+
if (enableRowSelection) {
|
|
62
|
+
mappedColumns.unshift(SelectionColumnDefinition);
|
|
63
|
+
}
|
|
46
64
|
return mappedColumns;
|
|
47
|
-
}, [columns]);
|
|
48
|
-
const { enableSorting, enableMultiRemove, enableSortingRemoval, manualSorting, sorting, onSortingChange, } = useSortingState({ columns, sortState, onSortChanged });
|
|
65
|
+
}, [columns, enableRowSelection]);
|
|
49
66
|
/**
|
|
50
67
|
* Stable references for column states (visibility, order, pinning).
|
|
51
68
|
*/
|
|
@@ -54,8 +71,12 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
54
71
|
if (!columnOrdering || columnOrdering.length === 0) {
|
|
55
72
|
return undefined;
|
|
56
73
|
}
|
|
74
|
+
// If we have a custom column order, we need to make sure the selection column always appears first.
|
|
75
|
+
if (enableRowSelection) {
|
|
76
|
+
return ['selection', ...columnOrdering];
|
|
77
|
+
}
|
|
57
78
|
return columnOrdering;
|
|
58
|
-
}, [columnOrdering]);
|
|
79
|
+
}, [columnOrdering, enableRowSelection]);
|
|
59
80
|
// Column visibiilty - record of column ID's to visibility, where false/no value = hidden.
|
|
60
81
|
const columnVisibility = useMemo(() => {
|
|
61
82
|
// We can't have no columns visible - if the array is empty we show them all.
|
|
@@ -70,11 +91,16 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
70
91
|
// Pinned columns
|
|
71
92
|
const columnPinning = useMemo(() => {
|
|
72
93
|
var _a, _b;
|
|
94
|
+
let left = (_a = pinnedColumns === null || pinnedColumns === undefined ? undefined : pinnedColumns.left) !== null && _a !== undefined ? _a : [];
|
|
95
|
+
// If we have any left-pinned columns, we need to include the selection column as it should appear first.
|
|
96
|
+
if (enableRowSelection && left.length > 0) {
|
|
97
|
+
left = [SELECTION_COLUMN_ID, ...left];
|
|
98
|
+
}
|
|
73
99
|
return {
|
|
74
|
-
left
|
|
100
|
+
left,
|
|
75
101
|
right: (_b = pinnedColumns === null || pinnedColumns === undefined ? undefined : pinnedColumns.right) !== null && _b !== undefined ? _b : [],
|
|
76
102
|
};
|
|
77
|
-
}, [pinnedColumns]);
|
|
103
|
+
}, [pinnedColumns, enableRowSelection]);
|
|
78
104
|
/**
|
|
79
105
|
* Setup the TanStack table, including mapped column definitions, row data, and any additional state such as
|
|
80
106
|
* column visibility and ordering.
|
|
@@ -96,12 +122,17 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
96
122
|
onSortingChange,
|
|
97
123
|
// Pinning
|
|
98
124
|
enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,
|
|
125
|
+
// Selection
|
|
126
|
+
enableRowSelection,
|
|
127
|
+
enableMultiRowSelection,
|
|
128
|
+
onRowSelectionChange,
|
|
99
129
|
// Inject external table state
|
|
100
130
|
state: {
|
|
101
131
|
columnOrder,
|
|
102
132
|
columnVisibility,
|
|
103
133
|
columnPinning,
|
|
104
134
|
sorting,
|
|
135
|
+
rowSelection,
|
|
105
136
|
},
|
|
106
137
|
});
|
|
107
138
|
/**
|
|
@@ -112,7 +143,8 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
112
143
|
* Other hooks
|
|
113
144
|
*/
|
|
114
145
|
useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });
|
|
115
|
-
|
|
146
|
+
useKeyboardNavigation({ tableRef, enableKeyboardNavigation });
|
|
147
|
+
return (React__default.createElement(GridContainer, { containerRef: containerRef, tableRef: tableRef, borderMode: borderMode, containerStyles: { ...containerStyle, ...pinnedColumnLayoutStyles }, ariaRoles: ariaRoles, enableResizeableColumns: enableColumnResizing, density: density, table: table, "aria-label": ariaLabel },
|
|
116
148
|
enableColumnResizing && React__default.createElement(Columns, { table: table }),
|
|
117
149
|
React__default.createElement(Header, { table: table }),
|
|
118
150
|
table.getState().columnSizingInfo.isResizingColumn ? (React__default.createElement(MemoizedBody, { table: table, ariaRoles: ariaRoles, striped: striped })) : (React__default.createElement(Body, { table: table, ariaRoles: ariaRoles, striped: striped })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.js","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { ColumnMapper, getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { MemoizedBody } from './components/Body';\n\nimport { usePinnedColumnLayout, useSortingState } from './hooks';\n\n/**\n * [WIP]\n *\n * A DataGrid component which renders data in a two-dimensional format, with columns and rows. Unlike the `DataTable`\n * component, the `DataGrid` supports both flat and hierarchical (tree) data.\n *\n * Under the hood, it uses [TanStack Table](http://tanstack.com/table/) for table management, and aims to replicate functionality\n * available in major third party grid components such as CloudScape's Table component, AgGrid, etc.\n *\n * Supported features include:\n * - Pinning, resizing (incl. smooth resizing), reordering, and hiding of columns\n * - Selection (single and multiple) and disabling of rows.\n * - Rendering of arbitrarily nested data, expanding/collapsing, and custom full-width 'group' rows.\n * - In-built keyboard navigation with arrow keys, and drag to scroll.\n * - Configurable density.\n *\n * *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*\n */\nexport const DataGrid = ({\n density = 'base',\n striped = true,\n borderMode = 'full',\n resizeMode = 'off',\n containerStyle,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n\n sortState,\n onSortChanged,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n const containerRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(() => columns.some((column) => column.renderFooter), [columns]);\n const ariaRoles = useMemo(() => getAriaRoles(), []);\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Mapping of column definitions.\n */\n const columnMapper = useRef(new ColumnMapper());\n const mappedColumnDefinitions = useMemo(() => {\n const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));\n return mappedColumns;\n }, [columns]);\n\n const {\n enableSorting,\n enableMultiRemove,\n enableSortingRemoval,\n manualSorting,\n sorting,\n onSortingChange,\n } = useSortingState({ columns, sortState, onSortChanged });\n\n /**\n * Stable references for column states (visibility, order, pinning).\n */\n\n // Column render order - the order of the array indicates the order on screen.\n const columnOrder = useMemo(() => {\n if (!columnOrdering || columnOrdering.length === 0) {\n return undefined;\n }\n\n return columnOrdering;\n }, [columnOrdering]);\n\n // Column visibiilty - record of column ID's to visibility, where false/no value = hidden.\n const columnVisibility = useMemo(() => {\n // We can't have no columns visible - if the array is empty we show them all.\n if (!hiddenColumns || hiddenColumns.length === columns.length) {\n return undefined;\n }\n\n return columns.reduce(\n (acc, column) => ({\n ...acc,\n [column.id]: !hiddenColumns.includes(column.id),\n }),\n {},\n );\n }, [hiddenColumns, columns]);\n\n // Pinned columns\n const columnPinning = useMemo(() => {\n return {\n left: pinnedColumns?.left ?? [],\n right: pinnedColumns?.right ?? [],\n };\n }, [pinnedColumns]);\n\n /**\n * Setup the TanStack table, including mapped column definitions, row data, and any additional state such as\n * column visibility and ordering.\n */\n const table = useReactTable<any>({\n data,\n columns: mappedColumnDefinitions,\n\n // Column settings\n columnResizeMode: resizeMode === 'off' ? undefined : resizeMode,\n enableColumnResizing,\n\n // Row model\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n\n // Sorting\n enableSorting,\n enableSortingRemoval,\n enableMultiRemove,\n manualSorting,\n onSortingChange,\n\n // Pinning\n enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n },\n });\n\n /**\n * Pinned column layout\n */\n const { pinnedColumnLayoutStyles } = usePinnedColumnLayout({ table });\n\n /**\n * Other hooks\n */\n useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });\n\n return (\n <GridContainer\n containerRef={containerRef}\n borderMode={borderMode}\n containerStyles={{ ...containerStyle, ...pinnedColumnLayoutStyles }}\n ariaRoles={ariaRoles}\n enableResizeableColumns={enableColumnResizing}\n density={density}\n table={table}\n aria-label={ariaLabel}\n >\n {/* Columns */}\n {enableColumnResizing && <Columns table={table} />}\n\n {/* Header */}\n <Header table={table} />\n\n {/* Body */}\n {table.getState().columnSizingInfo.isResizingColumn ? (\n <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />\n ) : (\n <Body table={table} ariaRoles={ariaRoles} striped={striped} />\n )}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;AAiBG;MACU,QAAQ,GAAG,CAAC,EACvB,OAAO,GAAG,MAAM,EAChB,OAAO,GAAG,IAAI,EACd,UAAU,GAAG,MAAM,EACnB,UAAU,GAAG,KAAK,EAClB,cAAc,EAEd,OAAO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Grid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { ColumnMapper, getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { MemoizedBody } from './components/Body';\n\nimport { usePinnedColumnLayout, useSortingState, useKeyboardNavigation } from './hooks';\n\nimport { useSelectionState } from './hooks/useSelectionState';\nimport { SELECTION_COLUMN_ID } from './constants';\nimport { SelectionColumnDefinition } from './columns';\n\n/**\n * [WIP]\n *\n * A DataGrid component which renders data in a two-dimensional format, with columns and rows. Unlike the `DataTable`\n * component, the `DataGrid` supports both flat and hierarchical (tree) data.\n *\n * Under the hood, it uses [TanStack Table](http://tanstack.com/table/) for table management, and aims to replicate functionality\n * available in major third party grid components such as CloudScape's Table component, AgGrid, etc.\n *\n * Supported features include:\n * - Pinning, resizing (incl. smooth resizing), reordering, and hiding of columns\n * - Selection (single and multiple) and disabling of rows.\n * - Rendering of arbitrarily nested data, expanding/collapsing, and custom full-width 'group' rows.\n * - In-built keyboard navigation with arrow keys, and drag to scroll.\n * - Configurable density.\n *\n * *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*\n */\nexport const DataGrid = ({\n density = 'base',\n striped = true,\n borderMode = 'full',\n resizeMode = 'off',\n containerStyle,\n enableKeyboardNavigation = false,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n\n sortState,\n onSortChanged,\n\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(() => columns.some((column) => column.renderFooter), [columns]);\n const ariaRoles = useMemo(\n () => getAriaRoles(enableKeyboardNavigation),\n [enableKeyboardNavigation],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection and sorting.\n */\n\n const { enableRowSelection, enableMultiRowSelection, rowSelection, onRowSelectionChange } =\n useSelectionState({\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n });\n\n const {\n enableSorting,\n enableMultiRemove,\n enableSortingRemoval,\n manualSorting,\n sorting,\n onSortingChange,\n } = useSortingState({ columns, sortState, onSortChanged });\n\n /**\n * Mapping of column definitions.\n */\n const columnMapper = useRef(new ColumnMapper());\n const mappedColumnDefinitions = useMemo(() => {\n const mappedColumns = columns.map((column) => columnMapper.current.mapColumnDefinition(column));\n\n if (enableRowSelection) {\n mappedColumns.unshift(SelectionColumnDefinition);\n }\n\n return mappedColumns;\n }, [columns, enableRowSelection]);\n\n /**\n * Stable references for column states (visibility, order, pinning).\n */\n\n // Column render order - the order of the array indicates the order on screen.\n const columnOrder = useMemo(() => {\n if (!columnOrdering || columnOrdering.length === 0) {\n return undefined;\n }\n\n // If we have a custom column order, we need to make sure the selection column always appears first.\n if (enableRowSelection) {\n return ['selection', ...columnOrdering];\n }\n\n return columnOrdering;\n }, [columnOrdering, enableRowSelection]);\n\n // Column visibiilty - record of column ID's to visibility, where false/no value = hidden.\n const columnVisibility = useMemo(() => {\n // We can't have no columns visible - if the array is empty we show them all.\n if (!hiddenColumns || hiddenColumns.length === columns.length) {\n return undefined;\n }\n\n return columns.reduce(\n (acc, column) => ({\n ...acc,\n [column.id]: !hiddenColumns.includes(column.id),\n }),\n {},\n );\n }, [hiddenColumns, columns]);\n\n // Pinned columns\n const columnPinning = useMemo(() => {\n let left = pinnedColumns?.left ?? [];\n\n // If we have any left-pinned columns, we need to include the selection column as it should appear first.\n if (enableRowSelection && left.length > 0) {\n left = [SELECTION_COLUMN_ID, ...left];\n }\n\n return {\n left,\n right: pinnedColumns?.right ?? [],\n };\n }, [pinnedColumns, enableRowSelection]);\n\n /**\n * Setup the TanStack table, including mapped column definitions, row data, and any additional state such as\n * column visibility and ordering.\n */\n const table = useReactTable<any>({\n data,\n columns: mappedColumnDefinitions,\n\n // Column settings\n columnResizeMode: resizeMode === 'off' ? undefined : resizeMode,\n enableColumnResizing,\n\n // Row model\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n\n // Sorting\n enableSorting,\n enableSortingRemoval,\n enableMultiRemove,\n manualSorting,\n onSortingChange,\n\n // Pinning\n enableColumnPinning: columnPinning.left.length + columnPinning.right.length > 0,\n\n // Selection\n enableRowSelection,\n enableMultiRowSelection,\n onRowSelectionChange,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n },\n });\n\n /**\n * Pinned column layout\n */\n const { pinnedColumnLayoutStyles } = usePinnedColumnLayout({ table });\n\n /**\n * Other hooks\n */\n useDragToScroll({ targetRef: containerRef, ignoreClassName: 'data-grid-column-resizer' });\n useKeyboardNavigation({ tableRef, enableKeyboardNavigation });\n\n return (\n <GridContainer\n containerRef={containerRef}\n tableRef={tableRef}\n borderMode={borderMode}\n containerStyles={{ ...containerStyle, ...pinnedColumnLayoutStyles }}\n ariaRoles={ariaRoles}\n enableResizeableColumns={enableColumnResizing}\n density={density}\n table={table}\n aria-label={ariaLabel}\n >\n {/* Columns */}\n {enableColumnResizing && <Columns table={table} />}\n\n {/* Header */}\n <Header table={table} />\n\n {/* Body */}\n {table.getState().columnSizingInfo.isResizingColumn ? (\n <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />\n ) : (\n <Body table={table} ariaRoles={ariaRoles} striped={striped} />\n )}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;;;;;;;;AAiBG;AACU,MAAA,QAAQ,GAAG,CAAC,EACvB,OAAO,GAAG,MAAM,EAChB,OAAO,GAAG,IAAI,EACd,UAAU,GAAG,MAAM,EACnB,UA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B,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,wBAAwB,EAAE,EACnE,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,oBAAoB,EAC7C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,gBACA,SAAS,EAAA;AAGpB,QAAA,oBAAoB,IAAIA,cAAC,CAAA,aAAA,CAAA,OAAO,IAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGlD,QAAAA,cAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAI,CAAA;QAGvB,KAAK,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,IACjDA,cAAC,CAAA,aAAA,CAAA,YAAY,IAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,KAEtEA,cAAA,CAAA,aAAA,CAAC,IAAI,EAAC,EAAA,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAA,CAAI,CAC/D;AAGA,QAAA,UAAU,IAAIA,cAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAI,CAAA,CAC/C;AAEpB;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var Checkbox = require('../../Checkbox/Checkbox.cjs');
|
|
5
|
+
var Radio = require('../../Radio/Radio.cjs');
|
|
6
|
+
var constants = require('../constants.cjs');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
11
|
+
|
|
12
|
+
const headerRenderer = ({ table }) => table.options.enableMultiRowSelection && (React__default.default.createElement(Checkbox.Checkbox, { ariaLabel: "Select all rows", indeterminate: table.getIsSomeRowsSelected(), checked: table.getIsAllRowsSelected(), onChange: () => table.toggleAllRowsSelected() }));
|
|
13
|
+
const cellRenderer = ({ row }) => {
|
|
14
|
+
if (row.getCanMultiSelect()) {
|
|
15
|
+
return (React__default.default.createElement(Checkbox.Checkbox, { ariaLabel: "Select row", checked: row.getIsSelected(), onChange: row.getToggleSelectedHandler(), disabled: !row.getCanSelect() }));
|
|
16
|
+
}
|
|
17
|
+
return (React__default.default.createElement(Radio.Radio, { "aria-label": "Select row", checked: row.getIsSelected(), onChange: row.getToggleSelectedHandler(), disabled: !row.getCanSelect() }));
|
|
18
|
+
};
|
|
19
|
+
const SelectionColumnDefinition = {
|
|
20
|
+
id: constants.SELECTION_COLUMN_ID,
|
|
21
|
+
header: headerRenderer,
|
|
22
|
+
cell: cellRenderer,
|
|
23
|
+
size: 50,
|
|
24
|
+
minSize: 50,
|
|
25
|
+
maxSize: 50,
|
|
26
|
+
enableResizing: false,
|
|
27
|
+
enableSorting: false,
|
|
28
|
+
meta: {
|
|
29
|
+
rowHeader: false,
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
textAlign: 'center',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.SelectionColumnDefinition = SelectionColumnDefinition;
|
|
36
|
+
//# sourceMappingURL=SelectionColumnDefinition.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionColumnDefinition.cjs","sources":["../../../../src/components/DataGrid/columns/SelectionColumnDefinition.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DisplayColumnDef, Row, Table } from '@tanstack/react-table';\n\nimport { Checkbox } from '../../Checkbox';\nimport { Radio } from '../../Radio';\n\nimport { SELECTION_COLUMN_ID } from '../constants';\n\nconst headerRenderer = ({ table }: { table: Table<any> }) =>\n table.options.enableMultiRowSelection && (\n <Checkbox\n ariaLabel=\"Select all rows\"\n indeterminate={table.getIsSomeRowsSelected()}\n checked={table.getIsAllRowsSelected()}\n onChange={() => table.toggleAllRowsSelected()}\n />\n );\n\nconst cellRenderer = ({ row }: { row: Row<any> }) => {\n if (row.getCanMultiSelect()) {\n return (\n <Checkbox\n ariaLabel=\"Select row\"\n checked={row.getIsSelected()}\n onChange={row.getToggleSelectedHandler()}\n disabled={!row.getCanSelect()}\n />\n );\n }\n\n return (\n <Radio\n aria-label=\"Select row\"\n checked={row.getIsSelected()}\n onChange={row.getToggleSelectedHandler()}\n disabled={!row.getCanSelect()}\n />\n );\n};\n\nexport const SelectionColumnDefinition: DisplayColumnDef<any> = {\n id: SELECTION_COLUMN_ID,\n header: headerRenderer,\n cell: cellRenderer,\n size: 50,\n minSize: 50,\n maxSize: 50,\n enableResizing: false,\n enableSorting: false,\n meta: {\n rowHeader: false,\n justifyContent: 'center',\n textAlign: 'center',\n },\n};\n"],"names":["React","Checkbox","Radio","SELECTION_COLUMN_ID"],"mappings":";;;;;;;;;;;AASA,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAyB,KACtD,KAAK,CAAC,OAAO,CAAC,uBAAuB,KACnCA,sBAAA,CAAA,aAAA,CAACC,iBAAQ,EACP,EAAA,SAAS,EAAC,iBAAiB,EAC3B,aAAa,EAAE,KAAK,CAAC,qBAAqB,EAAE,EAC5C,OAAO,EAAE,KAAK,CAAC,oBAAoB,EAAE,EACrC,QAAQ,EAAE,MAAM,KAAK,CAAC,qBAAqB,EAAE,EAC7C,CAAA,CACH;AAEH,MAAM,YAAY,GAAG,CAAC,EAAE,GAAG,EAAqB,KAAI;AAClD,IAAA,IAAI,GAAG,CAAC,iBAAiB,EAAE,EAAE;AAC3B,QAAA,QACED,sBAAA,CAAA,aAAA,CAACC,iBAAQ,EAAA,EACP,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE,EAC5B,QAAQ,EAAE,GAAG,CAAC,wBAAwB,EAAE,EACxC,QAAQ,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,EAAA,CAC7B;AAEL;AAED,IAAA,QACED,sBAAA,CAAA,aAAA,CAACE,WAAK,EAAA,EAAA,YAAA,EACO,YAAY,EACvB,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE,EAC5B,QAAQ,EAAE,GAAG,CAAC,wBAAwB,EAAE,EACxC,QAAQ,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,EAAA,CAC7B;AAEN,CAAC;AAEY,MAAA,yBAAyB,GAA0B;AAC9D,IAAA,EAAE,EAAEC,6BAAmB;AACvB,IAAA,MAAM,EAAE,cAAc;AACtB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,cAAc,EAAE,KAAK;AACrB,IAAA,aAAa,EAAE,KAAK;AACpB,IAAA,IAAI,EAAE;AACJ,QAAA,SAAS,EAAE,KAAK;AAChB,QAAA,cAAc,EAAE,QAAQ;AACxB,QAAA,SAAS,EAAE,QAAQ;AACpB,KAAA;;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { Checkbox } from '../../Checkbox/Checkbox.js';
|
|
3
|
+
import { Radio } from '../../Radio/Radio.js';
|
|
4
|
+
import { SELECTION_COLUMN_ID } from '../constants.js';
|
|
5
|
+
|
|
6
|
+
const headerRenderer = ({ table }) => table.options.enableMultiRowSelection && (React__default.createElement(Checkbox, { ariaLabel: "Select all rows", indeterminate: table.getIsSomeRowsSelected(), checked: table.getIsAllRowsSelected(), onChange: () => table.toggleAllRowsSelected() }));
|
|
7
|
+
const cellRenderer = ({ row }) => {
|
|
8
|
+
if (row.getCanMultiSelect()) {
|
|
9
|
+
return (React__default.createElement(Checkbox, { ariaLabel: "Select row", checked: row.getIsSelected(), onChange: row.getToggleSelectedHandler(), disabled: !row.getCanSelect() }));
|
|
10
|
+
}
|
|
11
|
+
return (React__default.createElement(Radio, { "aria-label": "Select row", checked: row.getIsSelected(), onChange: row.getToggleSelectedHandler(), disabled: !row.getCanSelect() }));
|
|
12
|
+
};
|
|
13
|
+
const SelectionColumnDefinition = {
|
|
14
|
+
id: SELECTION_COLUMN_ID,
|
|
15
|
+
header: headerRenderer,
|
|
16
|
+
cell: cellRenderer,
|
|
17
|
+
size: 50,
|
|
18
|
+
minSize: 50,
|
|
19
|
+
maxSize: 50,
|
|
20
|
+
enableResizing: false,
|
|
21
|
+
enableSorting: false,
|
|
22
|
+
meta: {
|
|
23
|
+
rowHeader: false,
|
|
24
|
+
justifyContent: 'center',
|
|
25
|
+
textAlign: 'center',
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SelectionColumnDefinition };
|
|
30
|
+
//# sourceMappingURL=SelectionColumnDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionColumnDefinition.js","sources":["../../../../src/components/DataGrid/columns/SelectionColumnDefinition.tsx"],"sourcesContent":["import React from 'react';\n\nimport { DisplayColumnDef, Row, Table } from '@tanstack/react-table';\n\nimport { Checkbox } from '../../Checkbox';\nimport { Radio } from '../../Radio';\n\nimport { SELECTION_COLUMN_ID } from '../constants';\n\nconst headerRenderer = ({ table }: { table: Table<any> }) =>\n table.options.enableMultiRowSelection && (\n <Checkbox\n ariaLabel=\"Select all rows\"\n indeterminate={table.getIsSomeRowsSelected()}\n checked={table.getIsAllRowsSelected()}\n onChange={() => table.toggleAllRowsSelected()}\n />\n );\n\nconst cellRenderer = ({ row }: { row: Row<any> }) => {\n if (row.getCanMultiSelect()) {\n return (\n <Checkbox\n ariaLabel=\"Select row\"\n checked={row.getIsSelected()}\n onChange={row.getToggleSelectedHandler()}\n disabled={!row.getCanSelect()}\n />\n );\n }\n\n return (\n <Radio\n aria-label=\"Select row\"\n checked={row.getIsSelected()}\n onChange={row.getToggleSelectedHandler()}\n disabled={!row.getCanSelect()}\n />\n );\n};\n\nexport const SelectionColumnDefinition: DisplayColumnDef<any> = {\n id: SELECTION_COLUMN_ID,\n header: headerRenderer,\n cell: cellRenderer,\n size: 50,\n minSize: 50,\n maxSize: 50,\n enableResizing: false,\n enableSorting: false,\n meta: {\n rowHeader: false,\n justifyContent: 'center',\n textAlign: 'center',\n },\n};\n"],"names":["React"],"mappings":";;;;;AASA,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAyB,KACtD,KAAK,CAAC,OAAO,CAAC,uBAAuB,KACnCA,cAAA,CAAA,aAAA,CAAC,QAAQ,EACP,EAAA,SAAS,EAAC,iBAAiB,EAC3B,aAAa,EAAE,KAAK,CAAC,qBAAqB,EAAE,EAC5C,OAAO,EAAE,KAAK,CAAC,oBAAoB,EAAE,EACrC,QAAQ,EAAE,MAAM,KAAK,CAAC,qBAAqB,EAAE,EAC7C,CAAA,CACH;AAEH,MAAM,YAAY,GAAG,CAAC,EAAE,GAAG,EAAqB,KAAI;AAClD,IAAA,IAAI,GAAG,CAAC,iBAAiB,EAAE,EAAE;AAC3B,QAAA,QACEA,cAAA,CAAA,aAAA,CAAC,QAAQ,EAAA,EACP,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE,EAC5B,QAAQ,EAAE,GAAG,CAAC,wBAAwB,EAAE,EACxC,QAAQ,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,EAAA,CAC7B;AAEL;AAED,IAAA,QACEA,cAAA,CAAA,aAAA,CAAC,KAAK,EAAA,EAAA,YAAA,EACO,YAAY,EACvB,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE,EAC5B,QAAQ,EAAE,GAAG,CAAC,wBAAwB,EAAE,EACxC,QAAQ,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,EAAA,CAC7B;AAEN,CAAC;AAEY,MAAA,yBAAyB,GAA0B;AAC9D,IAAA,EAAE,EAAE,mBAAmB;AACvB,IAAA,MAAM,EAAE,cAAc;AACtB,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,cAAc,EAAE,KAAK;AACrB,IAAA,aAAa,EAAE,KAAK;AACpB,IAAA,IAAI,EAAE;AACJ,QAAA,SAAS,EAAE,KAAK;AAChB,QAAA,cAAc,EAAE,QAAQ;AACxB,QAAA,SAAS,EAAE,QAAQ;AACpB,KAAA;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SelectionColumnDefinition } from './SelectionColumnDefinition';
|
|
@@ -4,9 +4,11 @@ const DEFAULT_COLUMN_WIDTH = 200;
|
|
|
4
4
|
const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;
|
|
5
5
|
const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;
|
|
6
6
|
const DEFAULT_CELL_ALIGN = 'left';
|
|
7
|
+
const SELECTION_COLUMN_ID = 'selection';
|
|
7
8
|
|
|
8
9
|
exports.DEFAULT_CELL_ALIGN = DEFAULT_CELL_ALIGN;
|
|
9
10
|
exports.DEFAULT_COLUMN_MAXIMUM_WIDTH = DEFAULT_COLUMN_MAXIMUM_WIDTH;
|
|
10
11
|
exports.DEFAULT_COLUMN_MINIMUM_WIDTH = DEFAULT_COLUMN_MINIMUM_WIDTH;
|
|
11
12
|
exports.DEFAULT_COLUMN_WIDTH = DEFAULT_COLUMN_WIDTH;
|
|
13
|
+
exports.SELECTION_COLUMN_ID = SELECTION_COLUMN_ID;
|
|
12
14
|
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["../../../src/components/DataGrid/constants.ts"],"sourcesContent":["export const DEFAULT_COLUMN_WIDTH = 200;\nexport const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;\nexport const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;\n\nexport const DEFAULT_CELL_ALIGN = 'left';\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAoB,GAAG;AAC7B,MAAM,4BAA4B,GAAG;AAC/B,MAAA,4BAA4B,GAAG,MAAM,CAAC;AAE5C,MAAM,kBAAkB,GAAG
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../../src/components/DataGrid/constants.ts"],"sourcesContent":["export const DEFAULT_COLUMN_WIDTH = 200;\nexport const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;\nexport const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;\n\nexport const DEFAULT_CELL_ALIGN = 'left';\n\nexport const SELECTION_COLUMN_ID = 'selection';\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAoB,GAAG;AAC7B,MAAM,4BAA4B,GAAG;AAC/B,MAAA,4BAA4B,GAAG,MAAM,CAAC;AAE5C,MAAM,kBAAkB,GAAG;AAE3B,MAAM,mBAAmB,GAAG;;;;;;;;"}
|
|
@@ -2,3 +2,4 @@ export declare const DEFAULT_COLUMN_WIDTH = 200;
|
|
|
2
2
|
export declare const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;
|
|
3
3
|
export declare const DEFAULT_COLUMN_MAXIMUM_WIDTH: number;
|
|
4
4
|
export declare const DEFAULT_CELL_ALIGN = "left";
|
|
5
|
+
export declare const SELECTION_COLUMN_ID = "selection";
|
|
@@ -2,6 +2,7 @@ const DEFAULT_COLUMN_WIDTH = 200;
|
|
|
2
2
|
const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;
|
|
3
3
|
const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;
|
|
4
4
|
const DEFAULT_CELL_ALIGN = 'left';
|
|
5
|
+
const SELECTION_COLUMN_ID = 'selection';
|
|
5
6
|
|
|
6
|
-
export { DEFAULT_CELL_ALIGN, DEFAULT_COLUMN_MAXIMUM_WIDTH, DEFAULT_COLUMN_MINIMUM_WIDTH, DEFAULT_COLUMN_WIDTH };
|
|
7
|
+
export { DEFAULT_CELL_ALIGN, DEFAULT_COLUMN_MAXIMUM_WIDTH, DEFAULT_COLUMN_MINIMUM_WIDTH, DEFAULT_COLUMN_WIDTH, SELECTION_COLUMN_ID };
|
|
7
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../src/components/DataGrid/constants.ts"],"sourcesContent":["export const DEFAULT_COLUMN_WIDTH = 200;\nexport const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;\nexport const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;\n\nexport const DEFAULT_CELL_ALIGN = 'left';\n"],"names":[],"mappings":"AAAO,MAAM,oBAAoB,GAAG;AAC7B,MAAM,4BAA4B,GAAG;AAC/B,MAAA,4BAA4B,GAAG,MAAM,CAAC;AAE5C,MAAM,kBAAkB,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/components/DataGrid/constants.ts"],"sourcesContent":["export const DEFAULT_COLUMN_WIDTH = 200;\nexport const DEFAULT_COLUMN_MINIMUM_WIDTH = 120;\nexport const DEFAULT_COLUMN_MAXIMUM_WIDTH = Number.MAX_SAFE_INTEGER;\n\nexport const DEFAULT_CELL_ALIGN = 'left';\n\nexport const SELECTION_COLUMN_ID = 'selection';\n"],"names":[],"mappings":"AAAO,MAAM,oBAAoB,GAAG;AAC7B,MAAM,4BAA4B,GAAG;AAC/B,MAAA,4BAA4B,GAAG,MAAM,CAAC;AAE5C,MAAM,kBAAkB,GAAG;AAE3B,MAAM,mBAAmB,GAAG;;;;"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var tabbableSelectors = require('../../../utils/tabbableSelectors.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Finds a target element to be selected within a table cell element. If the table cell
|
|
8
|
+
* contains focusable children, the first child will be returned, otherwise we'll simply
|
|
9
|
+
* focus on the table cell.
|
|
10
|
+
*/
|
|
11
|
+
const findTargetElement = (tableCell) => {
|
|
12
|
+
const validChildTarget = tableCell.querySelector(tabbableSelectors.TABBABLE_SELECTORS);
|
|
13
|
+
return validChildTarget !== null && validChildTarget !== undefined ? validChildTarget : tableCell;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Finds the next available cell that can be focused by the user, within the next row.
|
|
17
|
+
*/
|
|
18
|
+
const findNextCell = (nextRow, nextCellIndex) => {
|
|
19
|
+
if (nextCellIndex >= nextRow.cells.length ||
|
|
20
|
+
nextRow.cells[nextCellIndex].hasAttribute('aria-hidden')) {
|
|
21
|
+
// Ignore (skip) cells that are marked as hidden. Find the next available cell (if there is one) that is visible.
|
|
22
|
+
return [...nextRow.cells].reverse().find((cell) => !cell.hasAttribute('aria-hidden'));
|
|
23
|
+
}
|
|
24
|
+
return nextRow.cells[nextCellIndex];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Handles a `keydown` event from within the table. Navigates between cells using the arrow keys.
|
|
28
|
+
* @param table The table element.
|
|
29
|
+
* @param event The keyboard event.
|
|
30
|
+
*/
|
|
31
|
+
const handleKeyDown = (table, event) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const target = event.target;
|
|
34
|
+
if (!table)
|
|
35
|
+
return;
|
|
36
|
+
const currentCell = target.closest('td, th');
|
|
37
|
+
if (!currentCell)
|
|
38
|
+
return;
|
|
39
|
+
const currentRow = currentCell.parentElement;
|
|
40
|
+
if (!currentRow)
|
|
41
|
+
return;
|
|
42
|
+
const rowIndex = Array.from(table.querySelectorAll('tr')).indexOf(currentRow);
|
|
43
|
+
const cellIndex = Array.from(currentRow.children).indexOf(currentCell);
|
|
44
|
+
let nextRowIndex = rowIndex;
|
|
45
|
+
let nextCellIndex = cellIndex;
|
|
46
|
+
switch (event.key) {
|
|
47
|
+
case 'ArrowUp':
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
nextRowIndex = Math.max(0, rowIndex - 1);
|
|
50
|
+
break;
|
|
51
|
+
case 'ArrowDown':
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
nextRowIndex = Math.min(table.rows.length - 1, rowIndex + 1);
|
|
54
|
+
break;
|
|
55
|
+
case 'ArrowLeft':
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
nextCellIndex = Math.max(0, cellIndex - 1);
|
|
58
|
+
break;
|
|
59
|
+
case 'ArrowRight':
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
nextCellIndex = Math.min(currentRow.cells.length - 1, cellIndex + 1);
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const nextRow = table.rows[nextRowIndex];
|
|
67
|
+
const nextCell = findNextCell(nextRow, nextCellIndex);
|
|
68
|
+
if (nextCell) {
|
|
69
|
+
const nextTarget = findTargetElement(nextCell);
|
|
70
|
+
nextTarget.setAttribute('tabindex', '0');
|
|
71
|
+
(_a = nextTarget.scrollIntoView) === null || _a === undefined ? undefined : _a.call(nextTarget, { inline: 'nearest', block: 'nearest' });
|
|
72
|
+
nextTarget.focus();
|
|
73
|
+
// Clear the tabindex when the element loses focus
|
|
74
|
+
nextTarget.addEventListener('blur', () => {
|
|
75
|
+
if (nextTarget.attributes.getNamedItem('data-first')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
nextTarget.removeAttribute('tabindex');
|
|
79
|
+
}, { once: true });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Hook which sets up keyboard navigation within the `DataGrid` component using the arrow keys, can be disabled
|
|
84
|
+
* with the `enableKeyboardNavigation` prop.
|
|
85
|
+
*
|
|
86
|
+
* Supports navigating between cells and rows, with the focus directed either towards the cell element, or
|
|
87
|
+
* the first interactive child if one is present.
|
|
88
|
+
*/
|
|
89
|
+
const useKeyboardNavigation = ({ enableKeyboardNavigation, tableRef, }) => {
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
if (!tableRef.current || !enableKeyboardNavigation) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const table = tableRef.current;
|
|
95
|
+
// Find the first column header in the table, and assign it a tabindex.
|
|
96
|
+
const firstElement = table.querySelector('th');
|
|
97
|
+
if (!firstElement)
|
|
98
|
+
return undefined;
|
|
99
|
+
const firstTarget = findTargetElement(firstElement);
|
|
100
|
+
firstTarget.setAttribute('tabindex', '0');
|
|
101
|
+
firstTarget.setAttribute('data-first', '');
|
|
102
|
+
const handler = (event) => handleKeyDown(table, event);
|
|
103
|
+
table.addEventListener('keydown', handler);
|
|
104
|
+
return () => {
|
|
105
|
+
table.removeEventListener('keydown', handler);
|
|
106
|
+
};
|
|
107
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
+
}, [tableRef, enableKeyboardNavigation]);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.useKeyboardNavigation = useKeyboardNavigation;
|
|
112
|
+
//# sourceMappingURL=useKeyboardNavigation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardNavigation.cjs","sources":["../../../../src/components/DataGrid/hooks/useKeyboardNavigation.ts"],"sourcesContent":["import { RefObject, useEffect } from 'react';\n\nimport { TABBABLE_SELECTORS } from '../../../utils/tabbableSelectors';\nimport { DataGridProps } from '../types';\n\ntype UseKeyboardNavigationProps = Pick<DataGridProps, 'enableKeyboardNavigation'> & {\n tableRef: RefObject<HTMLTableElement>;\n};\n\n/**\n * Finds a target element to be selected within a table cell element. If the table cell\n * contains focusable children, the first child will be returned, otherwise we'll simply\n * focus on the table cell.\n */\nconst findTargetElement = (tableCell: HTMLElement): HTMLElement => {\n const validChildTarget: HTMLElement | null = tableCell.querySelector(TABBABLE_SELECTORS);\n return validChildTarget ?? tableCell;\n};\n\n/**\n * Finds the next available cell that can be focused by the user, within the next row.\n */\nconst findNextCell = (nextRow: HTMLTableRowElement, nextCellIndex: number) => {\n if (\n nextCellIndex >= nextRow.cells.length ||\n nextRow.cells[nextCellIndex].hasAttribute('aria-hidden')\n ) {\n // Ignore (skip) cells that are marked as hidden. Find the next available cell (if there is one) that is visible.\n return [...nextRow.cells].reverse().find((cell) => !cell.hasAttribute('aria-hidden'));\n }\n\n return nextRow.cells[nextCellIndex];\n};\n\n/**\n * Handles a `keydown` event from within the table. Navigates between cells using the arrow keys.\n * @param table The table element.\n * @param event The keyboard event.\n */\nconst handleKeyDown = (table: HTMLTableElement, event: KeyboardEvent) => {\n const target = event.target as HTMLElement;\n\n if (!table) return;\n\n const currentCell = target.closest('td, th') as HTMLElement;\n if (!currentCell) return;\n\n const currentRow = currentCell.parentElement as HTMLTableRowElement;\n if (!currentRow) return;\n\n const rowIndex = Array.from(table.querySelectorAll('tr')).indexOf(currentRow);\n const cellIndex = Array.from(currentRow.children).indexOf(currentCell);\n\n let nextRowIndex = rowIndex;\n let nextCellIndex = cellIndex;\n\n switch (event.key) {\n case 'ArrowUp':\n event.preventDefault();\n nextRowIndex = Math.max(0, rowIndex - 1);\n break;\n case 'ArrowDown':\n event.preventDefault();\n nextRowIndex = Math.min(table.rows.length - 1, rowIndex + 1);\n break;\n case 'ArrowLeft':\n event.preventDefault();\n nextCellIndex = Math.max(0, cellIndex - 1);\n break;\n case 'ArrowRight':\n event.preventDefault();\n nextCellIndex = Math.min(currentRow.cells.length - 1, cellIndex + 1);\n break;\n default:\n return;\n }\n\n const nextRow = table.rows[nextRowIndex];\n const nextCell = findNextCell(nextRow, nextCellIndex);\n\n if (nextCell) {\n const nextTarget = findTargetElement(nextCell);\n nextTarget.setAttribute('tabindex', '0');\n nextTarget.scrollIntoView?.({ inline: 'nearest', block: 'nearest' });\n nextTarget.focus();\n\n // Clear the tabindex when the element loses focus\n nextTarget.addEventListener(\n 'blur',\n () => {\n if (nextTarget.attributes.getNamedItem('data-first')) {\n return;\n }\n\n nextTarget.removeAttribute('tabindex');\n },\n { once: true },\n );\n }\n};\n\n/**\n * Hook which sets up keyboard navigation within the `DataGrid` component using the arrow keys, can be disabled\n * with the `enableKeyboardNavigation` prop.\n *\n * Supports navigating between cells and rows, with the focus directed either towards the cell element, or\n * the first interactive child if one is present.\n */\nexport const useKeyboardNavigation = ({\n enableKeyboardNavigation,\n tableRef,\n}: UseKeyboardNavigationProps) => {\n useEffect(() => {\n if (!tableRef.current || !enableKeyboardNavigation) {\n return undefined;\n }\n\n const table = tableRef.current;\n\n // Find the first column header in the table, and assign it a tabindex.\n const firstElement = table.querySelector('th') as HTMLElement;\n if (!firstElement) return undefined;\n const firstTarget = findTargetElement(firstElement);\n\n firstTarget.setAttribute('tabindex', '0');\n firstTarget.setAttribute('data-first', '');\n\n const handler = (event: KeyboardEvent) => handleKeyDown(table, event);\n table.addEventListener('keydown', handler);\n\n return () => {\n table.removeEventListener('keydown', handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tableRef, enableKeyboardNavigation]);\n};\n"],"names":["TABBABLE_SELECTORS","useEffect"],"mappings":";;;;;AASA;;;;AAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,SAAsB,KAAiB;IAChE,MAAM,gBAAgB,GAAuB,SAAS,CAAC,aAAa,CAACA,oCAAkB,CAAC;AACxF,IAAA,OAAO,gBAAgB,KAAhB,IAAA,IAAA,gBAAgB,iBAAhB,gBAAgB,GAAI,SAAS;AACtC,CAAC;AAED;;AAEG;AACH,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,aAAqB,KAAI;AAC3E,IAAA,IACE,aAAa,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM;QACrC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,EACxD;;QAEA,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC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B;AAED,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO;;QAG9B,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAgB;AAC7D,QAAA,IAAI,CAAC,YAAY;AAAE,YAAA,OAAO,SAAS;AACnC,QAAA,MAAM,WAAW,GAAG,iBAAiB,CAAC,YAAY,CAAC;AAEnD,QAAA,WAAW,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC;AACzC,QAAA,WAAW,CAAC,YAAY,CAAC,YAAY,EAAE,EAAE,CAAC;AAE1C,QAAA,MAAM,OAAO,GAAG,CAAC,KAAoB,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC;AACrE,QAAA,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC;AAE1C,QAAA,OAAO,MAAK;AACV,YAAA,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC;AAC/C,SAAC;;AAEH,KAAC,EAAE,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;AAC1C;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { DataGridProps } from '../types';
|
|
3
|
+
type UseKeyboardNavigationProps = Pick<DataGridProps, 'enableKeyboardNavigation'> & {
|
|
4
|
+
tableRef: RefObject<HTMLTableElement>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook which sets up keyboard navigation within the `DataGrid` component using the arrow keys, can be disabled
|
|
8
|
+
* with the `enableKeyboardNavigation` prop.
|
|
9
|
+
*
|
|
10
|
+
* Supports navigating between cells and rows, with the focus directed either towards the cell element, or
|
|
11
|
+
* the first interactive child if one is present.
|
|
12
|
+
*/
|
|
13
|
+
export declare const useKeyboardNavigation: ({ enableKeyboardNavigation, tableRef, }: UseKeyboardNavigationProps) => void;
|
|
14
|
+
export {};
|