@absreim/react-bootstrap-data-grid 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 var DEFAULT_COL_WIDTH = 100;
2
2
  export var CSS_PREFIX = "rbdg-grid";
3
3
  export var DEFAULT_MAX_PAGE_BUTTONS = 5;
4
4
  export var DEFAULT_PAGE_SIZES = [10, 25, 100];
5
+ export var 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
  var ToolbarContainer = function (_a) {
6
7
  var interfaceGen = _a.interfaceGen, styleModel = _a.styleModel;
7
8
  var _b = useState(null), option = _b[0], setOption = _b[1];
@@ -14,9 +15,15 @@ var ToolbarContainer = function (_a) {
14
15
  return prev;
15
16
  }, {});
16
17
  }, [interfaces]);
17
- 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) || [
18
+ // Z-index of 4 is needed to go on top of Bootstrap pagination links that have
19
+ // a z-index of 3.
20
+ // The z-index of 4 is applied as a style prop here to avoid a breaking
21
+ // change. As part of the next major release, move this setting the common
22
+ // SCSS file.
23
+ 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: {
24
+ zIndex: 4,
25
+ }, className: classNames((styleModel === null || styleModel === void 0 ? void 0 : styleModel.interfaceContainer) || [
18
26
  "position-absolute",
19
- "z-1",
20
27
  "bg-body",
21
28
  "border",
22
29
  "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;
@@ -10,17 +10,22 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useCallback } from "react";
13
14
  import FilterOptionsTable from "../filtering/FilterOptionsTable";
14
- import { useMemo } from "react";
15
15
  import ExportForm from "../export/ExportForm";
16
- var useInterfaces = function (gen) {
17
- return useMemo(function () { return function (closeCallback) {
18
- var props = gen(closeCallback);
16
+ var useInterfaces = function (_a) {
17
+ var exportParams = _a.exportParams, filterParams = _a.filterParams;
18
+ var generatorFn = useCallback(function (closeUiCallback) { return ({
19
+ exporting: exportParams && __assign(__assign({}, exportParams), { closeCallback: closeUiCallback }),
20
+ filtering: filterParams && __assign(__assign({}, filterParams), { closeFormCallback: closeUiCallback }),
21
+ }); }, [exportParams, filterParams]);
22
+ return useCallback(function (closeCallback) {
23
+ var props = generatorFn(closeCallback);
19
24
  var exporting = props.exporting, filtering = props.filtering;
20
25
  return {
21
26
  filtering: filtering ? (_jsx(FilterOptionsTable, __assign({}, filtering))) : undefined,
22
27
  exporting: exporting ? _jsx(ExportForm, __assign({}, exporting)) : undefined,
23
28
  };
24
- }; }, [gen]);
29
+ }, [generatorFn]);
25
30
  };
26
31
  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
  var startingCoordinates = {
3
3
  ariaColIndex: 1,
4
- ariaRowIndex: 1,
4
+ displayRowIndex: 1,
5
5
  };
6
6
  var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
7
7
  var _a = useState(startingCoordinates), coords = _a[0], setCoords = _a[1];
@@ -9,14 +9,14 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
9
9
  // be a prop here to update effective coordinates at the appropriate times.
10
10
  var effectiveCoords = useMemo(function () { return ({
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
  var currentCellIsSortableHeader = useMemo(function () {
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
  var gridClickHandler = useCallback(function (event) {
21
21
  var cursor = event.target;
22
22
  while (cursor !== event.currentTarget &&
@@ -30,26 +30,26 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
30
30
  }
31
31
  var 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
  var gridKeydownHandler = useCallback(function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
123
123
  if (!gridRef.current.contains(document.activeElement)) {
124
124
  return;
125
125
  }
126
- var cellSelector = ":scope > div > div[aria-rowindex=\"".concat(effectiveCoords.ariaRowIndex, "\"] > div[aria-colindex=\"").concat(effectiveCoords.ariaColIndex, "\"]");
126
+ var cellSelector = ":scope > div > div[display-rowindex=\"".concat(effectiveCoords.displayRowIndex, "\"] > div[aria-colindex=\"").concat(effectiveCoords.ariaColIndex, "\"]");
127
127
  var elToFocus = gridRef.current.querySelector(currentCellIsSortableHeader
128
128
  ? cellSelector + " .rbdg-grid-header-button"
129
129
  : cellSelector);
@@ -132,7 +132,7 @@ var useGridFocus = function (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,6 +10,9 @@ 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
  *
@@ -17,13 +20,14 @@ import Pagination from "../../common/pagination/Pagination";
17
20
  */
18
21
  var Grid = function (_a) {
19
22
  var _b, _c, _d;
20
- var rows = _a.rows, cols = _a.cols, sortModel = _a.sortModel, pagination = _a.pagination, width = _a.width, height = _a.height, variant = _a.variant, stripes = _a.stripes, hover = _a.hover, borders = _a.borders, small = _a.small, divider = _a.divider, borderVariant = _a.borderVariant, headerCellVariant = _a.headerCellVariant, headerRowVariant = _a.headerRowVariant, bodyCellVariant = _a.bodyCellVariant, bodyRowVariant = _a.bodyRowVariant, headerCellFocusVariant = _a.headerCellFocusVariant, bodyCellFocusVariant = _a.bodyCellFocusVariant;
23
+ var rows = _a.rows, cols = _a.cols, sortModel = _a.sortModel, pagination = _a.pagination, allowExport = _a.allowExport, filterModel = _a.filterModel, width = _a.width, height = _a.height, variant = _a.variant, stripes = _a.stripes, hover = _a.hover, borders = _a.borders, small = _a.small, divider = _a.divider, borderVariant = _a.borderVariant, headerCellVariant = _a.headerCellVariant, headerRowVariant = _a.headerRowVariant, bodyCellVariant = _a.bodyCellVariant, bodyRowVariant = _a.bodyRowVariant, headerCellFocusVariant = _a.headerCellFocusVariant, bodyCellFocusVariant = _a.bodyCellFocusVariant, styleOptions = _a.styleOptions;
21
24
  var _e = useCombinedPipeline({
22
25
  rows: rows,
23
26
  cols: cols,
24
27
  sortModel: sortModel,
25
28
  pagination: pagination,
26
- }), displayRows = _e.displayRows, filteredRows = _e.filteredRows, sortedRowsOutput = _e.sortedRowsOutput, currentPageRowsOutput = _e.currentPageRowsOutput;
29
+ filterModel: filterModel,
30
+ }), displayRows = _e.displayRows, filterState = _e.filterState, normalizedTableFilterModel = _e.normalizedTableFilterModel, filteredRows = _e.filteredRows, sortedRowsOutput = _e.sortedRowsOutput, _f = _e.currentPageRowsOutput, paginatedRows = _f.paginatedRows, normalizedModel = _f.normalizedModel;
27
31
  var colNameToWidth = useColNameToWidth(cols);
28
32
  var augFormattedRows = useAugFormattedRows(colNameToWidth, displayRows);
29
33
  function getWidthProperty(width) {
@@ -62,7 +66,7 @@ var Grid = function (_a) {
62
66
  .map(function (_, index) { return index + 1; })
63
67
  .filter(function (ariaColIndex) { return cols[ariaColIndex - 1].sortable; })
64
68
  : [];
65
- var _f = useGridFocus(gridRef, displayRows.length + 1, cols.length, sortableColIndices), effectiveCoords = _f.effectiveCoords, gridClickHandler = _f.gridClickHandler, gridKeydownHandler = _f.gridKeydownHandler;
69
+ var _g = useGridFocus(gridRef, displayRows.length + 1, cols.length, sortableColIndices), effectiveCoords = _g.effectiveCoords, gridClickHandler = _g.gridClickHandler, gridKeydownHandler = _g.gridKeydownHandler;
66
70
  var onCopy = useCallback(function (event) {
67
71
  var _a;
68
72
  if (!((_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement))) {
@@ -88,7 +92,7 @@ var Grid = function (_a) {
88
92
  "rbdg-grid-borderless": borders === "none",
89
93
  "rbdg-grid-sm": !!small,
90
94
  "rbdg-grid-group-divider": !!divider,
91
- }, "rbdg-grid", variant && "".concat(CSS_PREFIX, "-").concat(variant), borderVariant && "border-".concat(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
95
+ }, "rbdg-grid", variant && "".concat(CSS_PREFIX, "-").concat(variant), borderVariant && "border-".concat(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
92
96
  ? effectiveCoords.ariaColIndex
93
97
  : null, cellFocusVariant: headerCellFocusVariant, sortInfo: sortedRowsOutput }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
94
98
  var getPagination = function (pagination) {
@@ -97,8 +101,26 @@ var Grid = function (_a) {
97
101
  "d-flex",
98
102
  "rbdg-justify-content-".concat(((_a = pagination.styleOptions) === null || _a === void 0 ? void 0 : _a.horizontalAlignment) || "right"),
99
103
  "gap-".concat(((_b = pagination.styleOptions) === null || _b === void 0 ? void 0 : _b.paginationComponentSpacing) === undefined ? 2 : (_c = pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.paginationComponentSpacing),
100
- ], normalizedModel: currentPageRowsOutput.normalizedModel, prePagingNumRows: rows.length, sizeSelectAfterPageSelect: (_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.sizeSelectAfterPageSelect }));
104
+ ], normalizedModel: normalizedModel, prePagingNumRows: rows.length, sizeSelectAfterPageSelect: (_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.sizeSelectAfterPageSelect }));
101
105
  };
102
- return pagination ? (_jsx("div", { style: { width: widthProperty, height: heightProperties.containerDiv }, className: classNames("d-flex", "flex-column", "gap-".concat(((_b = pagination.styleOptions) === null || _b === void 0 ? void 0 : _b.mainComponentSpacing) === undefined ? 2 : (_c = pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.mainComponentSpacing)), "data-testid": "rbdg-top-level-grid-container", children: ((_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.aboveMainComponent) ? (_jsxs(_Fragment, { children: [getPagination(pagination), mainGridComponent] })) : (_jsxs(_Fragment, { children: [mainGridComponent, getPagination(pagination)] })) })) : (_jsx(_Fragment, { children: mainGridComponent }));
106
+ var exportFnInfo = useExportFn({
107
+ rows: rows,
108
+ cols: cols,
109
+ filteredRows: filterModel && filteredRows,
110
+ currentPageRows: pagination && paginatedRows,
111
+ });
112
+ var toolbarInterfaces = useInterfaces({
113
+ exportParams: allowExport ? { exportFnInfo: exportFnInfo } : undefined,
114
+ filterParams: filterModel
115
+ ? {
116
+ filterState: filterState,
117
+ setFilterState: normalizedTableFilterModel.setTableFilterState,
118
+ caption: filterModel.filterTableCaption,
119
+ }
120
+ : undefined,
121
+ });
122
+ var showToolbar = allowExport || filterModel;
123
+ var mainSpacingSetting = (_b = styleOptions === null || styleOptions === void 0 ? void 0 : styleOptions.mainComponentSpacing) !== null && _b !== void 0 ? _b : (_c = pagination === null || pagination === void 0 ? void 0 : pagination.styleOptions) === null || _c === void 0 ? void 0 : _c.mainComponentSpacing;
124
+ return pagination || showToolbar ? (_jsxs("div", { style: { width: widthProperty, height: heightProperties.containerDiv }, className: classNames("d-flex", "flex-column", "gap-".concat(mainSpacingSetting === undefined ? 2 : mainSpacingSetting)), "data-testid": "rbdg-top-level-grid-container", children: [showToolbar && _jsx(ToolbarContainer, { interfaceGen: toolbarInterfaces }), pagination ? (_jsx(_Fragment, { children: ((_d = pagination.styleOptions) === null || _d === void 0 ? void 0 : _d.aboveMainComponent) ? (_jsxs(_Fragment, { children: [getPagination(pagination), mainGridComponent] })) : (_jsxs(_Fragment, { children: [mainGridComponent, getPagination(pagination)] })) })) : (_jsx(_Fragment, { children: mainGridComponent }))] })) : (_jsx(_Fragment, { children: mainGridComponent }));
103
125
  };
104
126
  export default Grid;
@@ -5,19 +5,20 @@ import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
5
5
  import { GRID_BODY_DATA_TEST_ID } from "../constants";
6
6
  var GridBody = function (_a) {
7
7
  var augFormattedRows = _a.augFormattedRows, cols = _a.cols, rowVariant = _a.rowVariant, cellVariant = _a.cellVariant, focusCoords = _a.focusCoords, cellFocusVariant = _a.cellFocusVariant;
8
- return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map(function (row, rowDisplayIndex) {
8
+ return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map(function (row, displayRowArrayIndex) {
9
9
  var ariaRowIndex = row.prePaginationIndex + 2;
10
- return (_jsx("div", { role: "row", "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
11
- rowVariant(row, rowDisplayIndex) &&
12
- "".concat(CSS_PREFIX, "-").concat(rowVariant(row, rowDisplayIndex))), children: row.contents.map(function (_a, index) {
10
+ var displayRowIndex = displayRowArrayIndex + 2;
11
+ return (_jsx("div", { role: "row", "display-rowindex": displayRowIndex, "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
12
+ rowVariant(row, displayRowArrayIndex) &&
13
+ "".concat(CSS_PREFIX, "-").concat(rowVariant(row, displayRowArrayIndex))), children: row.contents.map(function (_a, index) {
13
14
  var formattedValue = _a.formattedValue, width = _a.width;
14
15
  var ariaColIndex = index + 1;
15
16
  var isFocused = focusCoords.ariaColIndex === ariaColIndex &&
16
- focusCoords.ariaRowIndex === ariaRowIndex;
17
+ focusCoords.displayRowIndex === displayRowIndex;
17
18
  var cellVariantVal = cellVariant &&
18
- cellVariant(row.contents[index], row, index, rowDisplayIndex);
19
+ cellVariant(row.contents[index], row, index, displayRowArrayIndex);
19
20
  var cellFocusVariantVal = cellFocusVariant &&
20
- cellFocusVariant(row.contents[index], row, index, rowDisplayIndex);
21
+ cellFocusVariant(row.contents[index], row, index, displayRowArrayIndex);
21
22
  return (_jsx("div", { tabIndex: isFocused ? 0 : -1, style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariantVal && "".concat(CSS_PREFIX, "-").concat(cellVariantVal), cellFocusVariantVal && "focus-ring-".concat(cellFocusVariantVal), {
22
23
  "z-2": isFocused,
23
24
  "rbdg-focusable-cell": isFocused,
@@ -25,7 +25,7 @@ var GridHeader = function (_a) {
25
25
  }
26
26
  setSortColDef(null);
27
27
  }; };
28
- 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 && "".concat(CSS_PREFIX, "-").concat(rowVariant)), "aria-rowindex": 1, children: cols.map(function (col, index) {
28
+ 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 && "".concat(CSS_PREFIX, "-").concat(rowVariant)), "display-rowindex": 1, "aria-rowindex": 1, children: cols.map(function (col, index) {
29
29
  var ariaColIndex = index + 1;
30
30
  var isFocused = focusColIndex === ariaColIndex;
31
31
  var 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",
3
3
  "description": "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": "MIT",
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";
@@ -10,7 +9,7 @@ import useExportFn from "../common/export/useExportFn";
10
9
  import getWidthStyle from "../common/util/getWidthStyle";
11
10
  var InternalTable = function (_a) {
12
11
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
13
- var _o = _a.gridProps, rows = _o.rows, cols = _o.cols, pagination = _o.pagination, filterModel = _o.filterModel, selectModel = _o.selectModel, editModel = _o.editModel, caption = _o.caption, styleModel = _o.styleModel, displayMode = _o.displayMode, allowExport = _o.allowExport, _p = _a.hooks, pipelineOutput = _p.pipelineOutput, selectFns = _p.selectFns, _q = _a.slots, colHeaderCells = _q.colHeaderCells, bodyRows = _q.bodyRows, prefixHeader = _q.prefixHeader, classes = _a.classes;
12
+ var _o = _a.tableProps, rows = _o.rows, cols = _o.cols, pagination = _o.pagination, filterModel = _o.filterModel, selectModel = _o.selectModel, editModel = _o.editModel, caption = _o.caption, styleModel = _o.styleModel, displayMode = _o.displayMode, allowExport = _o.allowExport, _p = _a.hooks, pipelineOutput = _p.pipelineOutput, selectFns = _p.selectFns, _q = _a.slots, colHeaderCells = _q.colHeaderCells, bodyRows = _q.bodyRows, prefixHeader = _q.prefixHeader, classes = _a.classes;
14
13
  var normalizedTableFilterModel = pipelineOutput.normalizedTableFilterModel, filteredRows = pipelineOutput.filteredRows, filterState = pipelineOutput.filterState, sortedRows = pipelineOutput.sortedRowsOutput.sortedRows, _r = pipelineOutput.currentPageRowsOutput, paginatedRows = _r.paginatedRows, normalizedModel = _r.normalizedModel, showSelectCol = pipelineOutput.showSelectCol;
15
14
  var exportFnInfo = useExportFn({
16
15
  rows: rows,
@@ -19,35 +18,22 @@ var InternalTable = function (_a) {
19
18
  currentPageRows: pagination && paginatedRows,
20
19
  });
21
20
  var showToolbar = filterModel || allowExport;
22
- var toolbarPropGen = useMemo(function () { return function (closeUiCallback) {
23
- return {
24
- filtering: filterState && filterModel && normalizedTableFilterModel
25
- ? {
26
- filterState: filterState,
27
- setFilterState: normalizedTableFilterModel.setTableFilterState,
28
- caption: filterModel.filterTableCaption,
29
- styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
30
- closeFormCallback: closeUiCallback,
31
- }
32
- : undefined,
33
- exporting: allowExport
34
- ? {
35
- exportFnInfo: exportFnInfo,
36
- styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
37
- closeCallback: closeUiCallback,
38
- }
39
- : undefined,
40
- };
41
- }; }, [
42
- allowExport,
43
- exportFnInfo,
44
- filterModel,
45
- filterState,
46
- normalizedTableFilterModel,
47
- styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
48
- styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
49
- ]);
50
- var toolbarInterfaces = useInterfaces(toolbarPropGen);
21
+ var toolbarInterfaces = useInterfaces({
22
+ exportParams: allowExport
23
+ ? {
24
+ exportFnInfo: exportFnInfo,
25
+ styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.exportFormStyleModel,
26
+ }
27
+ : undefined,
28
+ filterParams: filterModel
29
+ ? {
30
+ filterState: filterState,
31
+ setFilterState: normalizedTableFilterModel.setTableFilterState,
32
+ caption: filterModel.filterTableCaption,
33
+ styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel,
34
+ }
35
+ : undefined,
36
+ });
51
37
  var rowsAreSelectable = selectFns.rowsAreSelectable, selectionInfo = selectFns.selectionInfo, selectAllOnClick = selectFns.selectAllOnClick;
52
38
  var mainTable = (_jsxs("table", { className: classNames({
53
39
  "table-hover": rowsAreSelectable,
package/table/Table.js CHANGED
@@ -43,7 +43,7 @@ var Table = function (props) {
43
43
  styleModel.mainTableStyleModel.theadTh(index), width: width }, name));
44
44
  });
45
45
  var 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 }));
46
- return (_jsx(InternalTable, { gridProps: props, hooks: {
46
+ return (_jsx(InternalTable, { tableProps: props, hooks: {
47
47
  pipelineOutput: combinedPipelineOutput,
48
48
  selectFns: gridSelectionFns,
49
49
  }, slots: { colHeaderCells: colHeaderCells, bodyRows: 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
  */