@veeqo/ui 11.3.2 → 11.4.0
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 +9 -3
- package/dist/components/DataGrid/DataGrid.cjs.map +1 -1
- package/dist/components/DataGrid/DataGrid.d.ts +1 -1
- package/dist/components/DataGrid/DataGrid.js +9 -3
- package/dist/components/DataGrid/DataGrid.js.map +1 -1
- package/dist/components/DataGrid/components/Body/Body.cjs +6 -2
- package/dist/components/DataGrid/components/Body/Body.cjs.map +1 -1
- package/dist/components/DataGrid/components/Body/Body.d.ts +7 -3
- package/dist/components/DataGrid/components/Body/Body.js +6 -2
- package/dist/components/DataGrid/components/Body/Body.js.map +1 -1
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.cjs +5 -3
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.cjs.map +1 -1
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.js +6 -4
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.js.map +1 -1
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss.cjs +2 -2
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss.cjs.map +1 -1
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss.js +2 -2
- package/dist/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss.js.map +1 -1
- package/dist/components/DataGrid/components/Body/Row/Row.cjs +12 -1
- package/dist/components/DataGrid/components/Body/Row/Row.cjs.map +1 -1
- package/dist/components/DataGrid/components/Body/Row/Row.d.ts +11 -3
- package/dist/components/DataGrid/components/Body/Row/Row.js +12 -1
- package/dist/components/DataGrid/components/Body/Row/Row.js.map +1 -1
- package/dist/components/DataGrid/components/Body/Row/Row.module.scss.cjs +9 -0
- package/dist/components/DataGrid/components/Body/Row/Row.module.scss.cjs.map +1 -0
- package/dist/components/DataGrid/components/Body/Row/Row.module.scss.js +7 -0
- package/dist/components/DataGrid/components/Body/Row/Row.module.scss.js.map +1 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/index.d.ts +1 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/useRowTheme.cjs +26 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/useRowTheme.cjs.map +1 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/useRowTheme.d.ts +16 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/useRowTheme.js +24 -0
- package/dist/components/DataGrid/components/Body/Row/hooks/useRowTheme.js.map +1 -0
- package/dist/components/DataGrid/types/ColumnDefinition.d.ts +9 -3
- package/dist/components/DataGrid/types/DataGridProps.d.ts +6 -6
- package/dist/components/DataGrid/types/RowTheme.d.ts +13 -0
- package/dist/components/DataGrid/types/declarations.d.ts +1 -0
- package/dist/components/DataGrid/types/index.d.ts +1 -0
- package/dist/components/DataGrid/utils/ColumnMapper.cjs +1 -0
- package/dist/components/DataGrid/utils/ColumnMapper.cjs.map +1 -1
- package/dist/components/DataGrid/utils/ColumnMapper.js +1 -0
- package/dist/components/DataGrid/utils/ColumnMapper.js.map +1 -1
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
44
44
|
*
|
|
45
45
|
* *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*
|
|
46
46
|
*/
|
|
47
|
-
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, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, 'aria-label': ariaLabel, }) => {
|
|
47
|
+
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, enableKeyboardNavigation = false, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, rowThemes, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, 'aria-label': ariaLabel, }) => {
|
|
48
48
|
/**
|
|
49
49
|
* Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.
|
|
50
50
|
*/
|
|
@@ -138,10 +138,16 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
138
138
|
if (data.length === 0) {
|
|
139
139
|
return React__default.default.createElement(EmptyBody.EmptyBody, { table: table, emptyState: emptyState, emptySlot: emptySlot });
|
|
140
140
|
}
|
|
141
|
+
const bodyProps = {
|
|
142
|
+
table,
|
|
143
|
+
ariaRoles,
|
|
144
|
+
striped,
|
|
145
|
+
rowThemes,
|
|
146
|
+
};
|
|
141
147
|
if (table.getState().columnSizingInfo.isResizingColumn) {
|
|
142
|
-
return React__default.default.createElement(Body.MemoizedBody, {
|
|
148
|
+
return React__default.default.createElement(Body.MemoizedBody, { ...bodyProps });
|
|
143
149
|
}
|
|
144
|
-
return React__default.default.createElement(Body.Body, {
|
|
150
|
+
return React__default.default.createElement(Body.Body, { ...bodyProps });
|
|
145
151
|
};
|
|
146
152
|
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 },
|
|
147
153
|
enableColumnResizing && React__default.default.createElement(Columns.Columns, { table: table }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.cjs","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, getExpandedRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { EmptyBody, LoadingBody, MemoizedBody } from './components/Body';\n\nimport {\n usePinnedColumnLayout,\n useSortingState,\n useKeyboardNavigation,\n useColumnState,\n useExpandedState,\n useColumnWidthState,\n useSelectionState,\n} 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 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 rowGrouping,\n\n columnWidths,\n onColumnsResized,\n\n isLoading,\n loadingRowCount,\n\n emptyState,\n emptySlot,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n /**\n * Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.\n */\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(\n () => !isLoading && columns.some((column) => column.renderFooter),\n [isLoading, columns],\n );\n const ariaRoles = useMemo(\n () => getAriaRoles({ enableKeyboardNavigation, rowGrouping }),\n [enableKeyboardNavigation, rowGrouping],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection, sorting, and expanded/collapsed.\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 const { expanded, onExpandedChange, enableExpanding, getRowCanExpand, getSubRows } =\n useExpandedState(rowGrouping);\n\n /**\n * Hooks to setup column state, including visibility, ordering, pinning, and width(s).\n */\n const { mappedColumnDefinitions, columnOrder, columnVisibility, columnPinning } = useColumnState({\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n enableRowSelection: !!enableRowSelection,\n });\n\n const { columnSizing, onColumnSizingChange } = useColumnWidthState({\n mappedColumnDefinitions,\n columnWidths,\n onColumnsResized,\n });\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 onColumnSizingChange,\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 // Row grouping\n getSubRows,\n getRowCanExpand,\n onExpandedChange,\n enableExpanding,\n getExpandedRowModel: enableExpanding ? getExpandedRowModel() : undefined,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n expanded,\n columnSizing,\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 const renderBody = () => {\n if (isLoading) {\n return <LoadingBody table={table} loadingRowCount={loadingRowCount ?? 5} striped={striped} />;\n }\n\n if (data.length === 0) {\n return <EmptyBody table={table} emptyState={emptyState} emptySlot={emptySlot} />;\n }\n\n if (table.getState().columnSizingInfo.isResizingColumn) {\n return <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />;\n }\n\n return <Body table={table} ariaRoles={ariaRoles} striped={striped} />;\n };\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 {renderBody()}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["useRef","useMemo","getAriaRoles","useSelectionState","useSortingState","useExpandedState","useColumnState","useColumnWidthState","useReactTable","getCoreRowModel","getExpandedRowModel","usePinnedColumnLayout","useDragToScroll","useKeyboardNavigation","React","LoadingBody","EmptyBody","MemoizedBody","Body","GridContainer","Columns","Header","Footer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,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,EAEhC,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EAEb,I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,EAAE,KAAK,EAAI,CAAA;AAGlD,QAAAN,sBAAA,CAAA,aAAA,CAACO,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGvB,QAAA,UAAU,EAAE;AAGZ,QAAA,UAAU,IAAIP,sBAAA,CAAA,aAAA,CAACQ,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, getExpandedRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { EmptyBody, LoadingBody, MemoizedBody } from './components/Body';\n\nimport {\n usePinnedColumnLayout,\n useSortingState,\n useKeyboardNavigation,\n useColumnState,\n useExpandedState,\n useColumnWidthState,\n useSelectionState,\n} 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 enableKeyboardNavigation = false,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n rowThemes,\n\n sortState,\n onSortChanged,\n\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n\n rowGrouping,\n\n columnWidths,\n onColumnsResized,\n\n isLoading,\n loadingRowCount,\n\n emptyState,\n emptySlot,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n /**\n * Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.\n */\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(\n () => !isLoading && columns.some((column) => column.renderFooter),\n [isLoading, columns],\n );\n const ariaRoles = useMemo(\n () => getAriaRoles({ enableKeyboardNavigation, rowGrouping }),\n [enableKeyboardNavigation, rowGrouping],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection, sorting, and expanded/collapsed.\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 const { expanded, onExpandedChange, enableExpanding, getRowCanExpand, getSubRows } =\n useExpandedState(rowGrouping);\n\n /**\n * Hooks to setup column state, including visibility, ordering, pinning, and width(s).\n */\n const { mappedColumnDefinitions, columnOrder, columnVisibility, columnPinning } = useColumnState({\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n enableRowSelection: !!enableRowSelection,\n });\n\n const { columnSizing, onColumnSizingChange } = useColumnWidthState({\n mappedColumnDefinitions,\n columnWidths,\n onColumnsResized,\n });\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 onColumnSizingChange,\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 // Row grouping\n getSubRows,\n getRowCanExpand,\n onExpandedChange,\n enableExpanding,\n getExpandedRowModel: enableExpanding ? getExpandedRowModel() : undefined,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n expanded,\n columnSizing,\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 const renderBody = () => {\n if (isLoading) {\n return <LoadingBody table={table} loadingRowCount={loadingRowCount ?? 5} striped={striped} />;\n }\n\n if (data.length === 0) {\n return <EmptyBody table={table} emptyState={emptyState} emptySlot={emptySlot} />;\n }\n\n const bodyProps = {\n table,\n ariaRoles,\n striped,\n rowThemes,\n };\n\n if (table.getState().columnSizingInfo.isResizingColumn) {\n return <MemoizedBody {...bodyProps} />;\n }\n\n return <Body {...bodyProps} />;\n };\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 {renderBody()}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["useRef","useMemo","getAriaRoles","useSelectionState","useSortingState","useExpandedState","useColumnState","useColumnWidthState","useReactTable","getCoreRowModel","getExpandedRowModel","usePinnedColumnLayout","useDragToScroll","useKeyboardNavigation","React","LoadingBody","EmptyBody","MemoizedBody","Body","GridContainer","Columns","Header","Footer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,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,EAEhC,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EAEb,IAAI,EACJ,QAAQ,EACR,SAAS,EAET,SAAS,EACT,aAAa,EAEb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAElB,WAAW,EAEX,YAAY,EACZ,gBAAgB,EAEhB,SAAS,EACT,eAAe,EAEf,UAAU,EACV,SAAS,EAET,YAAY,EAAE,SAAS,GACT,KAAI;AAClB;;AAEG;AACH,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAiB,IAAI,CAAC;AACjD,IAAA,MAAM,QAAQ,GAAGA,YAAM,CAAmB,IAAI,CAAC;AAE/C,IAAA,MAAM,UAAU,GAAGC,aAAO,CACxB,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC,EACjE,CAAC,SAAS,EAAE,OAAO,CAAC,CACrB;IACD,MAAM,SAAS,GAAGA,aAAO,CACvB,MAAMC,yBAAY,CAAC,EAAE,wBAAwB,EAAE,WAAW,EAAE,CAAC,EAC7D,CAAC,wBAAwB,EAAE,WAAW,CAAC,CACxC;AACD,IAAA,MAAM,oBAAoB,GAAGD,aAAO,CAA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,EAAA,GAAA,SAAS,GAAI;AACvC;AAED,QAAA,OAAOH,sBAAC,CAAA,aAAA,CAAAI,SAAI,EAAK,EAAA,GAAA,SAAS,GAAI;AAChC,KAAC;AAED,IAAA,QACEJ,sBAAC,CAAA,aAAA,CAAAK,2BAAa,IACZ,YAAY,EAAE,YAAY,EAC1B,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,IAAIL,sBAAC,CAAA,aAAA,CAAAM,eAAO,IAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGlD,QAAAN,sBAAA,CAAA,aAAA,CAACO,aAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAI,CAAA;AAGvB,QAAA,UAAU,EAAE;AAGZ,QAAA,UAAU,IAAIP,sBAAA,CAAA,aAAA,CAACQ,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, enableKeyboardNavigation, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, "aria-label": ariaLabel, }: DataGridProps) => React.JSX.Element;
|
|
21
|
+
export declare const DataGrid: ({ density, striped, borderMode, resizeMode, containerStyle, enableKeyboardNavigation, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, rowThemes, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, "aria-label": ariaLabel, }: DataGridProps) => React.JSX.Element;
|
|
@@ -38,7 +38,7 @@ import { useExpandedState } from './hooks/useExpandedState.js';
|
|
|
38
38
|
*
|
|
39
39
|
* *Important: This component uses CSS modules, and therefore requires a `<ThemeInjector />` to be present on your page.*
|
|
40
40
|
*/
|
|
41
|
-
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, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, 'aria-label': ariaLabel, }) => {
|
|
41
|
+
const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resizeMode = 'off', containerStyle, enableKeyboardNavigation = false, columns, hiddenColumns, columnOrdering, pinnedColumns, data, getRowId, rowThemes, sortState, onSortChanged, selectionMode, selectedRows, disabledRows, onSelectionChanged, rowGrouping, columnWidths, onColumnsResized, isLoading, loadingRowCount, emptyState, emptySlot, 'aria-label': ariaLabel, }) => {
|
|
42
42
|
/**
|
|
43
43
|
* Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.
|
|
44
44
|
*/
|
|
@@ -132,10 +132,16 @@ const DataGrid = ({ density = 'base', striped = true, borderMode = 'full', resiz
|
|
|
132
132
|
if (data.length === 0) {
|
|
133
133
|
return React__default.createElement(EmptyBody, { table: table, emptyState: emptyState, emptySlot: emptySlot });
|
|
134
134
|
}
|
|
135
|
+
const bodyProps = {
|
|
136
|
+
table,
|
|
137
|
+
ariaRoles,
|
|
138
|
+
striped,
|
|
139
|
+
rowThemes,
|
|
140
|
+
};
|
|
135
141
|
if (table.getState().columnSizingInfo.isResizingColumn) {
|
|
136
|
-
return React__default.createElement(MemoizedBody, {
|
|
142
|
+
return React__default.createElement(MemoizedBody, { ...bodyProps });
|
|
137
143
|
}
|
|
138
|
-
return React__default.createElement(Body, {
|
|
144
|
+
return React__default.createElement(Body, { ...bodyProps });
|
|
139
145
|
};
|
|
140
146
|
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 },
|
|
141
147
|
enableColumnResizing && React__default.createElement(Columns, { table: table }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGrid.js","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, getExpandedRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { EmptyBody, LoadingBody, MemoizedBody } from './components/Body';\n\nimport {\n usePinnedColumnLayout,\n useSortingState,\n useKeyboardNavigation,\n useColumnState,\n useExpandedState,\n useColumnWidthState,\n useSelectionState,\n} 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 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 rowGrouping,\n\n columnWidths,\n onColumnsResized,\n\n isLoading,\n loadingRowCount,\n\n emptyState,\n emptySlot,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n /**\n * Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.\n */\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(\n () => !isLoading && columns.some((column) => column.renderFooter),\n [isLoading, columns],\n );\n const ariaRoles = useMemo(\n () => getAriaRoles({ enableKeyboardNavigation, rowGrouping }),\n [enableKeyboardNavigation, rowGrouping],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection, sorting, and expanded/collapsed.\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 const { expanded, onExpandedChange, enableExpanding, getRowCanExpand, getSubRows } =\n useExpandedState(rowGrouping);\n\n /**\n * Hooks to setup column state, including visibility, ordering, pinning, and width(s).\n */\n const { mappedColumnDefinitions, columnOrder, columnVisibility, columnPinning } = useColumnState({\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n enableRowSelection: !!enableRowSelection,\n });\n\n const { columnSizing, onColumnSizingChange } = useColumnWidthState({\n mappedColumnDefinitions,\n columnWidths,\n onColumnsResized,\n });\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 onColumnSizingChange,\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 // Row grouping\n getSubRows,\n getRowCanExpand,\n onExpandedChange,\n enableExpanding,\n getExpandedRowModel: enableExpanding ? getExpandedRowModel() : undefined,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n expanded,\n columnSizing,\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 const renderBody = () => {\n if (isLoading) {\n return <LoadingBody table={table} loadingRowCount={loadingRowCount ?? 5} striped={striped} />;\n }\n\n if (data.length === 0) {\n return <EmptyBody table={table} emptyState={emptyState} emptySlot={emptySlot} />;\n }\n\n if (table.getState().columnSizingInfo.isResizingColumn) {\n return <MemoizedBody table={table} ariaRoles={ariaRoles} striped={striped} />;\n }\n\n return <Body table={table} ariaRoles={ariaRoles} striped={striped} />;\n };\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 {renderBody()}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,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,EAEhC,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EAEb,IAAI,EACJ,QAAQ,EAER,SAAS,EACT,aAAa,EAEb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAElB,WAAW,EAEX,YAAY,EACZ,gBAAgB,EAEhB,SAAS,EACT,eAAe,EAEf,UAAU,EACV,SAAS,EAET,YAAY,EAAE,SAAS,GACT,KAAI;AAClB;;AAEG;AACH,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;AACjD,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAmB,IAAI,CAAC;AAE/C,IAAA,MAAM,UAAU,GAAG,OAAO,CACxB,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC,EACjE,CAAC,SAAS,EAAE,OAAO,CAAC,CACrB;IACD,MAAM,SAAS,GAAG,OAAO,CACvB,MAAM,YAAY,CAAC,EAAE,wBAAwB,EAAE,WAAW,EAAE,CAAC,EAC7D,CAAC,wBAAwB,EAAE,WAAW,CAAC,CACxC;AACD,IAAA,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,UAAU,KAAK,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC;AAE9E;;AAEG;I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AE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAI;AACvE,KAAC;AAED,IAAA,QACEA,cAAC,CAAA,aAAA,CAAA,aAAa,IACZ,YAAY,EAAE,YAAY,EAC1B,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;AAGvB,QAAA,UAAU,EAAE;AAGZ,QAAA,UAAU,IAAIA,cAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAI,CAAA,CAC/C;AAEpB;;;;"}
|
|
1
|
+
{"version":3,"file":"DataGrid.js","sources":["../../../src/components/DataGrid/DataGrid.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { getCoreRowModel, getExpandedRowModel, useReactTable } from '@tanstack/react-table';\n\nimport { useDragToScroll } from '../../hooks';\n\nimport { DataGridProps } from './types';\nimport { getAriaRoles } from './utils';\nimport { GridContainer, Header, Body, Footer, Columns } from './components';\nimport { EmptyBody, LoadingBody, MemoizedBody } from './components/Body';\n\nimport {\n usePinnedColumnLayout,\n useSortingState,\n useKeyboardNavigation,\n useColumnState,\n useExpandedState,\n useColumnWidthState,\n useSelectionState,\n} 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 enableKeyboardNavigation = false,\n\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n\n data,\n getRowId,\n rowThemes,\n\n sortState,\n onSortChanged,\n\n selectionMode,\n selectedRows,\n disabledRows,\n onSelectionChanged,\n\n rowGrouping,\n\n columnWidths,\n onColumnsResized,\n\n isLoading,\n loadingRowCount,\n\n emptyState,\n emptySlot,\n\n 'aria-label': ariaLabel,\n}: DataGridProps) => {\n /**\n * Refs to the table and table container. Used for keyboard navigation and drag-to-scroll.\n */\n const containerRef = useRef<HTMLDivElement>(null);\n const tableRef = useRef<HTMLTableElement>(null);\n\n const showFooter = useMemo(\n () => !isLoading && columns.some((column) => column.renderFooter),\n [isLoading, columns],\n );\n const ariaRoles = useMemo(\n () => getAriaRoles({ enableKeyboardNavigation, rowGrouping }),\n [enableKeyboardNavigation, rowGrouping],\n );\n const enableColumnResizing = useMemo(() => resizeMode !== 'off', [resizeMode]);\n\n /**\n * Hooks to handle state for selection, sorting, and expanded/collapsed.\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 const { expanded, onExpandedChange, enableExpanding, getRowCanExpand, getSubRows } =\n useExpandedState(rowGrouping);\n\n /**\n * Hooks to setup column state, including visibility, ordering, pinning, and width(s).\n */\n const { mappedColumnDefinitions, columnOrder, columnVisibility, columnPinning } = useColumnState({\n columns,\n hiddenColumns,\n columnOrdering,\n pinnedColumns,\n enableRowSelection: !!enableRowSelection,\n });\n\n const { columnSizing, onColumnSizingChange } = useColumnWidthState({\n mappedColumnDefinitions,\n columnWidths,\n onColumnsResized,\n });\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 onColumnSizingChange,\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 // Row grouping\n getSubRows,\n getRowCanExpand,\n onExpandedChange,\n enableExpanding,\n getExpandedRowModel: enableExpanding ? getExpandedRowModel() : undefined,\n\n // Inject external table state\n state: {\n columnOrder,\n columnVisibility,\n columnPinning,\n sorting,\n rowSelection,\n expanded,\n columnSizing,\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 const renderBody = () => {\n if (isLoading) {\n return <LoadingBody table={table} loadingRowCount={loadingRowCount ?? 5} striped={striped} />;\n }\n\n if (data.length === 0) {\n return <EmptyBody table={table} emptyState={emptyState} emptySlot={emptySlot} />;\n }\n\n const bodyProps = {\n table,\n ariaRoles,\n striped,\n rowThemes,\n };\n\n if (table.getState().columnSizingInfo.isResizingColumn) {\n return <MemoizedBody {...bodyProps} />;\n }\n\n return <Body {...bodyProps} />;\n };\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 {renderBody()}\n\n {/* Footer */}\n {showFooter && <Footer table={table} ariaRoles={ariaRoles} />}\n </GridContainer>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;AAiBG;AACI,MAAM,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,EAEhC,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EAEb,IAAI,EACJ,QAAQ,EACR,SAAS,EAET,SAAS,EACT,aAAa,EAEb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAElB,WAAW,EAEX,YAAY,EACZ,gBAAgB,EAEhB,SAAS,EACT,eAAe,EAEf,UAAU,EACV,SAAS,EAET,YAAY,EAAE,SAAS,GACT,KAAI;AAClB;;AAEG;AACH,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;AACjD,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAmB,IAAI,CAAC;AAE/C,IAAA,MAAM,UAAU,GAAG,OAAO,CACxB,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,C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AA,MAAM,SAAS,GAAG;YAChB,KAAK;YACL,SAAS;YACT,OAAO;YACP,SAAS;SACV;QAED,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,EAAE;AACtD,YAAA,OAAOA,cAAC,CAAA,aAAA,CAAA,YAAY,EAAK,EAAA,GAAA,SAAS,GAAI;AACvC;AAED,QAAA,OAAOA,cAAC,CAAA,aAAA,CAAA,IAAI,EAAK,EAAA,GAAA,SAAS,GAAI;AAChC,KAAC;AAED,IAAA,QACEA,cAAC,CAAA,aAAA,CAAA,aAAa,IACZ,YAAY,EAAE,YAAY,EAC1B,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;AAGvB,QAAA,UAAU,EAAE;AAGZ,QAAA,UAAU,IAAIA,cAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAI,CAAA,CAC/C;AAEpB;;;;"}
|
|
@@ -8,11 +8,15 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
10
10
|
|
|
11
|
-
const Body = ({ table, striped, ariaRoles }) => {
|
|
11
|
+
const Body = ({ table, striped, rowThemes, ariaRoles }) => {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
const enableExpanding = (_a = table.options.enableExpanding) !== null && _a !== undefined ? _a : false;
|
|
14
14
|
const enableRowSelection = (_b = table.options.enableRowSelection) !== null && _b !== undefined ? _b : false;
|
|
15
|
-
return (React__default.default.createElement("tbody", { className: "data-grid-body", "aria-busy": "false" }, table.getRowModel().rows.map((row) =>
|
|
15
|
+
return (React__default.default.createElement("tbody", { className: "data-grid-body", "aria-busy": "false" }, table.getRowModel().rows.map((row) => {
|
|
16
|
+
const rowTheme = rowThemes === null || rowThemes === undefined ? undefined : rowThemes[row.id];
|
|
17
|
+
const selected = row.getIsSelected();
|
|
18
|
+
return (React__default.default.createElement(Row.Row, { key: row.id, row: row, striped: striped, selected: selected, rowTheme: rowTheme, enableExpanding: enableExpanding }, row.getVisibleCells().map((cell) => (React__default.default.createElement(BodyCell.BodyCell, { cell: cell, key: cell.id, ariaRoles: ariaRoles, enableExpanding: enableExpanding, enableRowSelection: !!enableRowSelection })))));
|
|
19
|
+
})));
|
|
16
20
|
};
|
|
17
21
|
/**
|
|
18
22
|
* Memoized table body, used to prevent rerenders when columns are being resized.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Body.cjs","sources":["../../../../../src/components/DataGrid/components/Body/Body.tsx"],"sourcesContent":["import React from 'react';\nimport { Table } from '@tanstack/react-table';\n\nimport { BodyCell } from './BodyCell';\nimport { Row } from './Row';\nimport { AriaRoles } from '../../types';\n\ntype BodyProps = {\n /**\n * TanStack table instance.\n */\n table: Table<any>;\n\n /**\n * Whether the rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * ARIA roles for the table.\n */\n ariaRoles: AriaRoles;\n};\n\nexport const Body = ({ table, striped, ariaRoles }: BodyProps) => {\n const enableExpanding = table.options.enableExpanding ?? false;\n const enableRowSelection = table.options.enableRowSelection ?? false;\n\n return (\n <tbody className=\"data-grid-body\" aria-busy=\"false\">\n {table.getRowModel().rows.map((row) => (\n <Row
|
|
1
|
+
{"version":3,"file":"Body.cjs","sources":["../../../../../src/components/DataGrid/components/Body/Body.tsx"],"sourcesContent":["import React from 'react';\nimport { Table } from '@tanstack/react-table';\n\nimport { BodyCell } from './BodyCell';\nimport { Row } from './Row';\nimport { AriaRoles, RowThemeMap } from '../../types';\n\ntype BodyProps = {\n /**\n * TanStack table instance.\n */\n table: Table<any>;\n\n /**\n * Whether the rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * Map of row ID's to custom theming properties.\n */\n rowThemes?: RowThemeMap;\n\n /**\n * ARIA roles for the table.\n */\n ariaRoles: AriaRoles;\n};\n\nexport const Body = ({ table, striped, rowThemes, ariaRoles }: BodyProps) => {\n const enableExpanding = table.options.enableExpanding ?? false;\n const enableRowSelection = table.options.enableRowSelection ?? false;\n\n return (\n <tbody className=\"data-grid-body\" aria-busy=\"false\">\n {table.getRowModel().rows.map((row) => {\n const rowTheme = rowThemes?.[row.id];\n const selected = row.getIsSelected();\n\n return (\n <Row\n key={row.id}\n row={row}\n striped={striped}\n selected={selected}\n rowTheme={rowTheme}\n enableExpanding={enableExpanding}\n >\n {row.getVisibleCells().map((cell) => (\n <BodyCell\n cell={cell}\n key={cell.id}\n ariaRoles={ariaRoles}\n enableExpanding={enableExpanding}\n enableRowSelection={!!enableRowSelection}\n />\n ))}\n </Row>\n );\n })}\n </tbody>\n );\n};\n\n/**\n * Memoized table body, used to prevent rerenders when columns are being resized.\n */\nexport const MemoizedBody = React.memo(\n Body,\n (prev, next) => prev.table.options.data === next.table.options.data,\n);\n"],"names":["React","Row","BodyCell"],"mappings":";;;;;;;;;;AA6BO,MAAM,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAa,KAAI;;IAC1E,MAAM,eAAe,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,OAAO,CAAC,eAAe,MAAI,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,EAAA,GAAA,KAAK;IAC9D,MAAM,kBAAkB,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC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3
|
+
import { AriaRoles, RowThemeMap } from '../../types';
|
|
4
4
|
type BodyProps = {
|
|
5
5
|
/**
|
|
6
6
|
* TanStack table instance.
|
|
@@ -10,14 +10,18 @@ type BodyProps = {
|
|
|
10
10
|
* Whether the rows should be striped or not.
|
|
11
11
|
*/
|
|
12
12
|
striped: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Map of row ID's to custom theming properties.
|
|
15
|
+
*/
|
|
16
|
+
rowThemes?: RowThemeMap;
|
|
13
17
|
/**
|
|
14
18
|
* ARIA roles for the table.
|
|
15
19
|
*/
|
|
16
20
|
ariaRoles: AriaRoles;
|
|
17
21
|
};
|
|
18
|
-
export declare const Body: ({ table, striped, ariaRoles }: BodyProps) => React.JSX.Element;
|
|
22
|
+
export declare const Body: ({ table, striped, rowThemes, ariaRoles }: BodyProps) => React.JSX.Element;
|
|
19
23
|
/**
|
|
20
24
|
* Memoized table body, used to prevent rerenders when columns are being resized.
|
|
21
25
|
*/
|
|
22
|
-
export declare const MemoizedBody: React.MemoExoticComponent<({ table, striped, ariaRoles }: BodyProps) => React.JSX.Element>;
|
|
26
|
+
export declare const MemoizedBody: React.MemoExoticComponent<({ table, striped, rowThemes, ariaRoles }: BodyProps) => React.JSX.Element>;
|
|
23
27
|
export {};
|
|
@@ -2,11 +2,15 @@ import React__default from 'react';
|
|
|
2
2
|
import { BodyCell } from './BodyCell/BodyCell.js';
|
|
3
3
|
import { Row } from './Row/Row.js';
|
|
4
4
|
|
|
5
|
-
const Body = ({ table, striped, ariaRoles }) => {
|
|
5
|
+
const Body = ({ table, striped, rowThemes, ariaRoles }) => {
|
|
6
6
|
var _a, _b;
|
|
7
7
|
const enableExpanding = (_a = table.options.enableExpanding) !== null && _a !== undefined ? _a : false;
|
|
8
8
|
const enableRowSelection = (_b = table.options.enableRowSelection) !== null && _b !== undefined ? _b : false;
|
|
9
|
-
return (React__default.createElement("tbody", { className: "data-grid-body", "aria-busy": "false" }, table.getRowModel().rows.map((row) =>
|
|
9
|
+
return (React__default.createElement("tbody", { className: "data-grid-body", "aria-busy": "false" }, table.getRowModel().rows.map((row) => {
|
|
10
|
+
const rowTheme = rowThemes === null || rowThemes === undefined ? undefined : rowThemes[row.id];
|
|
11
|
+
const selected = row.getIsSelected();
|
|
12
|
+
return (React__default.createElement(Row, { key: row.id, row: row, striped: striped, selected: selected, rowTheme: rowTheme, enableExpanding: enableExpanding }, row.getVisibleCells().map((cell) => (React__default.createElement(BodyCell, { cell: cell, key: cell.id, ariaRoles: ariaRoles, enableExpanding: enableExpanding, enableRowSelection: !!enableRowSelection })))));
|
|
13
|
+
})));
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* Memoized table body, used to prevent rerenders when columns are being resized.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Body.js","sources":["../../../../../src/components/DataGrid/components/Body/Body.tsx"],"sourcesContent":["import React from 'react';\nimport { Table } from '@tanstack/react-table';\n\nimport { BodyCell } from './BodyCell';\nimport { Row } from './Row';\nimport { AriaRoles } from '../../types';\n\ntype BodyProps = {\n /**\n * TanStack table instance.\n */\n table: Table<any>;\n\n /**\n * Whether the rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * ARIA roles for the table.\n */\n ariaRoles: AriaRoles;\n};\n\nexport const Body = ({ table, striped, ariaRoles }: BodyProps) => {\n const enableExpanding = table.options.enableExpanding ?? false;\n const enableRowSelection = table.options.enableRowSelection ?? false;\n\n return (\n <tbody className=\"data-grid-body\" aria-busy=\"false\">\n {table.getRowModel().rows.map((row) => (\n <Row
|
|
1
|
+
{"version":3,"file":"Body.js","sources":["../../../../../src/components/DataGrid/components/Body/Body.tsx"],"sourcesContent":["import React from 'react';\nimport { Table } from '@tanstack/react-table';\n\nimport { BodyCell } from './BodyCell';\nimport { Row } from './Row';\nimport { AriaRoles, RowThemeMap } from '../../types';\n\ntype BodyProps = {\n /**\n * TanStack table instance.\n */\n table: Table<any>;\n\n /**\n * Whether the rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * Map of row ID's to custom theming properties.\n */\n rowThemes?: RowThemeMap;\n\n /**\n * ARIA roles for the table.\n */\n ariaRoles: AriaRoles;\n};\n\nexport const Body = ({ table, striped, rowThemes, ariaRoles }: BodyProps) => {\n const enableExpanding = table.options.enableExpanding ?? false;\n const enableRowSelection = table.options.enableRowSelection ?? false;\n\n return (\n <tbody className=\"data-grid-body\" aria-busy=\"false\">\n {table.getRowModel().rows.map((row) => {\n const rowTheme = rowThemes?.[row.id];\n const selected = row.getIsSelected();\n\n return (\n <Row\n key={row.id}\n row={row}\n striped={striped}\n selected={selected}\n rowTheme={rowTheme}\n enableExpanding={enableExpanding}\n >\n {row.getVisibleCells().map((cell) => (\n <BodyCell\n cell={cell}\n key={cell.id}\n ariaRoles={ariaRoles}\n enableExpanding={enableExpanding}\n enableRowSelection={!!enableRowSelection}\n />\n ))}\n </Row>\n );\n })}\n </tbody>\n );\n};\n\n/**\n * Memoized table body, used to prevent rerenders when columns are being resized.\n */\nexport const MemoizedBody = React.memo(\n Body,\n (prev, next) => prev.table.options.data === next.table.options.data,\n);\n"],"names":["React"],"mappings":";;;;AA6BO,MAAM,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAa,KAAI;;IAC1E,MAAM,eAAe,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,OAAO,CAAC,eAAe,MAAI,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,EAAA,GAAA,KAAK;IAC9D,MAAM,kBAAkB,GAAG,CAAA,EAAA,GAAA,KAAK,CAAC,OAAO,CAAC,kBAAkB,MAAI,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,EAAA,GAAA,KAAK;IAEpE,QACEA,wCAAO,SAAS,EAAC,gBAAgB,EAAW,WAAA,EAAA,OAAO,IAChD,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAI;AACpC,QAAA,MAAM,QAAQ,GAAG,SAAS,KAAA,IAAA,IAAT,SAAS,KAAA,SAAA,GAAA,SAAA,GAAT,SAAS,CAAG,GAAG,CAAC,EAAE,CAAC;AACpC,QAAA,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,EAAE;AAEpC,QAAA,QACEA,cAAA,CAAA,aAAA,CAAC,GAAG,EAAA,EACF,GAAG,EAAE,GAAG,CAAC,EAAE,EACX,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,IAE/B,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,MAC9BA,6BAAC,QAAQ,EAAA,EACP,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,IAAI,CAAC,EAAE,EACZ,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,CAAC,CAAC,kBAAkB,EACxC,CAAA,CACH,CAAC,CACE;KAET,CAAC,CACI;AAEZ;AAEA;;AAEG;AACI,MAAM,YAAY,GAAGA,cAAK,CAAC,IAAI,CACpC,IAAI,EACJ,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI;;;;"}
|
|
@@ -27,7 +27,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
|
27
27
|
* Renders a cell element, and its content, for a given column and row, within the grid body.
|
|
28
28
|
*/
|
|
29
29
|
const BodyCell = ({ cell, ariaRoles, enableRowSelection, enableExpanding, }) => {
|
|
30
|
-
const { justifyContent, textAlign, rowHeader } = cell.column.columnDef.meta;
|
|
30
|
+
const { justifyContent, textAlign, rowHeader, generateDataTestId } = cell.column.columnDef.meta;
|
|
31
31
|
const CellElement = rowHeader ? 'th' : 'td';
|
|
32
32
|
const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles.usePinnedColumnStyles({ column: cell.column });
|
|
33
33
|
const { expandButtonProps, contentMarginLeft } = useExpandableCell.useExpandableCell({
|
|
@@ -40,12 +40,14 @@ const BodyCell = ({ cell, ariaRoles, enableRowSelection, enableExpanding, }) =>
|
|
|
40
40
|
pinnedCellClassName,
|
|
41
41
|
'data-grid-cell',
|
|
42
42
|
]);
|
|
43
|
-
|
|
43
|
+
const cellContext = cell.getContext();
|
|
44
|
+
const cellTestId = React.useMemo(() => (generateDataTestId ? generateDataTestId(cellContext.row.original) : undefined), [generateDataTestId, cellContext.row.original]);
|
|
45
|
+
return (React__default.default.createElement(CellElement, { className: bodyCellClassname, "aria-colindex": cell.column.getIndex() + 1, scope: rowHeader ? 'row' : undefined, role: rowHeader ? 'rowheader' : ariaRoles.cell, style: pinnedCellStyles, "data-testid": cellTestId },
|
|
44
46
|
React__default.default.createElement(CellContent.CellContent, { contentStyle: {
|
|
45
47
|
marginLeft: contentMarginLeft,
|
|
46
48
|
justifyContent,
|
|
47
49
|
textAlign,
|
|
48
|
-
}, expandButtonProps: expandButtonProps }, reactTable.flexRender(cell.column.columnDef.cell,
|
|
50
|
+
}, expandButtonProps: expandButtonProps }, reactTable.flexRender(cell.column.columnDef.cell, cellContext))));
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
exports.BodyCell = BodyCell;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BodyCell.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.tsx"],"sourcesContent":["import React from 'react';\n\nimport { Cell, flexRender } from '@tanstack/react-table';\n\nimport { buildClassnames } from '../../../../../utils';\n\nimport { AriaRoles } from '../../../types';\nimport { CellContent } from '../../CellContent';\nimport { usePinnedColumnStyles } from '../../../hooks';\n\nimport { useExpandableCell } from './hooks';\nimport styles from './BodyCell.module.scss';\n\ntype ColumnCellProps = {\n /**\n * Cell within the TanStack Table instance.\n */\n cell: Cell<any, any>;\n\n /**\n * ARIA roles for the grid.\n */\n ariaRoles: AriaRoles;\n\n /**\n * Whether row selection is enabled.\n */\n enableRowSelection: boolean;\n\n /**\n * Whether row expanding is enabled for the grid.\n */\n enableExpanding: boolean;\n};\n\n/**\n * Renders a cell element, and its content, for a given column and row, within the grid body.\n */\nexport const BodyCell = ({\n cell,\n ariaRoles,\n enableRowSelection,\n enableExpanding,\n}: ColumnCellProps) => {\n const { justifyContent, textAlign, rowHeader } = cell.column.columnDef.meta!;\n const CellElement = rowHeader ? 'th' : 'td';\n\n const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles({ column: cell.column });\n\n const { expandButtonProps, contentMarginLeft } = useExpandableCell({\n cell,\n enableExpanding,\n enableRowSelection,\n });\n\n const bodyCellClassname = buildClassnames([\n styles.bodyCell,\n pinnedCellClassName,\n 'data-grid-cell',\n ]);\n\n return (\n <CellElement\n className={bodyCellClassname}\n aria-colindex={cell.column.getIndex() + 1}\n scope={rowHeader ? 'row' : undefined}\n role={rowHeader ? 'rowheader' : ariaRoles.cell}\n style={pinnedCellStyles}\n >\n <CellContent\n contentStyle={\n {\n marginLeft: contentMarginLeft,\n justifyContent,\n textAlign,\n } as React.CSSProperties\n }\n expandButtonProps={expandButtonProps}\n >\n {flexRender(cell.column.columnDef.cell,
|
|
1
|
+
{"version":3,"file":"BodyCell.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\n\nimport { Cell, flexRender } from '@tanstack/react-table';\n\nimport { buildClassnames } from '../../../../../utils';\n\nimport { AriaRoles } from '../../../types';\nimport { CellContent } from '../../CellContent';\nimport { usePinnedColumnStyles } from '../../../hooks';\n\nimport { useExpandableCell } from './hooks';\nimport styles from './BodyCell.module.scss';\n\ntype ColumnCellProps = {\n /**\n * Cell within the TanStack Table instance.\n */\n cell: Cell<any, any>;\n\n /**\n * ARIA roles for the grid.\n */\n ariaRoles: AriaRoles;\n\n /**\n * Whether row selection is enabled.\n */\n enableRowSelection: boolean;\n\n /**\n * Whether row expanding is enabled for the grid.\n */\n enableExpanding: boolean;\n};\n\n/**\n * Renders a cell element, and its content, for a given column and row, within the grid body.\n */\nexport const BodyCell = ({\n cell,\n ariaRoles,\n enableRowSelection,\n enableExpanding,\n}: ColumnCellProps) => {\n const { justifyContent, textAlign, rowHeader, generateDataTestId } = cell.column.columnDef.meta!;\n const CellElement = rowHeader ? 'th' : 'td';\n\n const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles({ column: cell.column });\n\n const { expandButtonProps, contentMarginLeft } = useExpandableCell({\n cell,\n enableExpanding,\n enableRowSelection,\n });\n\n const bodyCellClassname = buildClassnames([\n styles.bodyCell,\n pinnedCellClassName,\n 'data-grid-cell',\n ]);\n\n const cellContext = cell.getContext();\n const cellTestId = useMemo(\n () => (generateDataTestId ? generateDataTestId(cellContext.row.original) : undefined),\n [generateDataTestId, cellContext.row.original],\n );\n\n return (\n <CellElement\n className={bodyCellClassname}\n aria-colindex={cell.column.getIndex() + 1}\n scope={rowHeader ? 'row' : undefined}\n role={rowHeader ? 'rowheader' : ariaRoles.cell}\n style={pinnedCellStyles}\n data-testid={cellTestId}\n >\n <CellContent\n contentStyle={\n {\n marginLeft: contentMarginLeft,\n justifyContent,\n textAlign,\n } as React.CSSProperties\n }\n expandButtonProps={expandButtonProps}\n >\n {flexRender(cell.column.columnDef.cell, cellContext)}\n </CellContent>\n </CellElement>\n );\n};\n"],"names":["usePinnedColumnStyles","useExpandableCell","buildClassnames","styles","useMemo","React","CellContent","flexRender"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;AAEG;AACI,MAAM,QAAQ,GAAG,CAAC,EACvB,IAAI,EACJ,SAAS,EACT,kBAAkB,EAClB,eAAe,GACC,KAAI;AACpB,IAAA,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS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AAElB;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
1
|
+
import React__default, { useMemo } from 'react';
|
|
2
2
|
import { flexRender } from '@tanstack/react-table';
|
|
3
3
|
import { buildClassnames } from '../../../../../utils/buildClassnames.js';
|
|
4
4
|
import 'uid/secure';
|
|
@@ -21,7 +21,7 @@ import styles from './BodyCell.module.scss.js';
|
|
|
21
21
|
* Renders a cell element, and its content, for a given column and row, within the grid body.
|
|
22
22
|
*/
|
|
23
23
|
const BodyCell = ({ cell, ariaRoles, enableRowSelection, enableExpanding, }) => {
|
|
24
|
-
const { justifyContent, textAlign, rowHeader } = cell.column.columnDef.meta;
|
|
24
|
+
const { justifyContent, textAlign, rowHeader, generateDataTestId } = cell.column.columnDef.meta;
|
|
25
25
|
const CellElement = rowHeader ? 'th' : 'td';
|
|
26
26
|
const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles({ column: cell.column });
|
|
27
27
|
const { expandButtonProps, contentMarginLeft } = useExpandableCell({
|
|
@@ -34,12 +34,14 @@ const BodyCell = ({ cell, ariaRoles, enableRowSelection, enableExpanding, }) =>
|
|
|
34
34
|
pinnedCellClassName,
|
|
35
35
|
'data-grid-cell',
|
|
36
36
|
]);
|
|
37
|
-
|
|
37
|
+
const cellContext = cell.getContext();
|
|
38
|
+
const cellTestId = useMemo(() => (generateDataTestId ? generateDataTestId(cellContext.row.original) : undefined), [generateDataTestId, cellContext.row.original]);
|
|
39
|
+
return (React__default.createElement(CellElement, { className: bodyCellClassname, "aria-colindex": cell.column.getIndex() + 1, scope: rowHeader ? 'row' : undefined, role: rowHeader ? 'rowheader' : ariaRoles.cell, style: pinnedCellStyles, "data-testid": cellTestId },
|
|
38
40
|
React__default.createElement(CellContent, { contentStyle: {
|
|
39
41
|
marginLeft: contentMarginLeft,
|
|
40
42
|
justifyContent,
|
|
41
43
|
textAlign,
|
|
42
|
-
}, expandButtonProps: expandButtonProps }, flexRender(cell.column.columnDef.cell,
|
|
44
|
+
}, expandButtonProps: expandButtonProps }, flexRender(cell.column.columnDef.cell, cellContext))));
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
export { BodyCell };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BodyCell.js","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.tsx"],"sourcesContent":["import React from 'react';\n\nimport { Cell, flexRender } from '@tanstack/react-table';\n\nimport { buildClassnames } from '../../../../../utils';\n\nimport { AriaRoles } from '../../../types';\nimport { CellContent } from '../../CellContent';\nimport { usePinnedColumnStyles } from '../../../hooks';\n\nimport { useExpandableCell } from './hooks';\nimport styles from './BodyCell.module.scss';\n\ntype ColumnCellProps = {\n /**\n * Cell within the TanStack Table instance.\n */\n cell: Cell<any, any>;\n\n /**\n * ARIA roles for the grid.\n */\n ariaRoles: AriaRoles;\n\n /**\n * Whether row selection is enabled.\n */\n enableRowSelection: boolean;\n\n /**\n * Whether row expanding is enabled for the grid.\n */\n enableExpanding: boolean;\n};\n\n/**\n * Renders a cell element, and its content, for a given column and row, within the grid body.\n */\nexport const BodyCell = ({\n cell,\n ariaRoles,\n enableRowSelection,\n enableExpanding,\n}: ColumnCellProps) => {\n const { justifyContent, textAlign, rowHeader } = cell.column.columnDef.meta!;\n const CellElement = rowHeader ? 'th' : 'td';\n\n const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles({ column: cell.column });\n\n const { expandButtonProps, contentMarginLeft } = useExpandableCell({\n cell,\n enableExpanding,\n enableRowSelection,\n });\n\n const bodyCellClassname = buildClassnames([\n styles.bodyCell,\n pinnedCellClassName,\n 'data-grid-cell',\n ]);\n\n return (\n <CellElement\n className={bodyCellClassname}\n aria-colindex={cell.column.getIndex() + 1}\n scope={rowHeader ? 'row' : undefined}\n role={rowHeader ? 'rowheader' : ariaRoles.cell}\n style={pinnedCellStyles}\n >\n <CellContent\n contentStyle={\n {\n marginLeft: contentMarginLeft,\n justifyContent,\n textAlign,\n } as React.CSSProperties\n }\n expandButtonProps={expandButtonProps}\n >\n {flexRender(cell.column.columnDef.cell,
|
|
1
|
+
{"version":3,"file":"BodyCell.js","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\n\nimport { Cell, flexRender } from '@tanstack/react-table';\n\nimport { buildClassnames } from '../../../../../utils';\n\nimport { AriaRoles } from '../../../types';\nimport { CellContent } from '../../CellContent';\nimport { usePinnedColumnStyles } from '../../../hooks';\n\nimport { useExpandableCell } from './hooks';\nimport styles from './BodyCell.module.scss';\n\ntype ColumnCellProps = {\n /**\n * Cell within the TanStack Table instance.\n */\n cell: Cell<any, any>;\n\n /**\n * ARIA roles for the grid.\n */\n ariaRoles: AriaRoles;\n\n /**\n * Whether row selection is enabled.\n */\n enableRowSelection: boolean;\n\n /**\n * Whether row expanding is enabled for the grid.\n */\n enableExpanding: boolean;\n};\n\n/**\n * Renders a cell element, and its content, for a given column and row, within the grid body.\n */\nexport const BodyCell = ({\n cell,\n ariaRoles,\n enableRowSelection,\n enableExpanding,\n}: ColumnCellProps) => {\n const { justifyContent, textAlign, rowHeader, generateDataTestId } = cell.column.columnDef.meta!;\n const CellElement = rowHeader ? 'th' : 'td';\n\n const { pinnedCellClassName, pinnedCellStyles } = usePinnedColumnStyles({ column: cell.column });\n\n const { expandButtonProps, contentMarginLeft } = useExpandableCell({\n cell,\n enableExpanding,\n enableRowSelection,\n });\n\n const bodyCellClassname = buildClassnames([\n styles.bodyCell,\n pinnedCellClassName,\n 'data-grid-cell',\n ]);\n\n const cellContext = cell.getContext();\n const cellTestId = useMemo(\n () => (generateDataTestId ? generateDataTestId(cellContext.row.original) : undefined),\n [generateDataTestId, cellContext.row.original],\n );\n\n return (\n <CellElement\n className={bodyCellClassname}\n aria-colindex={cell.column.getIndex() + 1}\n scope={rowHeader ? 'row' : undefined}\n role={rowHeader ? 'rowheader' : ariaRoles.cell}\n style={pinnedCellStyles}\n data-testid={cellTestId}\n >\n <CellContent\n contentStyle={\n {\n marginLeft: contentMarginLeft,\n justifyContent,\n textAlign,\n } as React.CSSProperties\n }\n expandButtonProps={expandButtonProps}\n >\n {flexRender(cell.column.columnDef.cell, cellContext)}\n </CellContent>\n </CellElement>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA;;AAEG;AACI,MAAM,QAAQ,GAAG,CAAC,EACvB,IAAI,EACJ,SAAS,EACT,kBAAkB,EAClB,eAAe,GACC,KAAI;AACpB,IAAA,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAK;IAChG,MAAM,WAAW,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI;AAE3C,IAAA,MAAM,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAEhG,IAAA,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,CAAC;QACjE,IAAI;QACJ,eAAe;QACf,kBAAkB;AACnB,KAAA,CAAC;IAEF,MAAM,iBAAiB,GAAG,eAAe,CAAC;AACxC,QAAA,MAAM,CAAC,QAAQ;QACf,mBAAmB;QACnB,gBAAgB;AACjB,KAAA,CAAC;AAEF,IAAA,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE;AACrC,IAAA,MAAM,UAAU,GAAG,OAAO,CACxB,OAAO,kBAAkB,GAAG,kBAAkB,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,EACrF,CAAC,kBAAkB,EAAE,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAC/C;IAED,QACEA,6BAAC,WAAW,EAAA,EACV,SAAS,EAAE,iBAAiB,mBACb,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,EACzC,KAAK,EAAE,SAAS,GAAG,KAAK,GAAG,SAAS,EACpC,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC,IAAI,EAC9C,KAAK,EAAE,gBAAgB,EAAA,aAAA,EACV,UAAU,EAAA;QAEvBA,cAAC,CAAA,aAAA,CAAA,WAAW,EACV,EAAA,YAAY,EACV;AACE,gBAAA,UAAU,EAAE,iBAAiB;gBAC7B,cAAc;gBACd,SAAS;AACa,aAAA,EAE1B,iBAAiB,EAAE,iBAAiB,IAEnC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CACxC,CACF;AAElB;;;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var ___$insertStyle = require('../../../../../_virtual/____insertStyle.cjs');
|
|
4
4
|
|
|
5
|
-
___$insertStyle(".
|
|
6
|
-
var styles = {"baseCell":"
|
|
5
|
+
___$insertStyle("._baseCell_1vcew_1, ._bodyCell_1vcew_1 {\n position: relative;\n box-sizing: border-box;\n}\n._baseCell_1vcew_1:focus, ._bodyCell_1vcew_1:focus, ._baseCell_1vcew_1:focus-visible, ._bodyCell_1vcew_1:focus-visible {\n outline: var(--sizes-none);\n box-shadow: inset var(--sizes-none) var(--sizes-none) var(--sizes-none) var(--sizes-line) var(--colors-secondary-blue-base);\n}\n\n._pinnedColumnBase_1vcew_10::after, ._pinnedColumnRight_1vcew_10::after, ._pinnedColumnLeft_1vcew_10::after {\n position: absolute;\n top: var(--sizes-none);\n bottom: -1px;\n width: 30px;\n content: \"\";\n pointer-events: none;\n box-sizing: border-box;\n}\n\n._pinnedColumnLeft_1vcew_10::after {\n transform: translate(100%);\n right: var(--sizes-none);\n box-shadow: inset 10px 0px 10px -8px rgba(0, 0, 0, 0.25);\n}\n\n._pinnedColumnRight_1vcew_10::after {\n transform: translate(-100%);\n left: var(--sizes-none);\n box-shadow: inset -10px 0px 10px -8px rgba(0, 0, 0, 0.25);\n}\n\n._bodyCell_1vcew_1 {\n background-color: white;\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}");
|
|
6
|
+
var styles = {"baseCell":"_baseCell_1vcew_1","bodyCell":"_bodyCell_1vcew_1","pinnedColumnBase":"_pinnedColumnBase_1vcew_10","pinnedColumnRight":"_pinnedColumnRight_1vcew_10","pinnedColumnLeft":"_pinnedColumnLeft_1vcew_10"};
|
|
7
7
|
|
|
8
8
|
module.exports = styles;
|
|
9
9
|
//# sourceMappingURL=BodyCell.module.scss.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BodyCell.module.scss.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss"],"sourcesContent":["@use '../../../DataGrid.module.scss';\n\n.bodyCell {\n @extend .baseCell;\n\n background-color: white;\n\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}\n
|
|
1
|
+
{"version":3,"file":"BodyCell.module.scss.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss"],"sourcesContent":["@use '../../../DataGrid.module.scss';\n\n.bodyCell {\n @extend .baseCell;\n\n background-color: white;\n\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}\n"],"names":[],"mappings":";;;;AACE,eAAA,CAAA,6vCAAA;AACA,aAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,kBAAA,CAAA,4BAAA,CAAA,mBAAA,CAAA,6BAAA,CAAA,kBAAA,CAAA,4BAAA;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import insertStyle from '../../../../../_virtual/____insertStyle.js';
|
|
2
2
|
|
|
3
|
-
insertStyle(".
|
|
4
|
-
var styles = {"baseCell":"
|
|
3
|
+
insertStyle("._baseCell_1vcew_1, ._bodyCell_1vcew_1 {\n position: relative;\n box-sizing: border-box;\n}\n._baseCell_1vcew_1:focus, ._bodyCell_1vcew_1:focus, ._baseCell_1vcew_1:focus-visible, ._bodyCell_1vcew_1:focus-visible {\n outline: var(--sizes-none);\n box-shadow: inset var(--sizes-none) var(--sizes-none) var(--sizes-none) var(--sizes-line) var(--colors-secondary-blue-base);\n}\n\n._pinnedColumnBase_1vcew_10::after, ._pinnedColumnRight_1vcew_10::after, ._pinnedColumnLeft_1vcew_10::after {\n position: absolute;\n top: var(--sizes-none);\n bottom: -1px;\n width: 30px;\n content: \"\";\n pointer-events: none;\n box-sizing: border-box;\n}\n\n._pinnedColumnLeft_1vcew_10::after {\n transform: translate(100%);\n right: var(--sizes-none);\n box-shadow: inset 10px 0px 10px -8px rgba(0, 0, 0, 0.25);\n}\n\n._pinnedColumnRight_1vcew_10::after {\n transform: translate(-100%);\n left: var(--sizes-none);\n box-shadow: inset -10px 0px 10px -8px rgba(0, 0, 0, 0.25);\n}\n\n._bodyCell_1vcew_1 {\n background-color: white;\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}");
|
|
4
|
+
var styles = {"baseCell":"_baseCell_1vcew_1","bodyCell":"_bodyCell_1vcew_1","pinnedColumnBase":"_pinnedColumnBase_1vcew_10","pinnedColumnRight":"_pinnedColumnRight_1vcew_10","pinnedColumnLeft":"_pinnedColumnLeft_1vcew_10"};
|
|
5
5
|
|
|
6
6
|
export { styles as default };
|
|
7
7
|
//# sourceMappingURL=BodyCell.module.scss.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BodyCell.module.scss.js","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss"],"sourcesContent":["@use '../../../DataGrid.module.scss';\n\n.bodyCell {\n @extend .baseCell;\n\n background-color: white;\n\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}\n
|
|
1
|
+
{"version":3,"file":"BodyCell.module.scss.js","sources":["../../../../../../src/components/DataGrid/components/Body/BodyCell/BodyCell.module.scss"],"sourcesContent":["@use '../../../DataGrid.module.scss';\n\n.bodyCell {\n @extend .baseCell;\n\n background-color: white;\n\n color: var(--text-body-small-color);\n font-family: var(--text-body-small-font-family);\n font-size: var(--text-body-small-font-size);\n font-weight: var(--text-body-small-font-weight);\n line-height: var(--text-body-small-line-height);\n}\n"],"names":["___$insertStyle"],"mappings":";;AACEA,WAAA,CAAA,6vCAAA;AACA,aAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,kBAAA,CAAA,4BAAA,CAAA,mBAAA,CAAA,6BAAA,CAAA,kBAAA,CAAA,4BAAA;;;;"}
|
|
@@ -3,12 +3,23 @@
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var buildClassnames = require('../../../../../utils/buildClassnames.cjs');
|
|
5
5
|
require('uid/secure');
|
|
6
|
+
var useRowTheme = require('./hooks/useRowTheme.cjs');
|
|
7
|
+
var Row_module = require('./Row.module.scss.cjs');
|
|
6
8
|
|
|
7
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
8
10
|
|
|
9
11
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
10
12
|
|
|
11
|
-
const Row = ({ row, striped, enableExpanding, children }) =>
|
|
13
|
+
const Row = ({ row, striped, selected, enableExpanding, rowTheme, children }) => {
|
|
14
|
+
const { themeVars, themeClasses } = useRowTheme.useRowTheme({ rowTheme });
|
|
15
|
+
const classNames = buildClassnames.buildClassnames([
|
|
16
|
+
Row_module.row,
|
|
17
|
+
striped && Row_module.striped,
|
|
18
|
+
selected && Row_module.selected,
|
|
19
|
+
themeClasses,
|
|
20
|
+
]);
|
|
21
|
+
return (React__default.default.createElement("tr", { className: classNames, key: row.id, "aria-rowindex": row.index + 2, "aria-level": enableExpanding ? row.depth + 1 : undefined, style: themeVars }, children));
|
|
22
|
+
};
|
|
12
23
|
|
|
13
24
|
exports.Row = Row;
|
|
14
25
|
//# sourceMappingURL=Row.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.tsx"],"sourcesContent":["import React from 'react';\n\nimport { buildClassnames } from '../../../../../utils';\n\
|
|
1
|
+
{"version":3,"file":"Row.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.tsx"],"sourcesContent":["import React from 'react';\n\nimport { buildClassnames } from '../../../../../utils';\nimport { RowTheme } from '../../../types';\nimport { useRowTheme } from './hooks';\n\nimport styles from './Row.module.scss';\n\nexport type RowProps = {\n /**\n * Row information, including id, index, and depth (typically the TanStack table row).\n */\n row: {\n id: string;\n index: number;\n depth: number;\n };\n\n /**\n * Whether rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * Whether the row is selected.\n */\n selected?: boolean;\n\n /**\n * Whether row expanding is enabled.\n */\n enableExpanding: boolean;\n\n /**\n * Optional theming properties for this row.\n */\n rowTheme?: RowTheme;\n\n /**\n * Child elements (table cells).\n */\n children: React.ReactNode;\n};\n\nexport const Row = ({ row, striped, selected, enableExpanding, rowTheme, children }: RowProps) => {\n const { themeVars, themeClasses } = useRowTheme({ rowTheme });\n\n const classNames = buildClassnames([\n styles.row,\n striped && styles.striped,\n selected && styles.selected,\n themeClasses,\n ]);\n\n return (\n <tr\n className={classNames}\n key={row.id}\n // 0-based index + header row.\n aria-rowindex={row.index + 2}\n aria-level={enableExpanding ? row.depth + 1 : undefined}\n style={themeVars}\n >\n {children}\n </tr>\n );\n};"],"names":["useRowTheme","buildClassnames","styles","React"],"mappings":";;;;;;;;;;;;AA4Ca,MAAA,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAY,KAAI;AAC/F,IAAA,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAGA,uBAAW,CAAC,EAAE,QAAQ,EAAE,CAAC;IAE7D,MAAM,UAAU,GAAGC,+BAAe,CAAC;AACjC,QAAAC,UAAM,CAAC,GAAG;QACV,OAAO,IAAIA,UAAM,CAAC,OAAO;QACzB,QAAQ,IAAIA,UAAM,CAAC,QAAQ;QAC3B,YAAY;AACb,KAAA,CAAC;AAEF,IAAA,QACEC,sBACE,CAAA,aAAA,CAAA,IAAA,EAAA,EAAA,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,GAAG,CAAC,EAAE,EAEI,eAAA,EAAA,GAAG,CAAC,KAAK,GAAG,CAAC,EAChB,YAAA,EAAA,eAAe,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,EACvD,KAAK,EAAE,SAAS,IAEf,QAAQ,CACN;AAET;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import { RowTheme } from '../../../types';
|
|
3
|
+
export type RowProps = {
|
|
3
4
|
/**
|
|
4
5
|
* Row information, including id, index, and depth (typically the TanStack table row).
|
|
5
6
|
*/
|
|
@@ -12,14 +13,21 @@ type RowProps = {
|
|
|
12
13
|
* Whether rows should be striped or not.
|
|
13
14
|
*/
|
|
14
15
|
striped: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the row is selected.
|
|
18
|
+
*/
|
|
19
|
+
selected?: boolean;
|
|
15
20
|
/**
|
|
16
21
|
* Whether row expanding is enabled.
|
|
17
22
|
*/
|
|
18
23
|
enableExpanding: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Optional theming properties for this row.
|
|
26
|
+
*/
|
|
27
|
+
rowTheme?: RowTheme;
|
|
19
28
|
/**
|
|
20
29
|
* Child elements (table cells).
|
|
21
30
|
*/
|
|
22
31
|
children: React.ReactNode;
|
|
23
32
|
};
|
|
24
|
-
export declare const Row: ({ row, striped, enableExpanding, children }: RowProps) => React.JSX.Element;
|
|
25
|
-
export {};
|
|
33
|
+
export declare const Row: ({ row, striped, selected, enableExpanding, rowTheme, children }: RowProps) => React.JSX.Element;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { buildClassnames } from '../../../../../utils/buildClassnames.js';
|
|
3
3
|
import 'uid/secure';
|
|
4
|
+
import { useRowTheme } from './hooks/useRowTheme.js';
|
|
5
|
+
import styles from './Row.module.scss.js';
|
|
4
6
|
|
|
5
|
-
const Row = ({ row, striped, enableExpanding, children }) =>
|
|
7
|
+
const Row = ({ row, striped, selected, enableExpanding, rowTheme, children }) => {
|
|
8
|
+
const { themeVars, themeClasses } = useRowTheme({ rowTheme });
|
|
9
|
+
const classNames = buildClassnames([
|
|
10
|
+
styles.row,
|
|
11
|
+
striped && styles.striped,
|
|
12
|
+
selected && styles.selected,
|
|
13
|
+
themeClasses,
|
|
14
|
+
]);
|
|
15
|
+
return (React__default.createElement("tr", { className: classNames, key: row.id, "aria-rowindex": row.index + 2, "aria-level": enableExpanding ? row.depth + 1 : undefined, style: themeVars }, children));
|
|
16
|
+
};
|
|
6
17
|
|
|
7
18
|
export { Row };
|
|
8
19
|
//# sourceMappingURL=Row.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.js","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.tsx"],"sourcesContent":["import React from 'react';\n\nimport { buildClassnames } from '../../../../../utils';\n\
|
|
1
|
+
{"version":3,"file":"Row.js","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.tsx"],"sourcesContent":["import React from 'react';\n\nimport { buildClassnames } from '../../../../../utils';\nimport { RowTheme } from '../../../types';\nimport { useRowTheme } from './hooks';\n\nimport styles from './Row.module.scss';\n\nexport type RowProps = {\n /**\n * Row information, including id, index, and depth (typically the TanStack table row).\n */\n row: {\n id: string;\n index: number;\n depth: number;\n };\n\n /**\n * Whether rows should be striped or not.\n */\n striped: boolean;\n\n /**\n * Whether the row is selected.\n */\n selected?: boolean;\n\n /**\n * Whether row expanding is enabled.\n */\n enableExpanding: boolean;\n\n /**\n * Optional theming properties for this row.\n */\n rowTheme?: RowTheme;\n\n /**\n * Child elements (table cells).\n */\n children: React.ReactNode;\n};\n\nexport const Row = ({ row, striped, selected, enableExpanding, rowTheme, children }: RowProps) => {\n const { themeVars, themeClasses } = useRowTheme({ rowTheme });\n\n const classNames = buildClassnames([\n styles.row,\n striped && styles.striped,\n selected && styles.selected,\n themeClasses,\n ]);\n\n return (\n <tr\n className={classNames}\n key={row.id}\n // 0-based index + header row.\n aria-rowindex={row.index + 2}\n aria-level={enableExpanding ? row.depth + 1 : undefined}\n style={themeVars}\n >\n {children}\n </tr>\n );\n};"],"names":["React"],"mappings":";;;;;;AA4Ca,MAAA,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAY,KAAI;AAC/F,IAAA,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC;IAE7D,MAAM,UAAU,GAAG,eAAe,CAAC;AACjC,QAAA,MAAM,CAAC,GAAG;QACV,OAAO,IAAI,MAAM,CAAC,OAAO;QACzB,QAAQ,IAAI,MAAM,CAAC,QAAQ;QAC3B,YAAY;AACb,KAAA,CAAC;AAEF,IAAA,QACEA,cACE,CAAA,aAAA,CAAA,IAAA,EAAA,EAAA,SAAS,EAAE,UAAU,EACrB,GAAG,EAAE,GAAG,CAAC,EAAE,EAEI,eAAA,EAAA,GAAG,CAAC,KAAK,GAAG,CAAC,EAChB,YAAA,EAAA,eAAe,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,EACvD,KAAK,EAAE,SAAS,IAEf,QAAQ,CACN;AAET;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ___$insertStyle = require('../../../../../_virtual/____insertStyle.cjs');
|
|
4
|
+
|
|
5
|
+
___$insertStyle("._row_c0qye_1:not(._selected_c0qye_1)._striped_c0qye_1:nth-of-type(odd) td, ._row_c0qye_1:not(._selected_c0qye_1)._striped_c0qye_1:nth-of-type(odd) th {\n background-color: var(--colors-neutral-grey-lightest);\n}\n._row_c0qye_1:not(._selected_c0qye_1):hover td, ._row_c0qye_1:not(._selected_c0qye_1):hover th, ._row_c0qye_1:not(._selected_c0qye_1):hover._striped_c0qye_1 td, ._row_c0qye_1:not(._selected_c0qye_1):hover._striped_c0qye_1 th {\n background-color: #f2f8fc;\n}\n._row_c0qye_1._selected_c0qye_1 td, ._row_c0qye_1._selected_c0qye_1 th {\n background-color: var(--colors-brand-blue-lightest);\n}\n._row_c0qye_1 + ._row_c0qye_1 td, ._row_c0qye_1 + ._row_c0qye_1 th {\n border-top: 1px solid var(--colors-neutral-grey-base);\n}\n\n._accentColor_c0qye_14 > td:first-of-type::before, ._accentColor_c0qye_14 > th:first-of-type::before {\n content: \"\";\n position: absolute;\n top: var(--sizes-none);\n bottom: var(--sizes-none);\n left: var(--sizes-none);\n width: var(--sizes-1);\n background-color: var(--accent-color);\n}");
|
|
6
|
+
var styles = {"row":"_row_c0qye_1","selected":"_selected_c0qye_1","striped":"_striped_c0qye_1","accentColor":"_accentColor_c0qye_14"};
|
|
7
|
+
|
|
8
|
+
module.exports = styles;
|
|
9
|
+
//# sourceMappingURL=Row.module.scss.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Row.module.scss.cjs","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.module.scss"],"sourcesContent":[".row {\n &:not(.selected) {\n // Striping styles\n &.striped:nth-of-type(odd) {\n td, th {\n background-color: var(--colors-neutral-grey-lightest);\n }\n }\n\n // Hover styles\n &:hover, &:hover.striped {\n td, th {\n background-color: #f2f8fc;\n }\n }\n }\n\n // Selected row cell styles\n &.selected {\n td, th {\n background-color: var(--colors-brand-blue-lightest);\n }\n }\n\n // Row borders\n & + .row {\n td, th {\n border-top: 1px solid var(--colors-neutral-grey-base);\n }\n }\n}\n\n.accentColor {\n & > td:first-of-type,\n & > th:first-of-type {\n &::before {\n content: '';\n\n position: absolute;\n top: var(--sizes-none);\n bottom: var(--sizes-none);\n left: var(--sizes-none);\n width: var(--sizes-1);\n\n background-color: var(--accent-color);\n }\n }\n}\n"],"names":[],"mappings":";;;;AAKQ,eAAA,CAAA,mhCAAA;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import insertStyle from '../../../../../_virtual/____insertStyle.js';
|
|
2
|
+
|
|
3
|
+
insertStyle("._row_c0qye_1:not(._selected_c0qye_1)._striped_c0qye_1:nth-of-type(odd) td, ._row_c0qye_1:not(._selected_c0qye_1)._striped_c0qye_1:nth-of-type(odd) th {\n background-color: var(--colors-neutral-grey-lightest);\n}\n._row_c0qye_1:not(._selected_c0qye_1):hover td, ._row_c0qye_1:not(._selected_c0qye_1):hover th, ._row_c0qye_1:not(._selected_c0qye_1):hover._striped_c0qye_1 td, ._row_c0qye_1:not(._selected_c0qye_1):hover._striped_c0qye_1 th {\n background-color: #f2f8fc;\n}\n._row_c0qye_1._selected_c0qye_1 td, ._row_c0qye_1._selected_c0qye_1 th {\n background-color: var(--colors-brand-blue-lightest);\n}\n._row_c0qye_1 + ._row_c0qye_1 td, ._row_c0qye_1 + ._row_c0qye_1 th {\n border-top: 1px solid var(--colors-neutral-grey-base);\n}\n\n._accentColor_c0qye_14 > td:first-of-type::before, ._accentColor_c0qye_14 > th:first-of-type::before {\n content: \"\";\n position: absolute;\n top: var(--sizes-none);\n bottom: var(--sizes-none);\n left: var(--sizes-none);\n width: var(--sizes-1);\n background-color: var(--accent-color);\n}");
|
|
4
|
+
var styles = {"row":"_row_c0qye_1","selected":"_selected_c0qye_1","striped":"_striped_c0qye_1","accentColor":"_accentColor_c0qye_14"};
|
|
5
|
+
|
|
6
|
+
export { styles as default };
|
|
7
|
+
//# sourceMappingURL=Row.module.scss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Row.module.scss.js","sources":["../../../../../../src/components/DataGrid/components/Body/Row/Row.module.scss"],"sourcesContent":[".row {\n &:not(.selected) {\n // Striping styles\n &.striped:nth-of-type(odd) {\n td, th {\n background-color: var(--colors-neutral-grey-lightest);\n }\n }\n\n // Hover styles\n &:hover, &:hover.striped {\n td, th {\n background-color: #f2f8fc;\n }\n }\n }\n\n // Selected row cell styles\n &.selected {\n td, th {\n background-color: var(--colors-brand-blue-lightest);\n }\n }\n\n // Row borders\n & + .row {\n td, th {\n border-top: 1px solid var(--colors-neutral-grey-base);\n }\n }\n}\n\n.accentColor {\n & > td:first-of-type,\n & > th:first-of-type {\n &::before {\n content: '';\n\n position: absolute;\n top: var(--sizes-none);\n bottom: var(--sizes-none);\n left: var(--sizes-none);\n width: var(--sizes-1);\n\n background-color: var(--accent-color);\n }\n }\n}\n"],"names":["___$insertStyle"],"mappings":";;AAKQA,WAAA,CAAA,mhCAAA;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useRowTheme } from './useRowTheme';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var buildClassnames = require('../../../../../../utils/buildClassnames.cjs');
|
|
4
|
+
require('uid/secure');
|
|
5
|
+
var assignCssVars = require('../../../../../../utils/assignCssVars.cjs');
|
|
6
|
+
var Row_module = require('../Row.module.scss.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook to generate theming variables and classes for a given row theme.
|
|
10
|
+
*/
|
|
11
|
+
const useRowTheme = ({ rowTheme }) => {
|
|
12
|
+
if (!(rowTheme === null || rowTheme === undefined ? undefined : rowTheme.accentColor)) {
|
|
13
|
+
return {
|
|
14
|
+
themeVars: {},
|
|
15
|
+
themeClasses: undefined,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const themeClasses = buildClassnames.buildClassnames([(rowTheme === null || rowTheme === undefined ? undefined : rowTheme.accentColor) ? Row_module.accentColor : undefined]);
|
|
19
|
+
return {
|
|
20
|
+
themeVars: assignCssVars.assignCssVars(rowTheme || {}),
|
|
21
|
+
themeClasses,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.useRowTheme = useRowTheme;
|
|
26
|
+
//# sourceMappingURL=useRowTheme.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowTheme.cjs","sources":["../../../../../../../src/components/DataGrid/components/Body/Row/hooks/useRowTheme.ts"],"sourcesContent":["import { RowTheme } from '../../../../types';\nimport { buildClassnames, assignCssVars } from '../../../../../../utils';\n\nimport styles from '../Row.module.scss';\n\ntype UseRowThemeProps = {\n rowTheme?: RowTheme;\n};\n\n/**\n * Hook to generate theming variables and classes for a given row theme.\n */\nexport const useRowTheme = ({ rowTheme }: UseRowThemeProps) => {\n if (!rowTheme?.accentColor) {\n return {\n themeVars: {},\n themeClasses: undefined,\n };\n }\n\n const themeClasses = buildClassnames([rowTheme?.accentColor ? styles.accentColor : undefined]);\n return {\n themeVars: assignCssVars(rowTheme || {}),\n themeClasses,\n };\n};\n"],"names":["buildClassnames","styles","assignCssVars"],"mappings":";;;;;;;AASA;;AAEG;MACU,WAAW,GAAG,CAAC,EAAE,QAAQ,EAAoB,KAAI;IAC5D,IAAI,EAAC,QAAQ,KAAR,IAAA,IAAA,QAAQ,6BAAR,QAAQ,CAAE,WAAW,CAAA,EAAE;QAC1B,OAAO;AACL,YAAA,SAAS,EAAE,EAAE;AACb,YAAA,YAAY,EAAE,SAAS;SACxB;AACF;IAED,MAAM,YAAY,GAAGA,+BAAe,CAAC,CAAC,CAAA,QAAQ,KAAA,IAAA,IAAR,QAAQ,KAAA,SAAA,GAAA,SAAA,GAAR,QAAQ,CAAE,WAAW,IAAGC,UAAM,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC9F,OAAO;AACL,QAAA,SAAS,EAAEC,2BAAa,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,YAAY;KACb;AACH;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RowTheme } from '../../../../types';
|
|
3
|
+
type UseRowThemeProps = {
|
|
4
|
+
rowTheme?: RowTheme;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook to generate theming variables and classes for a given row theme.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useRowTheme: ({ rowTheme }: UseRowThemeProps) => {
|
|
10
|
+
themeVars: {};
|
|
11
|
+
themeClasses: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
themeVars: import("react").CSSProperties;
|
|
14
|
+
themeClasses: string;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { buildClassnames } from '../../../../../../utils/buildClassnames.js';
|
|
2
|
+
import 'uid/secure';
|
|
3
|
+
import { assignCssVars } from '../../../../../../utils/assignCssVars.js';
|
|
4
|
+
import styles from '../Row.module.scss.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook to generate theming variables and classes for a given row theme.
|
|
8
|
+
*/
|
|
9
|
+
const useRowTheme = ({ rowTheme }) => {
|
|
10
|
+
if (!(rowTheme === null || rowTheme === undefined ? undefined : rowTheme.accentColor)) {
|
|
11
|
+
return {
|
|
12
|
+
themeVars: {},
|
|
13
|
+
themeClasses: undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const themeClasses = buildClassnames([(rowTheme === null || rowTheme === undefined ? undefined : rowTheme.accentColor) ? styles.accentColor : undefined]);
|
|
17
|
+
return {
|
|
18
|
+
themeVars: assignCssVars(rowTheme || {}),
|
|
19
|
+
themeClasses,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useRowTheme };
|
|
24
|
+
//# sourceMappingURL=useRowTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowTheme.js","sources":["../../../../../../../src/components/DataGrid/components/Body/Row/hooks/useRowTheme.ts"],"sourcesContent":["import { RowTheme } from '../../../../types';\nimport { buildClassnames, assignCssVars } from '../../../../../../utils';\n\nimport styles from '../Row.module.scss';\n\ntype UseRowThemeProps = {\n rowTheme?: RowTheme;\n};\n\n/**\n * Hook to generate theming variables and classes for a given row theme.\n */\nexport const useRowTheme = ({ rowTheme }: UseRowThemeProps) => {\n if (!rowTheme?.accentColor) {\n return {\n themeVars: {},\n themeClasses: undefined,\n };\n }\n\n const themeClasses = buildClassnames([rowTheme?.accentColor ? styles.accentColor : undefined]);\n return {\n themeVars: assignCssVars(rowTheme || {}),\n themeClasses,\n };\n};\n"],"names":[],"mappings":";;;;;AASA;;AAEG;MACU,WAAW,GAAG,CAAC,EAAE,QAAQ,EAAoB,KAAI;IAC5D,IAAI,EAAC,QAAQ,KAAR,IAAA,IAAA,QAAQ,6BAAR,QAAQ,CAAE,WAAW,CAAA,EAAE;QAC1B,OAAO;AACL,YAAA,SAAS,EAAE,EAAE;AACb,YAAA,YAAY,EAAE,SAAS;SACxB;AACF;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAA,QAAQ,KAAA,IAAA,IAAR,QAAQ,KAAA,SAAA,GAAA,SAAA,GAAR,QAAQ,CAAE,WAAW,IAAG,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC9F,OAAO;AACL,QAAA,SAAS,EAAE,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,YAAY;KACb;AACH;;;;"}
|
|
@@ -5,7 +5,7 @@ export type ColumnAccessor<T> = (row: T) => any;
|
|
|
5
5
|
/**
|
|
6
6
|
* Basic column definition.
|
|
7
7
|
*/
|
|
8
|
-
export type BaseColumnDefinition = {
|
|
8
|
+
export type BaseColumnDefinition<T> = {
|
|
9
9
|
/**
|
|
10
10
|
* Column ID, this must be a string.
|
|
11
11
|
*/
|
|
@@ -60,18 +60,24 @@ export type BaseColumnDefinition = {
|
|
|
60
60
|
* Optional render method used to render a custom column header in place of the column title.
|
|
61
61
|
*/
|
|
62
62
|
renderHeader?: () => ReactElement;
|
|
63
|
+
/**
|
|
64
|
+
* Optional function to generate a `data-testid` for cells in this column.
|
|
65
|
+
* @param row The row data for which the test ID should be generated.
|
|
66
|
+
* @returns The generated test ID string.
|
|
67
|
+
*/
|
|
68
|
+
generateDataTestId?: (row: T) => string;
|
|
63
69
|
};
|
|
64
70
|
/**
|
|
65
71
|
* Column which has an underlying value in the model, can be sorted.
|
|
66
72
|
*/
|
|
67
|
-
export type DataColumnDefinition<T> = BaseColumnDefinition & {
|
|
73
|
+
export type DataColumnDefinition<T> = BaseColumnDefinition<T> & {
|
|
68
74
|
field: DeepKeys<T> | ColumnAccessor<T>;
|
|
69
75
|
renderCell?: (fieldValue: any, row: T) => ReactElement | null | string;
|
|
70
76
|
};
|
|
71
77
|
/**
|
|
72
78
|
* Column which is purely for display, not part of the model, cannot be sorted.
|
|
73
79
|
*/
|
|
74
|
-
export type DisplayColumnDefinition<T> = BaseColumnDefinition & {
|
|
80
|
+
export type DisplayColumnDefinition<T> = BaseColumnDefinition<T> & {
|
|
75
81
|
renderCell: (row: T) => ReactElement | null | string;
|
|
76
82
|
};
|
|
77
83
|
export type ColumnDefinition<T> = DataColumnDefinition<T> | DisplayColumnDefinition<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { AriaAttributes
|
|
1
|
+
import React, { AriaAttributes } from 'react';
|
|
2
2
|
import { SizeScale } from 'Theme/modules/sizes';
|
|
3
3
|
import { BorderMode, ResizeMode, SelectionMode } from './enums';
|
|
4
4
|
import { ColumnDefinition } from './ColumnDefinition';
|
|
@@ -7,11 +7,7 @@ import { PinnedColumnState } from './PinnedColumnState';
|
|
|
7
7
|
import { RowGroupingConfiguration } from './RowGroupingConfiguration';
|
|
8
8
|
import { ColumnWidths } from './ColumnWidths';
|
|
9
9
|
import { EmptyState } from './EmptyState';
|
|
10
|
-
|
|
11
|
-
iconSlot: ReactElement;
|
|
12
|
-
heading: string;
|
|
13
|
-
subHeading?: string;
|
|
14
|
-
};
|
|
10
|
+
import { RowThemeMap } from './RowTheme';
|
|
15
11
|
export type DataGridProps = Pick<AriaAttributes, 'aria-label'> & {
|
|
16
12
|
/** General config */
|
|
17
13
|
/**
|
|
@@ -81,6 +77,10 @@ export type DataGridProps = Pick<AriaAttributes, 'aria-label'> & {
|
|
|
81
77
|
* Getter which returns the ID to use for a row (a string). If one isn't provided, the row index will be used instead.
|
|
82
78
|
*/
|
|
83
79
|
getRowId?: (row: any, index: number, parent?: any) => string;
|
|
80
|
+
/**
|
|
81
|
+
* A map of row ID's to custom theming properties.
|
|
82
|
+
*/
|
|
83
|
+
rowThemes?: RowThemeMap;
|
|
84
84
|
/** Sorting */
|
|
85
85
|
/**
|
|
86
86
|
* The current sort state, including the selected column ID and sort direction.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theming properties for a row within the DataGrid.
|
|
3
|
+
*/
|
|
4
|
+
export type RowTheme = {
|
|
5
|
+
/**
|
|
6
|
+
* The accent color for the row.
|
|
7
|
+
*/
|
|
8
|
+
accentColor?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A map of row ID's to custom theming properties.
|
|
12
|
+
*/
|
|
13
|
+
export type RowThemeMap = Record<string, RowTheme>;
|
|
@@ -6,3 +6,4 @@ export { SortState } from './SortState';
|
|
|
6
6
|
export { PinnedColumnState } from './PinnedColumnState';
|
|
7
7
|
export { RowGroupingConfiguration, ExpandedRows } from './RowGroupingConfiguration';
|
|
8
8
|
export { EmptyState } from './EmptyState';
|
|
9
|
+
export { RowTheme, RowThemeMap } from './RowTheme';
|
|
@@ -73,6 +73,7 @@ class ColumnMapper {
|
|
|
73
73
|
justifyContent: alignmentToFlex((_e = definition.align) !== null && _e !== undefined ? _e : constants.DEFAULT_CELL_ALIGN),
|
|
74
74
|
textAlign: (_f = definition.align) !== null && _f !== undefined ? _f : constants.DEFAULT_CELL_ALIGN,
|
|
75
75
|
getAriaLabel: definition.getAriaLabel,
|
|
76
|
+
generateDataTestId: definition.generateDataTestId,
|
|
76
77
|
},
|
|
77
78
|
};
|
|
78
79
|
validateColumnDefinition(definition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnMapper.cjs","sources":["../../../../src/components/DataGrid/utils/ColumnMapper.ts"],"sourcesContent":["import { ColumnDef, ColumnHelper, createColumnHelper } from '@tanstack/react-table';\nimport { ColumnDefinition, DataColumnDefinition, ColumnAlignment } from '../types/ColumnDefinition';\nimport {\n DEFAULT_CELL_ALIGN,\n DEFAULT_COLUMN_MAXIMUM_WIDTH,\n DEFAULT_COLUMN_MINIMUM_WIDTH,\n DEFAULT_COLUMN_WIDTH,\n} from '../constants';\n\n/**\n * Helper method which checks whether a given column definition is a `DataColumn`.\n * @param column The column definition to check.\n * @returns True if the column definition is a `DataColumn`, false otherwise.\n */\nconst isDataColumn = <T>(column: ColumnDefinition<T>): column is DataColumnDefinition<T> => {\n return (column as DataColumnDefinition<T>).field !== undefined;\n};\n\n/**\n * Maps a column alignment to the equivalent flexbox alignment.\n * @param align The column alingment to map.\n * @returns The flexbox alignment.\n */\nfunction alignmentToFlex(align: ColumnAlignment) {\n switch (align) {\n case 'left':\n return 'flex-start';\n case 'center':\n return 'center';\n case 'right':\n return 'flex-end';\n default:\n return 'flex-start';\n }\n}\n\n/**\n * Validates a column definition, ensuring required properties are defined and values make sense.\n * @param definition The column definition to validate.\n * @throws Error if the column definition is invalid.\n */\nconst validateColumnDefinition = (definition: ColumnDefinition<any>) => {\n if (!definition.id) {\n throw new Error(\"[ColumnMapper] Column definition is missing an 'id' property.\");\n }\n\n if (!isDataColumn(definition)) {\n if (!definition.renderCell) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' is a display column but is missing a 'renderCell' property.`,\n );\n }\n }\n\n if (definition.width && definition.minWidth && definition.width < definition.minWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is smaller than its minimum size of ${definition.minWidth}.`,\n );\n }\n\n if (definition.width && definition.maxWidth && definition.width > definition.maxWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is larger than its maximum size of ${definition.maxWidth}.`,\n );\n }\n};\n\n/**\n * Mapper which validates and converts our ColumnDefinition's to a ColumnDef for use in TanStack Table.\n */\nexport class ColumnMapper {\n private columnHelper: ColumnHelper<any>;\n\n constructor() {\n this.columnHelper = createColumnHelper<any>();\n }\n\n mapColumnDefinition(definition: ColumnDefinition<any>): ColumnDef<any, any> {\n const sharedColumnProps = {\n id: definition.id,\n enableResizing: !!definition.resizeable,\n enableSorting: !!definition.sortable,\n\n header: definition.renderHeader ?? definition.title,\n footer: definition.renderFooter,\n\n size: definition.width ?? DEFAULT_COLUMN_WIDTH,\n maxSize: definition.maxWidth ?? DEFAULT_COLUMN_MAXIMUM_WIDTH,\n minSize: definition.minWidth ?? DEFAULT_COLUMN_MINIMUM_WIDTH,\n\n meta: {\n rowHeader: !!definition.rowHeader,\n // Generate flex and text alignment based off column.align\n justifyContent: alignmentToFlex(definition.align ?? DEFAULT_CELL_ALIGN),\n textAlign: definition.align ?? DEFAULT_CELL_ALIGN,\n getAriaLabel: definition.getAriaLabel,\n },\n };\n\n validateColumnDefinition(definition);\n\n if (isDataColumn(definition)) {\n return this.columnHelper.accessor(definition.field, {\n ...sharedColumnProps,\n // enableSorting: definition.sortable ?? false,\n cell: definition.renderCell\n ? (context) => definition.renderCell!(context.getValue(), context.row.original)\n : (context) => context.getValue(),\n });\n }\n\n return this.columnHelper.display({\n ...sharedColumnProps,\n cell: (context) => definition.renderCell(context.row.original),\n });\n }\n}\n"],"names":["createColumnHelper","DEFAULT_COLUMN_WIDTH","DEFAULT_COLUMN_MAXIMUM_WIDTH","DEFAULT_COLUMN_MINIMUM_WIDTH","DEFAULT_CELL_ALIGN"],"mappings":";;;;;AASA;;;;AAIG;AACH,MAAM,YAAY,GAAG,CAAI,MAA2B,KAAuC;AACzF,IAAA,OAAQ,MAAkC,CAAC,KAAK,KAAK,SAAS;AAChE,CAAC;AAED;;;;AAIG;AACH,SAAS,eAAe,CAAC,KAAsB,EAAA;AAC7C,IAAA,QAAQ,KAAK;AACX,QAAA,KAAK,MAAM;AACT,YAAA,OAAO,YAAY;AACrB,QAAA,KAAK,QAAQ;AACX,YAAA,OAAO,QAAQ;AACjB,QAAA,KAAK,OAAO;AACV,YAAA,OAAO,UAAU;AACnB,QAAA;AACE,YAAA,OAAO,YAAY;AACtB;AACH;AAEA;;;;AAIG;AACH,MAAM,wBAAwB,GAAG,CAAC,UAAiC,KAAI;AACrE,IAAA,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE;AAClB,QAAA,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC;AACjF;AAED,IAAA,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;AAC7B,QAAA,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,CAAA,uBAAA,EAA0B,UAAU,CAAC,EAAE,CAA+D,6DAAA,CAAA,CACvG;AACF;AACF;AAED,IAAA,IAAI,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE;AACrF,QAAA,MAAM,IAAI,KAAK,CACb,CAA0B,uBAAA,EAAA,UAAU,CAAC,E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EAAE,eAAe,CAAC,CAAA,EAAA,GAAA,UAAU,CAAC,KAAK,MAAI,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,EAAA,GAAAC,4BAAkB,CAAC;AACvE,gBAAA,SAAS,EAAE,CAAA,EAAA,GAAA,UAAU,CAAC,KAAK,sCAAIA,4BAAkB;gBACjD,YAAY,EAAE,UAAU,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"ColumnMapper.cjs","sources":["../../../../src/components/DataGrid/utils/ColumnMapper.ts"],"sourcesContent":["import { ColumnDef, ColumnHelper, createColumnHelper } from '@tanstack/react-table';\nimport { ColumnDefinition, DataColumnDefinition, ColumnAlignment } from '../types/ColumnDefinition';\nimport {\n DEFAULT_CELL_ALIGN,\n DEFAULT_COLUMN_MAXIMUM_WIDTH,\n DEFAULT_COLUMN_MINIMUM_WIDTH,\n DEFAULT_COLUMN_WIDTH,\n} from '../constants';\n\n/**\n * Helper method which checks whether a given column definition is a `DataColumn`.\n * @param column The column definition to check.\n * @returns True if the column definition is a `DataColumn`, false otherwise.\n */\nconst isDataColumn = <T>(column: ColumnDefinition<T>): column is DataColumnDefinition<T> => {\n return (column as DataColumnDefinition<T>).field !== undefined;\n};\n\n/**\n * Maps a column alignment to the equivalent flexbox alignment.\n * @param align The column alingment to map.\n * @returns The flexbox alignment.\n */\nfunction alignmentToFlex(align: ColumnAlignment) {\n switch (align) {\n case 'left':\n return 'flex-start';\n case 'center':\n return 'center';\n case 'right':\n return 'flex-end';\n default:\n return 'flex-start';\n }\n}\n\n/**\n * Validates a column definition, ensuring required properties are defined and values make sense.\n * @param definition The column definition to validate.\n * @throws Error if the column definition is invalid.\n */\nconst validateColumnDefinition = (definition: ColumnDefinition<any>) => {\n if (!definition.id) {\n throw new Error(\"[ColumnMapper] Column definition is missing an 'id' property.\");\n }\n\n if (!isDataColumn(definition)) {\n if (!definition.renderCell) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' is a display column but is missing a 'renderCell' property.`,\n );\n }\n }\n\n if (definition.width && definition.minWidth && definition.width < definition.minWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is smaller than its minimum size of ${definition.minWidth}.`,\n );\n }\n\n if (definition.width && definition.maxWidth && definition.width > definition.maxWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is larger than its maximum size of ${definition.maxWidth}.`,\n );\n }\n};\n\n/**\n * Mapper which validates and converts our ColumnDefinition's to a ColumnDef for use in TanStack Table.\n */\nexport class ColumnMapper {\n private columnHelper: ColumnHelper<any>;\n\n constructor() {\n this.columnHelper = createColumnHelper<any>();\n }\n\n mapColumnDefinition(definition: ColumnDefinition<any>): ColumnDef<any, any> {\n const sharedColumnProps = {\n id: definition.id,\n enableResizing: !!definition.resizeable,\n enableSorting: !!definition.sortable,\n\n header: definition.renderHeader ?? definition.title,\n footer: definition.renderFooter,\n\n size: definition.width ?? DEFAULT_COLUMN_WIDTH,\n maxSize: definition.maxWidth ?? DEFAULT_COLUMN_MAXIMUM_WIDTH,\n minSize: definition.minWidth ?? DEFAULT_COLUMN_MINIMUM_WIDTH,\n\n meta: {\n rowHeader: !!definition.rowHeader,\n // Generate flex and text alignment based off column.align\n justifyContent: alignmentToFlex(definition.align ?? DEFAULT_CELL_ALIGN),\n textAlign: definition.align ?? DEFAULT_CELL_ALIGN,\n getAriaLabel: definition.getAriaLabel,\n generateDataTestId: definition.generateDataTestId,\n },\n };\n\n validateColumnDefinition(definition);\n\n if (isDataColumn(definition)) {\n return this.columnHelper.accessor(definition.field, {\n ...sharedColumnProps,\n // enableSorting: definition.sortable ?? false,\n cell: definition.renderCell\n ? (context) => definition.renderCell!(context.getValue(), context.row.original)\n : (context) => context.getValue(),\n });\n }\n\n return this.columnHelper.display({\n ...sharedColumnProps,\n cell: (context) => definition.renderCell(context.row.original),\n });\n }\n}\n"],"names":["createColumnHelper","DEFAULT_COLUMN_WIDTH","DEFAULT_COLUMN_MAXIMUM_WIDTH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U,CAAC,YAAY;gBACrC,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;AAClD,aAAA;SACF;QAED,wBAAwB,CAAC,UAAU,CAAC;AAEpC,QAAA,IAAI,YAAY,CAAC,UAAU,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE;AAClD,gBAAA,GAAG,iBAAiB;;gBAEpB,IAAI,EAAE,UAAU,CAAC;sBACb,CAAC,OAAO,KAAK,UAAU,CAAC,UAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;sBAC5E,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,EAAE;AACpC,aAAA,CAAC;AACH;AAED,QAAA,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;AAC/B,YAAA,GAAG,iBAAiB;AACpB,YAAA,IAAI,EAAE,CAAC,OAAO,KAAK,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC/D,SAAA,CAAC;;AAEL;;;;"}
|
|
@@ -71,6 +71,7 @@ class ColumnMapper {
|
|
|
71
71
|
justifyContent: alignmentToFlex((_e = definition.align) !== null && _e !== undefined ? _e : DEFAULT_CELL_ALIGN),
|
|
72
72
|
textAlign: (_f = definition.align) !== null && _f !== undefined ? _f : DEFAULT_CELL_ALIGN,
|
|
73
73
|
getAriaLabel: definition.getAriaLabel,
|
|
74
|
+
generateDataTestId: definition.generateDataTestId,
|
|
74
75
|
},
|
|
75
76
|
};
|
|
76
77
|
validateColumnDefinition(definition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnMapper.js","sources":["../../../../src/components/DataGrid/utils/ColumnMapper.ts"],"sourcesContent":["import { ColumnDef, ColumnHelper, createColumnHelper } from '@tanstack/react-table';\nimport { ColumnDefinition, DataColumnDefinition, ColumnAlignment } from '../types/ColumnDefinition';\nimport {\n DEFAULT_CELL_ALIGN,\n DEFAULT_COLUMN_MAXIMUM_WIDTH,\n DEFAULT_COLUMN_MINIMUM_WIDTH,\n DEFAULT_COLUMN_WIDTH,\n} from '../constants';\n\n/**\n * Helper method which checks whether a given column definition is a `DataColumn`.\n * @param column The column definition to check.\n * @returns True if the column definition is a `DataColumn`, false otherwise.\n */\nconst isDataColumn = <T>(column: ColumnDefinition<T>): column is DataColumnDefinition<T> => {\n return (column as DataColumnDefinition<T>).field !== undefined;\n};\n\n/**\n * Maps a column alignment to the equivalent flexbox alignment.\n * @param align The column alingment to map.\n * @returns The flexbox alignment.\n */\nfunction alignmentToFlex(align: ColumnAlignment) {\n switch (align) {\n case 'left':\n return 'flex-start';\n case 'center':\n return 'center';\n case 'right':\n return 'flex-end';\n default:\n return 'flex-start';\n }\n}\n\n/**\n * Validates a column definition, ensuring required properties are defined and values make sense.\n * @param definition The column definition to validate.\n * @throws Error if the column definition is invalid.\n */\nconst validateColumnDefinition = (definition: ColumnDefinition<any>) => {\n if (!definition.id) {\n throw new Error(\"[ColumnMapper] Column definition is missing an 'id' property.\");\n }\n\n if (!isDataColumn(definition)) {\n if (!definition.renderCell) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' is a display column but is missing a 'renderCell' property.`,\n );\n }\n }\n\n if (definition.width && definition.minWidth && definition.width < definition.minWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is smaller than its minimum size of ${definition.minWidth}.`,\n );\n }\n\n if (definition.width && definition.maxWidth && definition.width > definition.maxWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is larger than its maximum size of ${definition.maxWidth}.`,\n );\n }\n};\n\n/**\n * Mapper which validates and converts our ColumnDefinition's to a ColumnDef for use in TanStack Table.\n */\nexport class ColumnMapper {\n private columnHelper: ColumnHelper<any>;\n\n constructor() {\n this.columnHelper = createColumnHelper<any>();\n }\n\n mapColumnDefinition(definition: ColumnDefinition<any>): ColumnDef<any, any> {\n const sharedColumnProps = {\n id: definition.id,\n enableResizing: !!definition.resizeable,\n enableSorting: !!definition.sortable,\n\n header: definition.renderHeader ?? definition.title,\n footer: definition.renderFooter,\n\n size: definition.width ?? DEFAULT_COLUMN_WIDTH,\n maxSize: definition.maxWidth ?? DEFAULT_COLUMN_MAXIMUM_WIDTH,\n minSize: definition.minWidth ?? DEFAULT_COLUMN_MINIMUM_WIDTH,\n\n meta: {\n rowHeader: !!definition.rowHeader,\n // Generate flex and text alignment based off column.align\n justifyContent: alignmentToFlex(definition.align ?? DEFAULT_CELL_ALIGN),\n textAlign: definition.align ?? DEFAULT_CELL_ALIGN,\n getAriaLabel: definition.getAriaLabel,\n },\n };\n\n validateColumnDefinition(definition);\n\n if (isDataColumn(definition)) {\n return this.columnHelper.accessor(definition.field, {\n ...sharedColumnProps,\n // enableSorting: definition.sortable ?? false,\n cell: definition.renderCell\n ? (context) => definition.renderCell!(context.getValue(), context.row.original)\n : (context) => context.getValue(),\n });\n }\n\n return this.columnHelper.display({\n ...sharedColumnProps,\n cell: (context) => definition.renderCell(context.row.original),\n });\n }\n}\n"],"names":[],"mappings":";;;AASA;;;;AAIG;AACH,MAAM,YAAY,GAAG,CAAI,MAA2B,KAAuC;AACzF,IAAA,OAAQ,MAAkC,CAAC,KAAK,KAAK,SAAS;AAChE,CAAC;AAED;;;;AAIG;AACH,SAAS,eAAe,CAAC,KAAsB,EAAA;AAC7C,IAAA,QAAQ,KAAK;AACX,QAAA,KAAK,MAAM;AACT,YAAA,OAAO,YAAY;AACrB,QAAA,KAAK,QAAQ;AACX,YAAA,OAAO,QAAQ;AACjB,QAAA,KAAK,OAAO;AACV,YAAA,OAAO,UAAU;AACnB,QAAA;AACE,YAAA,OAAO,YAAY;AACtB;AACH;AAEA;;;;AAIG;AACH,MAAM,wBAAwB,GAAG,CAAC,UAAiC,KAAI;AACrE,IAAA,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE;AAClB,QAAA,MAAM,IAAI,KA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A,KAAA,SAAA,GAAA,EAAA,GAAA,UAAU,CAAC,KAAK;YACnD,MAAM,EAAE,UAAU,CAAC,YAAY;AAE/B,YAAA,IAAI,EAAE,CAAA,EAAA,GAAA,UAAU,CAAC,KAAK,sCAAI,oBAAoB;AAC9C,YAAA,OAAO,EAAE,CAAA,EAAA,GAAA,UAAU,CAAC,QAAQ,sCAAI,4BAA4B;AAC5D,YAAA,OAAO,EAAE,CAAA,EAAA,GAAA,UAAU,CAAC,QAAQ,sCAAI,4BAA4B;AAE5D,YAAA,IAAI,EAAE;AACJ,gBAAA,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS;;gBAEjC,cAAc,EAAE,eAAe,CAAC,CAAA,EAAA,GAAA,UAAU,CAAC,KAAK,MAAI,IAAA,IAAA,EAAA,KAAA,SAAA,GAAA,EAAA,GAAA,kBAAkB,CAAC;AACvE,gBAAA,SAAS,EAAE,CAAA,EAAA,GAAA,UAAU,CAAC,KAAK,sCAAI,kBAAkB;gBACjD,YAAY,EAAE,UAAU,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"ColumnMapper.js","sources":["../../../../src/components/DataGrid/utils/ColumnMapper.ts"],"sourcesContent":["import { ColumnDef, ColumnHelper, createColumnHelper } from '@tanstack/react-table';\nimport { ColumnDefinition, DataColumnDefinition, ColumnAlignment } from '../types/ColumnDefinition';\nimport {\n DEFAULT_CELL_ALIGN,\n DEFAULT_COLUMN_MAXIMUM_WIDTH,\n DEFAULT_COLUMN_MINIMUM_WIDTH,\n DEFAULT_COLUMN_WIDTH,\n} from '../constants';\n\n/**\n * Helper method which checks whether a given column definition is a `DataColumn`.\n * @param column The column definition to check.\n * @returns True if the column definition is a `DataColumn`, false otherwise.\n */\nconst isDataColumn = <T>(column: ColumnDefinition<T>): column is DataColumnDefinition<T> => {\n return (column as DataColumnDefinition<T>).field !== undefined;\n};\n\n/**\n * Maps a column alignment to the equivalent flexbox alignment.\n * @param align The column alingment to map.\n * @returns The flexbox alignment.\n */\nfunction alignmentToFlex(align: ColumnAlignment) {\n switch (align) {\n case 'left':\n return 'flex-start';\n case 'center':\n return 'center';\n case 'right':\n return 'flex-end';\n default:\n return 'flex-start';\n }\n}\n\n/**\n * Validates a column definition, ensuring required properties are defined and values make sense.\n * @param definition The column definition to validate.\n * @throws Error if the column definition is invalid.\n */\nconst validateColumnDefinition = (definition: ColumnDefinition<any>) => {\n if (!definition.id) {\n throw new Error(\"[ColumnMapper] Column definition is missing an 'id' property.\");\n }\n\n if (!isDataColumn(definition)) {\n if (!definition.renderCell) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' is a display column but is missing a 'renderCell' property.`,\n );\n }\n }\n\n if (definition.width && definition.minWidth && definition.width < definition.minWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is smaller than its minimum size of ${definition.minWidth}.`,\n );\n }\n\n if (definition.width && definition.maxWidth && definition.width > definition.maxWidth) {\n throw new Error(\n `[ColumnMapper] Column '${definition.id}' has a size of ${definition.width} which is larger than its maximum size of ${definition.maxWidth}.`,\n );\n }\n};\n\n/**\n * Mapper which validates and converts our ColumnDefinition's to a ColumnDef for use in TanStack Table.\n */\nexport class ColumnMapper {\n private columnHelper: ColumnHelper<any>;\n\n constructor() {\n this.columnHelper = createColumnHelper<any>();\n }\n\n mapColumnDefinition(definition: ColumnDefinition<any>): ColumnDef<any, any> {\n const sharedColumnProps = {\n id: definition.id,\n enableResizing: !!definition.resizeable,\n enableSorting: !!definition.sortable,\n\n header: definition.renderHeader ?? definition.title,\n footer: definition.renderFooter,\n\n size: definition.width ?? DEFAULT_COLUMN_WIDTH,\n maxSize: definition.maxWidth ?? DEFAULT_COLUMN_MAXIMUM_WIDTH,\n minSize: definition.minWidth ?? DEFAULT_COLUMN_MINIMUM_WIDTH,\n\n meta: {\n rowHeader: !!definition.rowHeader,\n // Generate flex and text alignment based off column.align\n justifyContent: alignmentToFlex(definition.align ?? DEFAULT_CELL_ALIGN),\n textAlign: definition.align ?? DEFAULT_CELL_ALIGN,\n getAriaLabel: definition.getAriaLabel,\n generateDataTestId: definition.generateDataTestId,\n },\n };\n\n validateColumnDefinition(definition);\n\n if (isDataColumn(definition)) {\n return this.columnHelper.accessor(definition.field, {\n ...sharedColumnProps,\n // enableSorting: definition.sortable ?? false,\n cell: definition.renderCell\n ? (context) => definition.renderCell!(context.getValue(), context.row.original)\n : (context) => context.getValue(),\n });\n }\n\n return this.columnHelper.display({\n ...sharedColumnProps,\n cell: (context) => definition.renderCell(context.row.original),\n });\n }\n}\n"],"names":[],"mappings":";;;AASA;;;;AAIG;AACH,MAAM,YAAY,GAAG,CAAI,MAA2B,KAAuC;AACzF,IAAA,OAAQ,MAAkC,CAAC,KAAK,KAAK,SAAS;AAChE,CAAC;AAED;;;;AAIG;AACH,SAAS,eAAe,CAAC,KAAsB,EAAA;AAC7C,IAAA,QAAQ,KAAK;AACX,QAAA,KAAK,MAAM;AACT,YAAA,OAAO,YAAY;AACrB,QAAA,KAAK,QAAQ;AACX,YAAA,OAAO,QAAQ;AACjB,QAAA,KAAK,OAAO;AACV,YAAA,OAAO,UAAU;AACnB,QAAA;AACE,YAAA,OAAO,YAAY;AACtB;AACH;AAEA;;;;AAIG;AACH,MAAM,wBAAwB,GAAG,CAAC,UAAiC,KAAI;AACrE,IAAA,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE;AAClB,QAAA,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC;AACjF;AAED,IAAA,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;AAC7B,QAAA,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,CAAA,uBAAA,EAA0B,UAAU,CAAC,EAAE,CAA+D,6DAAA,CAAA,CACvG;AACF;AACF;AAED,IAAA,IAAI,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE;A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