@absreim/react-bootstrap-data-grid-pro 4.5.0 → 4.6.1

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.
@@ -2,3 +2,4 @@ export declare const DEFAULT_COL_WIDTH = 100;
2
2
  export declare const CSS_PREFIX = "rbdg-grid";
3
3
  export declare const DEFAULT_MAX_PAGE_BUTTONS = 5;
4
4
  export declare const DEFAULT_PAGE_SIZES: number[];
5
+ export declare const TOOLBAR_CONTAINER_TEST_ID = "toolbar feature interface content container";
@@ -2,3 +2,4 @@ export const DEFAULT_COL_WIDTH = 100;
2
2
  export const CSS_PREFIX = "rbdg-grid";
3
3
  export const DEFAULT_MAX_PAGE_BUTTONS = 5;
4
4
  export const DEFAULT_PAGE_SIZES = [10, 25, 100];
5
+ export const TOOLBAR_CONTAINER_TEST_ID = "toolbar feature interface content container";
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useMemo, useState } from "react";
3
3
  import Toolbar from "./Toolbar";
4
4
  import classNames from "classnames";
5
+ import { TOOLBAR_CONTAINER_TEST_ID } from "../constants";
5
6
  const ToolbarContainer = ({ interfaceGen, styleModel, }) => {
6
7
  const [option, setOption] = useState(null);
7
8
  const closeUiCallback = useCallback(() => setOption(null), []);
@@ -13,9 +14,15 @@ const ToolbarContainer = ({ interfaceGen, styleModel, }) => {
13
14
  return prev;
14
15
  }, {});
15
16
  }, [interfaces]);
16
- return (_jsxs("div", { className: "vstack", "data-testid": "toolbar container", children: [_jsx(Toolbar, { enabledFeatures: enabledFeatures, option: option, setOption: setOption, toolbarClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.toolbar, activeClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.activeButton, inactiveClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.inactiveButton }), _jsx("div", { className: "position-relative", children: option !== null && (_jsx("div", { "data-testid": "toolbar feature interface content container", className: classNames((styleModel === null || styleModel === void 0 ? void 0 : styleModel.interfaceContainer) || [
17
+ // Z-index of 4 is needed to go on top of Bootstrap pagination links that have
18
+ // a z-index of 3.
19
+ // The z-index of 4 is applied as a style prop here to avoid a breaking
20
+ // change. As part of the next major release, move this setting the common
21
+ // SCSS file.
22
+ return (_jsxs("div", { className: "vstack", "data-testid": "toolbar container", children: [_jsx(Toolbar, { enabledFeatures: enabledFeatures, option: option, setOption: setOption, toolbarClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.toolbar, activeClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.activeButton, inactiveClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.inactiveButton }), _jsx("div", { className: "position-relative", children: option !== null && (_jsx("div", { "data-testid": TOOLBAR_CONTAINER_TEST_ID, style: {
23
+ zIndex: 4,
24
+ }, className: classNames((styleModel === null || styleModel === void 0 ? void 0 : styleModel.interfaceContainer) || [
17
25
  "position-absolute",
18
- "z-1",
19
26
  "bg-body",
20
27
  "border",
21
28
  "shadow",
@@ -1,3 +1,19 @@
1
- import { InterfacePropGenerator, ToolbarInterfaces } from "./internalTypes";
2
- declare const useInterfaces: (gen: InterfacePropGenerator) => (closeCallback: () => void) => ToolbarInterfaces;
1
+ import { FilterState } from "../filtering/internalTypes";
2
+ import { EditableFilterState } from "../filtering/types";
3
+ import { ExportFormStyleModel, FilterInputTableStyleModel } from "../../table";
4
+ import { ExportFnInfo } from "../export/useExportFn";
5
+ import { ToolbarInterfaces } from "./internalTypes";
6
+ export interface InterfacePropParams {
7
+ exportParams?: {
8
+ exportFnInfo: ExportFnInfo;
9
+ styleModel?: ExportFormStyleModel;
10
+ };
11
+ filterParams?: {
12
+ filterState: FilterState;
13
+ setFilterState: (filterState: EditableFilterState) => void;
14
+ caption?: string;
15
+ styleModel?: FilterInputTableStyleModel;
16
+ };
17
+ }
18
+ declare const useInterfaces: (params: InterfacePropParams) => (closeCallback: () => void) => ToolbarInterfaces;
3
19
  export default useInterfaces;
@@ -1,15 +1,19 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback } from "react";
2
3
  import FilterOptionsTable from "../filtering/FilterOptionsTable";
3
- import { useMemo } from "react";
4
4
  import ExportForm from "../export/ExportForm";
5
- const useInterfaces = (gen) => {
6
- return useMemo(() => (closeCallback) => {
7
- const props = gen(closeCallback);
5
+ const useInterfaces = ({ exportParams, filterParams, }) => {
6
+ const generatorFn = useCallback((closeUiCallback) => ({
7
+ exporting: exportParams && Object.assign(Object.assign({}, exportParams), { closeCallback: closeUiCallback }),
8
+ filtering: filterParams && Object.assign(Object.assign({}, filterParams), { closeFormCallback: closeUiCallback }),
9
+ }), [exportParams, filterParams]);
10
+ return useCallback((closeCallback) => {
11
+ const props = generatorFn(closeCallback);
8
12
  const { exporting, filtering } = props;
9
13
  return {
10
14
  filtering: filtering ? (_jsx(FilterOptionsTable, Object.assign({}, filtering))) : undefined,
11
15
  exporting: exporting ? _jsx(ExportForm, Object.assign({}, exporting)) : undefined,
12
16
  };
13
- }, [gen]);
17
+ }, [generatorFn]);
14
18
  };
15
19
  export default useInterfaces;
package/common/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SortModel } from "./sorting/types";
2
+ import { FilterModel } from "./filtering/types";
2
3
  /**
3
4
  * Union of all possible column data types.
4
5
  *
@@ -137,6 +138,19 @@ export interface MainComponentSharedProps {
137
138
  * sorting feature of the component.
138
139
  */
139
140
  sortModel?: SortModel;
141
+ /**
142
+ * Enables exporting of data from the table.
143
+ *
144
+ * @defaultValue `false` - Export button will not be displayed to the user.
145
+ */
146
+ allowExport?: boolean;
147
+ /**
148
+ * The filter model of the table. Passing a truthy value enables the
149
+ * filtering feature of the component.
150
+ *
151
+ * @defaultValue `undefined` - Filtering will not be enabled.
152
+ */
153
+ filterModel?: FilterModel;
140
154
  }
141
155
  /**
142
156
  * {@link RowDef} object that additionally contains the index of the row in the
@@ -5,9 +5,11 @@
5
5
  */
6
6
  export interface FocusCoordinates {
7
7
  /**
8
- * The ARIA row index.
8
+ * An index like ARIA row index, except that it is based on the actual
9
+ * position of the row. When pagination is enabled, this value can differ from
10
+ * the ARIA row index.
9
11
  */
10
- ariaRowIndex: number;
12
+ displayRowIndex: number;
11
13
  /**
12
14
  * The ARIA column index.
13
15
  */
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo, useState, } from "react";
2
2
  const startingCoordinates = {
3
3
  ariaColIndex: 1,
4
- ariaRowIndex: 1,
4
+ displayRowIndex: 1,
5
5
  };
6
6
  const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
7
7
  const [coords, setCoords] = useState(startingCoordinates);
@@ -9,14 +9,14 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
9
9
  // be a prop here to update effective coordinates at the appropriate times.
10
10
  const effectiveCoords = useMemo(() => ({
11
11
  ariaColIndex: Math.min(coords.ariaColIndex, numCols),
12
- ariaRowIndex: Math.min(coords.ariaRowIndex, numRows),
13
- }), [coords.ariaColIndex, coords.ariaRowIndex, numCols, numRows]);
12
+ displayRowIndex: Math.min(coords.displayRowIndex, numRows),
13
+ }), [coords.ariaColIndex, coords.displayRowIndex, numCols, numRows]);
14
14
  const currentCellIsSortableHeader = useMemo(() => {
15
- if (coords.ariaRowIndex !== 1) {
15
+ if (coords.displayRowIndex !== 1) {
16
16
  return false;
17
17
  }
18
18
  return sortableColIndices.includes(coords.ariaColIndex);
19
- }, [coords.ariaColIndex, coords.ariaRowIndex, sortableColIndices]);
19
+ }, [coords.ariaColIndex, coords.displayRowIndex, sortableColIndices]);
20
20
  const gridClickHandler = useCallback((event) => {
21
21
  let cursor = event.target;
22
22
  while (cursor !== event.currentTarget &&
@@ -30,26 +30,26 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
30
30
  }
31
31
  const row = cursor.parentElement;
32
32
  setCoords({
33
- ariaColIndex: Number(cursor.getAttribute("aria-colIndex")),
34
- ariaRowIndex: Number(row.getAttribute("aria-rowIndex")),
33
+ ariaColIndex: Number(cursor.getAttribute("aria-colindex")),
34
+ displayRowIndex: Number(row.getAttribute("display-rowindex")),
35
35
  });
36
36
  }, []);
37
37
  const gridKeydownHandler = useCallback((event) => {
38
38
  switch (event.code) {
39
39
  case "ArrowDown": {
40
- if (effectiveCoords.ariaRowIndex !== numRows) {
40
+ if (effectiveCoords.displayRowIndex !== numRows) {
41
41
  setCoords({
42
42
  ariaColIndex: effectiveCoords.ariaColIndex,
43
- ariaRowIndex: effectiveCoords.ariaRowIndex + 1,
43
+ displayRowIndex: effectiveCoords.displayRowIndex + 1,
44
44
  });
45
45
  }
46
46
  break;
47
47
  }
48
48
  case "ArrowUp": {
49
- if (effectiveCoords.ariaRowIndex !== 1) {
49
+ if (effectiveCoords.displayRowIndex !== 1) {
50
50
  setCoords({
51
51
  ariaColIndex: effectiveCoords.ariaColIndex,
52
- ariaRowIndex: effectiveCoords.ariaRowIndex - 1,
52
+ displayRowIndex: effectiveCoords.displayRowIndex - 1,
53
53
  });
54
54
  }
55
55
  break;
@@ -58,7 +58,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
58
58
  if (effectiveCoords.ariaColIndex !== 1) {
59
59
  setCoords({
60
60
  ariaColIndex: effectiveCoords.ariaColIndex - 1,
61
- ariaRowIndex: effectiveCoords.ariaRowIndex,
61
+ displayRowIndex: effectiveCoords.displayRowIndex,
62
62
  });
63
63
  }
64
64
  break;
@@ -67,7 +67,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
67
67
  if (effectiveCoords.ariaColIndex !== numCols) {
68
68
  setCoords({
69
69
  ariaColIndex: effectiveCoords.ariaColIndex + 1,
70
- ariaRowIndex: effectiveCoords.ariaRowIndex,
70
+ displayRowIndex: effectiveCoords.displayRowIndex,
71
71
  });
72
72
  }
73
73
  break;
@@ -76,13 +76,13 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
76
76
  if (event.ctrlKey || event.metaKey) {
77
77
  setCoords({
78
78
  ariaColIndex: 1,
79
- ariaRowIndex: 1,
79
+ displayRowIndex: 1,
80
80
  });
81
81
  break;
82
82
  }
83
83
  setCoords({
84
84
  ariaColIndex: 1,
85
- ariaRowIndex: effectiveCoords.ariaRowIndex,
85
+ displayRowIndex: effectiveCoords.displayRowIndex,
86
86
  });
87
87
  break;
88
88
  }
@@ -90,13 +90,13 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
90
90
  if (event.ctrlKey || event.metaKey) {
91
91
  setCoords({
92
92
  ariaColIndex: numCols,
93
- ariaRowIndex: numRows,
93
+ displayRowIndex: numRows,
94
94
  });
95
95
  break;
96
96
  }
97
97
  setCoords({
98
98
  ariaColIndex: numCols,
99
- ariaRowIndex: effectiveCoords.ariaRowIndex,
99
+ displayRowIndex: effectiveCoords.displayRowIndex,
100
100
  });
101
101
  break;
102
102
  }
@@ -109,7 +109,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
109
109
  // makes in terms of performance vs relying on the useEffect hook.
110
110
  }, [
111
111
  effectiveCoords.ariaColIndex,
112
- effectiveCoords.ariaRowIndex,
112
+ effectiveCoords.displayRowIndex,
113
113
  numCols,
114
114
  numRows,
115
115
  ]);
@@ -123,7 +123,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
123
123
  if (!gridRef.current.contains(document.activeElement)) {
124
124
  return;
125
125
  }
126
- const cellSelector = `:scope > div > div[aria-rowindex="${effectiveCoords.ariaRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`;
126
+ const cellSelector = `:scope > div > div[display-rowindex="${effectiveCoords.displayRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`;
127
127
  const elToFocus = gridRef.current.querySelector(currentCellIsSortableHeader
128
128
  ? cellSelector + " .rbdg-grid-header-button"
129
129
  : cellSelector);
@@ -132,7 +132,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
132
132
  }
133
133
  }, [
134
134
  effectiveCoords.ariaColIndex,
135
- effectiveCoords.ariaRowIndex,
135
+ effectiveCoords.displayRowIndex,
136
136
  gridRef,
137
137
  currentCellIsSortableHeader,
138
138
  ]);
package/grid/main/Grid.js CHANGED
@@ -10,18 +10,22 @@ import classNames from "classnames";
10
10
  import { CSS_PREFIX } from "../../common/constants";
11
11
  import useGridFocus from "../focus/useGridFocus";
12
12
  import Pagination from "../../common/pagination/Pagination";
13
+ import useExportFn from "../../common/export/useExportFn";
14
+ import useInterfaces from "../../common/toolbar/useInterfaces";
15
+ import ToolbarContainer from "../../common/toolbar/ToolbarContainer";
13
16
  /**
14
17
  * The main component for the grid feature of react-bootstrap-data-grid.
15
18
  *
16
19
  * @public
17
20
  */
18
- const Grid = ({ rows, cols, sortModel, pagination, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, headerCellFocusVariant, bodyCellFocusVariant, }) => {
21
+ const Grid = ({ rows, cols, sortModel, pagination, allowExport, filterModel, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, headerCellFocusVariant, bodyCellFocusVariant, styleOptions, }) => {
19
22
  var _a, _b, _c;
20
- const { displayRows, filteredRows, sortedRowsOutput, currentPageRowsOutput } = useCombinedPipeline({
23
+ const { displayRows, filterState, normalizedTableFilterModel, filteredRows, sortedRowsOutput, currentPageRowsOutput: { paginatedRows, normalizedModel }, } = useCombinedPipeline({
21
24
  rows,
22
25
  cols,
23
26
  sortModel,
24
27
  pagination,
28
+ filterModel,
25
29
  });
26
30
  const colNameToWidth = useColNameToWidth(cols);
27
31
  const augFormattedRows = useAugFormattedRows(colNameToWidth, displayRows);
@@ -87,7 +91,7 @@ const Grid = ({ rows, cols, sortModel, pagination, width, height, variant, strip
87
91
  "rbdg-grid-borderless": borders === "none",
88
92
  "rbdg-grid-sm": !!small,
89
93
  "rbdg-grid-group-divider": !!divider,
90
- }, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, "data-testid": "rbdg-grid", children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.ariaRowIndex === 1
94
+ }, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, "data-testid": "rbdg-grid", children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.displayRowIndex === 1
91
95
  ? effectiveCoords.ariaColIndex
92
96
  : null, cellFocusVariant: headerCellFocusVariant, sortInfo: sortedRowsOutput }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
93
97
  const getPagination = (pagination) => {
@@ -96,8 +100,26 @@ const Grid = ({ rows, cols, sortModel, pagination, width, height, variant, strip
96
100
  "d-flex",
97
101
  `rbdg-justify-content-${((_a = pagination.styleOptions) === null || _a === void 0 ? void 0 : _a.horizontalAlignment) || "right"}`,
98
102
  `gap-${((_b = pagination.styleOptions) === null || _b === void 0 ? void 0 : _b.paginationComponentSpacing) === undefined ? 2 : (_c = pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.paginationComponentSpacing}`,
99
- ], normalizedModel: currentPageRowsOutput.normalizedModel, prePagingNumRows: rows.length, sizeSelectAfterPageSelect: (_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.sizeSelectAfterPageSelect }));
103
+ ], normalizedModel: normalizedModel, prePagingNumRows: rows.length, sizeSelectAfterPageSelect: (_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.sizeSelectAfterPageSelect }));
100
104
  };
101
- return pagination ? (_jsx("div", { style: { width: widthProperty, height: heightProperties.containerDiv }, className: classNames("d-flex", "flex-column", `gap-${((_a = pagination.styleOptions) === null || _a === void 0 ? void 0 : _a.mainComponentSpacing) === undefined ? 2 : (_b = pagination.styleOptions) === null || _b === void 0 ? void 0 : _b.mainComponentSpacing}`), "data-testid": "rbdg-top-level-grid-container", children: ((_c = pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.aboveMainComponent) ? (_jsxs(_Fragment, { children: [getPagination(pagination), mainGridComponent] })) : (_jsxs(_Fragment, { children: [mainGridComponent, getPagination(pagination)] })) })) : (_jsx(_Fragment, { children: mainGridComponent }));
105
+ const exportFnInfo = useExportFn({
106
+ rows,
107
+ cols,
108
+ filteredRows: filterModel && filteredRows,
109
+ currentPageRows: pagination && paginatedRows,
110
+ });
111
+ const toolbarInterfaces = useInterfaces({
112
+ exportParams: allowExport ? { exportFnInfo } : undefined,
113
+ filterParams: filterModel
114
+ ? {
115
+ filterState: filterState,
116
+ setFilterState: normalizedTableFilterModel.setTableFilterState,
117
+ caption: filterModel.filterTableCaption,
118
+ }
119
+ : undefined,
120
+ });
121
+ const showToolbar = allowExport || filterModel;
122
+ const mainSpacingSetting = (_a = styleOptions === null || styleOptions === void 0 ? void 0 : styleOptions.mainComponentSpacing) !== null && _a !== void 0 ? _a : (_b = pagination === null || pagination === void 0 ? void 0 : pagination.styleOptions) === null || _b === void 0 ? void 0 : _b.mainComponentSpacing;
123
+ return pagination || showToolbar ? (_jsxs("div", { style: { width: widthProperty, height: heightProperties.containerDiv }, className: classNames("d-flex", "flex-column", `gap-${mainSpacingSetting === undefined ? 2 : mainSpacingSetting}`), "data-testid": "rbdg-top-level-grid-container", children: [showToolbar && _jsx(ToolbarContainer, { interfaceGen: toolbarInterfaces }), pagination ? (_jsx(_Fragment, { children: ((_c = pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.aboveMainComponent) ? (_jsxs(_Fragment, { children: [getPagination(pagination), mainGridComponent] })) : (_jsxs(_Fragment, { children: [mainGridComponent, getPagination(pagination)] })) })) : (_jsx(_Fragment, { children: mainGridComponent }))] })) : (_jsx(_Fragment, { children: mainGridComponent }));
102
124
  };
103
125
  export default Grid;
@@ -4,18 +4,19 @@ import classNames from "classnames";
4
4
  import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
5
5
  import { GRID_BODY_DATA_TEST_ID } from "../constants";
6
6
  const GridBody = ({ augFormattedRows, cols, rowVariant, cellVariant, focusCoords, cellFocusVariant, }) => {
7
- return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row, rowDisplayIndex) => {
7
+ return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row, displayRowArrayIndex) => {
8
8
  const ariaRowIndex = row.prePaginationIndex + 2;
9
- return (_jsx("div", { role: "row", "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
10
- rowVariant(row, rowDisplayIndex) &&
11
- `${CSS_PREFIX}-${rowVariant(row, rowDisplayIndex)}`), children: row.contents.map(({ formattedValue, width }, index) => {
9
+ const displayRowIndex = displayRowArrayIndex + 2;
10
+ return (_jsx("div", { role: "row", "display-rowindex": displayRowIndex, "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
11
+ rowVariant(row, displayRowArrayIndex) &&
12
+ `${CSS_PREFIX}-${rowVariant(row, displayRowArrayIndex)}`), children: row.contents.map(({ formattedValue, width }, index) => {
12
13
  const ariaColIndex = index + 1;
13
14
  const isFocused = focusCoords.ariaColIndex === ariaColIndex &&
14
- focusCoords.ariaRowIndex === ariaRowIndex;
15
+ focusCoords.displayRowIndex === displayRowIndex;
15
16
  const cellVariantVal = cellVariant &&
16
- cellVariant(row.contents[index], row, index, rowDisplayIndex);
17
+ cellVariant(row.contents[index], row, index, displayRowArrayIndex);
17
18
  const cellFocusVariantVal = cellFocusVariant &&
18
- cellFocusVariant(row.contents[index], row, index, rowDisplayIndex);
19
+ cellFocusVariant(row.contents[index], row, index, displayRowArrayIndex);
19
20
  return (_jsx("div", { tabIndex: isFocused ? 0 : -1, style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariantVal && `${CSS_PREFIX}-${cellVariantVal}`, cellFocusVariantVal && `focus-ring-${cellFocusVariantVal}`, {
20
21
  "z-2": isFocused,
21
22
  "rbdg-focusable-cell": isFocused,
@@ -24,7 +24,7 @@ const GridHeader = ({ cols, vertScrollable, rowVariant, cellVariant, focusColInd
24
24
  }
25
25
  setSortColDef(null);
26
26
  };
27
- return (_jsx("div", { "data-testid": GRID_HEADER_DATA_TEST_ID, role: "rowgroup", className: classNames(vertScrollable ? ["position-sticky", "z-1", "top-0"] : []), children: _jsx("div", { role: "row", className: classNames("d-flex", "flex-row", rowVariant && `${CSS_PREFIX}-${rowVariant}`), "aria-rowindex": 1, children: cols.map((col, index) => {
27
+ return (_jsx("div", { "data-testid": GRID_HEADER_DATA_TEST_ID, role: "rowgroup", className: classNames(vertScrollable ? ["position-sticky", "z-1", "top-0"] : []), children: _jsx("div", { role: "row", className: classNames("d-flex", "flex-row", rowVariant && `${CSS_PREFIX}-${rowVariant}`), "display-rowindex": 1, "aria-rowindex": 1, children: cols.map((col, index) => {
28
28
  const ariaColIndex = index + 1;
29
29
  const isFocused = focusColIndex === ariaColIndex;
30
30
  const cellVariantVal = cellVariant && cellVariant(col, index);
@@ -56,62 +56,98 @@ export interface GridSpecificProps {
56
56
  width?: GridWidthSetting;
57
57
  /**
58
58
  * The grid-wide color variant
59
+ *
60
+ * @defaultValue `undefined` - no variant will be specified.
59
61
  */
60
62
  variant?: string;
61
63
  /**
62
64
  * The stripe setting of the grid
65
+ *
66
+ * @defaultValue `undefined` - no stripes will be present.
63
67
  */
64
68
  stripes?: GridStripeSetting;
65
69
  /**
66
70
  * Toggles hover styles for the grid
71
+ *
72
+ * @defaultValue `undefined` - no hover styles will be active.
67
73
  */
68
74
  hover?: boolean;
69
75
  /**
70
76
  * The border setting of the grid
77
+ *
78
+ * @defaultValue `undefined` - no borders will be shown.
71
79
  */
72
80
  borders?: GridBorderSetting;
73
81
  /**
74
82
  * The border color variant of the grid
83
+ *
84
+ * @defaultValue `undefined` - the default Bootstrap border color will be
85
+ * used.
75
86
  */
76
87
  borderVariant?: string;
77
88
  /**
78
89
  * Toggles a denser grid style
90
+ *
91
+ * @defaultValue `false` - the grid will have the default density of cells
92
+ * that are used in Bootstrap tables.
79
93
  */
80
94
  small?: boolean;
81
95
  /**
82
96
  * Toggles a horizontal divider between the grid header and body
97
+ *
98
+ * @defaultValue `false` - no divider will be shown.
83
99
  */
84
100
  divider?: boolean;
85
101
  /**
86
102
  * Sets the color variant of the header row
103
+ *
104
+ * @defaultValue `undefined` - no variant will be specified.
87
105
  */
88
106
  headerRowVariant?: string;
89
107
  /**
90
108
  * Function to set the color variant of header cells. Overrides the row-wide
91
109
  * setting when this function returns a non-null value.
110
+ *
111
+ * @defaultValue `undefined` - no variant will be specified.
92
112
  */
93
113
  headerCellVariant?: HeaderCellVariantFn;
94
114
  /**
95
115
  * Function to set the color variant of body rows
116
+ *
117
+ * @defaultValue `undefined` - no variant will be specified.
96
118
  */
97
119
  bodyRowVariant?: (row: FormattedRow, displayIndex: number) => string | null;
98
120
  /**
99
121
  * Function to set the color variant of body cells on a per-cell basis.
100
122
  * Overrides the row-wide setting when this function returns a non-null value.
123
+ *
124
+ * @defaultValue `undefined` - no variant will be specified.
101
125
  */
102
126
  bodyCellVariant?: BodyCellVariantFn;
103
127
  /**
104
128
  * Function to set the color variant of header cell focus rings
129
+ *
130
+ * @defaultValue `undefined` - no variant will be specified.
105
131
  */
106
132
  headerCellFocusVariant?: HeaderCellVariantFn;
107
133
  /**
108
134
  * Function to set the color variant of body cell focus rings
135
+ *
136
+ * @defaultValue `undefined` - no variant will be specified.
109
137
  */
110
138
  bodyCellFocusVariant?: BodyCellVariantFn;
111
139
  /**
112
140
  * Enables and configures pagination for the grid
141
+ *
142
+ * @defaultValue `undefined` - pagination will be disabled.
113
143
  */
114
144
  pagination?: GridPaginationModel;
145
+ /**
146
+ * Configures preset styles.
147
+ *
148
+ * @defaultValue `undefined` - default values for preset styles will be used.
149
+ */
150
+ styleOptions?: StyleOptions;
115
151
  }
116
152
  /**
117
153
  * The type of the prop to set grid height behavior
@@ -145,3 +181,21 @@ export type GridStripeSetting = "rows" | "columns" | "none";
145
181
  * @public
146
182
  */
147
183
  export type GridBorderSetting = "horizontal" | "full" | "none";
184
+ /**
185
+ * Object that contains preset style options for the {@link Grid} component.
186
+ *
187
+ * @public
188
+ */
189
+ export interface StyleOptions {
190
+ /**
191
+ * Sets the amount of vertical spacing between the main grid component, the
192
+ * toolbar, and pagination UI components. The number supplied to this
193
+ * property will be used for the
194
+ * {@link https://getbootstrap.com/docs/5.3/utilities/spacing/#gap | Bootstrap gap utility}.
195
+ * Valid values depend on Bootstrap `$spacers` Sass map. Be default, the valid
196
+ * values range from 0 to 5.
197
+ *
198
+ * @defaultValue `2`- the gap-2 Bootstrap utility class will be applied.
199
+ */
200
+ mainComponentSpacing?: number;
201
+ }
@@ -33,14 +33,13 @@ export interface PaginationStyleOptions {
33
33
  */
34
34
  horizontalAlignment?: "left" | "center" | "right";
35
35
  /**
36
- * Sets the amount of vertical spacing between the main grid or table
37
- * component and the pagination UI components. The number supplied to this
38
- * property will be used for the
39
- * {@link https://getbootstrap.com/docs/5.3/utilities/spacing/#gap | Bootstrap gap utility}.
40
- * Valid values depend on Bootstrap `$spacers` Sass map. Be default, the valid
41
- * values range from 0 to 5.
36
+ * Copy of the property of the same name in the {@link StyleOptions}
37
+ * interface. The value of the {@link StyleOptions} property takes
38
+ * precedence. This value is only used if the other value doesn't exist.
42
39
  *
43
- * @defaultValue `2`- the gap-2 Bootstrap utility class will be applied.
40
+ * @deprecated Use the property in the {@link StyleOptions} interface instead.
41
+ * The property is only kept around for backwards compatibility and may be
42
+ * removed in the next major release.
44
43
  */
45
44
  mainComponentSpacing?: number;
46
45
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@absreim/react-bootstrap-data-grid-pro",
3
3
  "description": "Pro Version of data grid UI component for use with web apps using React and Bootstrap",
4
- "version": "4.5.0",
4
+ "version": "4.6.1",
5
5
  "license": "Commercial. See LICENSE file.",
6
6
  "author": "Brook Li",
7
7
  "homepage": "https://react-bootstrap-data-grid.vercel.app/",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "classnames": "^2.5.1",
19
19
  "dayjs": "^1.11.13",
20
- "papaparse": "^5.5.3"
20
+ "papaparse": "^5.7.1"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": "^19",
@@ -2,8 +2,8 @@ import { FC, ReactNode } from "react";
2
2
  import { UseCombinedPipelineHook } from "../common/pipeline/useCombinedPipeline";
3
3
  import { UseGridSelectionFnsHook } from "../common/pipeline/useGridSelectionFns";
4
4
  import { BaseTableProps } from "./internalTypes";
5
- export interface InternalGridProps {
6
- gridProps: BaseTableProps;
5
+ export interface InternalTableProps {
6
+ tableProps: BaseTableProps;
7
7
  hooks: {
8
8
  selectFns: UseGridSelectionFnsHook;
9
9
  pipelineOutput: UseCombinedPipelineHook;
@@ -17,5 +17,5 @@ export interface InternalGridProps {
17
17
  headerRow?: string[];
18
18
  };
19
19
  }
20
- declare const InternalTable: FC<InternalGridProps>;
20
+ declare const InternalTable: FC<InternalTableProps>;
21
21
  export default InternalTable;
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo } from "react";
4
3
  import SelectAllHeaderCell from "./selection/SelectAllHeaderCell";
5
4
  import Pagination from "../common/pagination/Pagination";
6
5
  import classNames from "classnames";
@@ -8,7 +7,7 @@ import useInterfaces from "../common/toolbar/useInterfaces";
8
7
  import ToolbarContainer from "../common/toolbar/ToolbarContainer";
9
8
  import useExportFn from "../common/export/useExportFn";
10
9
  import getWidthStyle from "../common/util/getWidthStyle";
11
- const InternalTable = ({ gridProps: { rows, cols, pagination, filterModel, selectModel, editModel, caption, styleModel, displayMode, allowExport, }, hooks: { pipelineOutput, selectFns }, slots: { colHeaderCells, bodyRows, prefixHeader }, classes, }) => {
10
+ const InternalTable = ({ tableProps: { rows, cols, pagination, filterModel, selectModel, editModel, caption, styleModel, displayMode, allowExport, }, hooks: { pipelineOutput, selectFns }, slots: { colHeaderCells, bodyRows, prefixHeader }, classes, }) => {
12
11
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
13
12
  const { normalizedTableFilterModel, filteredRows, filterState, sortedRowsOutput: { sortedRows }, currentPageRowsOutput: { paginatedRows, normalizedModel }, showSelectCol, } = pipelineOutput;
14
13
  const exportFnInfo = useExportFn({
@@ -18,35 +17,22 @@ const InternalTable = ({ gridProps: { rows, cols, pagination, filterModel, selec
18
17
  currentPageRows: pagination && paginatedRows,
19
18
  });
20
19
  const showToolbar = filterModel || allowExport;
21
- const toolbarPropGen = useMemo(() => (closeUiCallback) => {
22
- return {
23
- filtering: filterState && filterModel && normalizedTableFilterModel
24
- ? {
25
- filterState: filterState,
26
- setFilterState: normalizedTableFilterModel.setTableFilterState,
27
- caption: filterModel.filterTableCaption,
28
- styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
29
- closeFormCallback: closeUiCallback,
30
- }
31
- : undefined,
32
- exporting: allowExport
33
- ? {
34
- exportFnInfo,
35
- styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
36
- closeCallback: closeUiCallback,
37
- }
38
- : undefined,
39
- };
40
- }, [
41
- allowExport,
42
- exportFnInfo,
43
- filterModel,
44
- filterState,
45
- normalizedTableFilterModel,
46
- styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
47
- styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
48
- ]);
49
- const toolbarInterfaces = useInterfaces(toolbarPropGen);
20
+ const toolbarInterfaces = useInterfaces({
21
+ exportParams: allowExport
22
+ ? {
23
+ exportFnInfo,
24
+ styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
25
+ }
26
+ : undefined,
27
+ filterParams: filterModel
28
+ ? {
29
+ filterState: filterState,
30
+ setFilterState: normalizedTableFilterModel.setTableFilterState,
31
+ caption: filterModel.filterTableCaption,
32
+ styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
33
+ }
34
+ : undefined,
35
+ });
50
36
  const { rowsAreSelectable, selectionInfo, selectAllOnClick } = selectFns;
51
37
  const mainTable = (_jsxs("table", { className: classNames({
52
38
  "table-hover": rowsAreSelectable,
package/table/Table.js CHANGED
@@ -42,7 +42,7 @@ const Table = (props) => {
42
42
  styleModel.mainTableStyleModel.theadTh(index), width: width }, name));
43
43
  });
44
44
  const bodyRows = (_jsx(BodyRows, { augFormattedRows: augFormattedRows, gridSelectionFns: gridSelectionFns, selectModel: selectModel, combinedPipelineOutput: combinedPipelineOutput, editModel: editModel, getInputStrSubmitCallback: getInputStrSubmitCallback, tableStyleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.mainTableStyleModel }));
45
- return (_jsx(InternalTable, { gridProps: props, hooks: {
45
+ return (_jsx(InternalTable, { tableProps: props, hooks: {
46
46
  pipelineOutput: combinedPipelineOutput,
47
47
  selectFns: gridSelectionFns,
48
48
  }, slots: { colHeaderCells, bodyRows } }));
package/table/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EditModel, FilterModel, MainComponentSharedProps, PaginationModel, SelectModel, StyleModel } from "../common";
1
+ import { EditModel, MainComponentSharedProps, PaginationModel, SelectModel, StyleModel } from "../common";
2
2
  /**
3
3
  * Available options for the displayMode prop of {@link TableSpecificProps}.
4
4
  *
@@ -12,11 +12,6 @@ export type DisplayMode = "table" | "block";
12
12
  * @public
13
13
  */
14
14
  export interface TableSpecificProps {
15
- /**
16
- * The filter model of the table. Passing a truthy value enables the
17
- * filtering feature of the component.
18
- */
19
- filterModel?: FilterModel;
20
15
  /**
21
16
  * The select model of the table. Passing a truthy value enables the
22
17
  * selection feature of the component.
@@ -33,10 +28,6 @@ export interface TableSpecificProps {
33
28
  * table.
34
29
  */
35
30
  styleModel?: StyleModel;
36
- /**
37
- * Enables exporting of data from the table.
38
- */
39
- allowExport?: boolean;
40
31
  /**
41
32
  * Sets a caption for the table
42
33
  */
@@ -122,7 +122,7 @@ const TablePro = (props) => {
122
122
  ]);
123
123
  const bodyRows = (_jsx(BodyRows, { augFormattedRows: augFormattedRows, gridSelectionFns: gridSelectionFns, selectModel: selectModel, combinedPipelineOutput: combinedPipelineOutput, editModel: editModel, getInputStrSubmitCallback: getInputStrSubmitCallback, renderPrefixCells: renderPrefixCells, additionalColIndexOffset: reorder ? 1 : 0, additionalRowStyles: additionalBodyRowStyles, tableStyleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.mainTableStyleModel }));
124
124
  const prefixHeader = reorder ? _jsx(ReorderHeaderCell, {}) : null;
125
- return (_jsx(InternalTable, { gridProps: props, hooks: {
125
+ return (_jsx(InternalTable, { tableProps: props, hooks: {
126
126
  pipelineOutput: combinedPipelineOutput,
127
127
  selectFns: gridSelectionFns,
128
128
  }, slots: { colHeaderCells, bodyRows, prefixHeader }, classes: {