@absreim/react-bootstrap-data-grid 4.4.0 → 4.6.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.
@@ -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";
@@ -15,7 +15,7 @@ import classNames from "classnames";
15
15
  */
16
16
  var PageSelector = function (_a) {
17
17
  var numPages = _a.numPages, numButtons = _a.numButtons, pageNum = _a.pageNum, setPageNum = _a.setPageNum, ariaLabel = _a.ariaLabel, alignment = _a.alignment, size = _a.size;
18
- var ulClasses = ["pagination"];
18
+ var ulClasses = ["pagination", "mb-0"];
19
19
  if (size === "small") {
20
20
  ulClasses.push("pagination-sm");
21
21
  }
@@ -44,39 +44,49 @@ var PageSelector = function (_a) {
44
44
  }
45
45
  return indices;
46
46
  }, [lowerBound, upperBound]);
47
+ var leftArrowButtonsDisabled = pageNum === 1;
48
+ var rightArrowButtonsDisabled = pageNum === numPages;
47
49
  function getFirstArrowButton() {
48
- if (lowerBound === 1) {
49
- return null;
50
- }
51
- return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "First", onClick: function (event) {
50
+ return (_jsx("li", { className: classNames("page-item", {
51
+ disabled: leftArrowButtonsDisabled,
52
+ }), children: _jsx("a", { className: "page-link", href: "#", "aria-label": "First", tabIndex: leftArrowButtonsDisabled ? -1 : 0, onClick: function (event) {
52
53
  event.preventDefault();
54
+ if (leftArrowButtonsDisabled) {
55
+ return;
56
+ }
53
57
  setPageNum(1);
54
58
  }, children: _jsx("span", { "aria-hidden": "true", children: "<<" }) }) }));
55
59
  }
56
60
  function getPrevArrowButton() {
57
- if (pageNum === 1) {
58
- return null;
59
- }
60
- return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Previous", onClick: function (event) {
61
+ return (_jsx("li", { className: classNames("page-item", {
62
+ disabled: leftArrowButtonsDisabled,
63
+ }), children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Previous", tabIndex: leftArrowButtonsDisabled ? -1 : 0, onClick: function (event) {
61
64
  event.preventDefault();
65
+ if (leftArrowButtonsDisabled) {
66
+ return;
67
+ }
62
68
  setPageNum(pageNum - 1);
63
69
  }, children: _jsx("span", { "aria-hidden": "true", children: "<" }) }) }));
64
70
  }
65
71
  function getNextArrowButton() {
66
- if (pageNum === numPages) {
67
- return null;
68
- }
69
- return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Next", onClick: function (event) {
72
+ return (_jsx("li", { className: classNames("page-item", {
73
+ disabled: rightArrowButtonsDisabled,
74
+ }), children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Next", tabIndex: rightArrowButtonsDisabled ? -1 : 0, onClick: function (event) {
70
75
  event.preventDefault();
76
+ if (rightArrowButtonsDisabled) {
77
+ return;
78
+ }
71
79
  setPageNum(pageNum + 1);
72
80
  }, children: _jsx("span", { "aria-hidden": "true", children: ">" }) }) }));
73
81
  }
74
82
  function getLastArrowButton() {
75
- if (upperBound === numPages) {
76
- return null;
77
- }
78
- return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Last", onClick: function (event) {
83
+ return (_jsx("li", { className: classNames("page-item", {
84
+ disabled: rightArrowButtonsDisabled,
85
+ }), children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Last", tabIndex: rightArrowButtonsDisabled ? -1 : 0, onClick: function (event) {
79
86
  event.preventDefault();
87
+ if (rightArrowButtonsDisabled) {
88
+ return;
89
+ }
80
90
  setPageNum(numPages);
81
91
  }, children: _jsx("span", { "aria-hidden": "true", children: ">>" }) }) }));
82
92
  }
@@ -87,6 +97,6 @@ var PageSelector = function (_a) {
87
97
  event.preventDefault();
88
98
  setPageNum(buttonIndex);
89
99
  }, children: buttonIndex }) }, buttonIndex)); });
90
- return (_jsx("nav", { "aria-label": ariaLabel, "data-testid": "rbdg-page-selector", children: _jsxs("ul", { className: classNames(ulClasses), children: [getFirstArrowButton(), getPrevArrowButton(), indexButtons, getNextArrowButton(), getLastArrowButton()] }) }));
100
+ return (_jsx("nav", { "aria-label": ariaLabel === undefined ? "Select page" : ariaLabel, "data-testid": "rbdg-page-selector", children: _jsxs("ul", { className: classNames(ulClasses), children: [getFirstArrowButton(), getPrevArrowButton(), indexButtons, getNextArrowButton(), getLastArrowButton()] }) }));
91
101
  };
92
102
  export default PageSelector;
@@ -5,6 +5,7 @@ export interface PageSizeSelectorProps {
5
5
  pageSizeOptions: number[];
6
6
  pageSizeIndex: number;
7
7
  handleSetPageSize: (index: number) => void;
8
+ showTextLabel: boolean;
8
9
  }
9
10
  declare const PageSizeSelector: FC<PageSizeSelectorProps>;
10
11
  export default PageSizeSelector;
@@ -1,15 +1,28 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
2
3
  import classNames from "classnames";
4
+ var labelText = "Rows per page";
3
5
  var PageSizeSelector = function (_a) {
4
- var componentSize = _a.componentSize, pageSizeOptions = _a.pageSizeOptions, pageSizeIndex = _a.pageSizeIndex, handleSetPageSize = _a.handleSetPageSize;
6
+ var componentSize = _a.componentSize, pageSizeOptions = _a.pageSizeOptions, pageSizeIndex = _a.pageSizeIndex, handleSetPageSize = _a.handleSetPageSize, showTextLabel = _a.showTextLabel;
7
+ var id = useId();
5
8
  var onChange = function (event) {
6
9
  var pageSizeIndex = Number(event.target.value);
7
10
  handleSetPageSize(pageSizeIndex);
8
11
  };
9
- return (_jsx("div", { "data-testid": "rbdg-page-size-selector", children: _jsx("select", { name: "rowsPerPage", className: classNames({
10
- "form-select": true,
11
- "form-select-lg": componentSize === "large",
12
- "form-select-sm": componentSize === "small",
13
- }), value: pageSizeIndex, "aria-label": "Number of Rows per Page", onChange: onChange, children: pageSizeOptions.map(function (numRows, index) { return (_jsx("option", { value: index, children: numRows }, index)); }) }) }));
12
+ function getTextSizeClass() {
13
+ switch (componentSize) {
14
+ case "small":
15
+ return "rbdg-input-label-sm";
16
+ case "large":
17
+ return "rbdg-input-label-lg";
18
+ default:
19
+ return undefined;
20
+ }
21
+ }
22
+ return (_jsxs("div", { "data-testid": "rbdg-page-size-selector", className: "d-flex align-items-center gap-2 flex-shrink-0", children: [showTextLabel && (_jsx("label", { htmlFor: id, className: classNames("flex-shrink-0", getTextSizeClass()), children: labelText })), _jsx("select", { "aria-label": showTextLabel ? undefined : labelText, id: id, name: "rowsPerPage", className: classNames({
23
+ "form-select": true,
24
+ "form-select-lg": componentSize === "large",
25
+ "form-select-sm": componentSize === "small",
26
+ }, "flex-shrink-0", "w-auto"), value: pageSizeIndex, onChange: onChange, children: pageSizeOptions.map(function (numRows, index) { return (_jsx("option", { value: index, children: numRows }, index)); }) })] }));
14
27
  };
15
28
  export default PageSizeSelector;
@@ -4,7 +4,7 @@ import PageSelector from "./PageSelector";
4
4
  import classNames from "classnames";
5
5
  var Pagination = function (_a) {
6
6
  var normalizedModel = _a.normalizedModel, prePagingNumRows = _a.prePagingNumRows, containerDivClasses = _a.containerDivClasses, sizeSelectAfterPageSelect = _a.sizeSelectAfterPageSelect;
7
- var pageSizeOptions = normalizedModel.pageSizeOptions, pageSizeIndex = normalizedModel.pageSizeIndex, currentPage = normalizedModel.currentPage, setCurrentPage = normalizedModel.setCurrentPage, setPageSizeIndex = normalizedModel.setPageSizeIndex, componentSize = normalizedModel.componentSize, maxPageButtons = normalizedModel.maxPageButtons, pageSelectorAriaLabel = normalizedModel.pageSelectorAriaLabel, pageSelectorJustifyContent = normalizedModel.pageSelectorJustifyContent;
7
+ var pageSizeOptions = normalizedModel.pageSizeOptions, pageSizeIndex = normalizedModel.pageSizeIndex, currentPage = normalizedModel.currentPage, setCurrentPage = normalizedModel.setCurrentPage, setPageSizeIndex = normalizedModel.setPageSizeIndex, componentSize = normalizedModel.componentSize, maxPageButtons = normalizedModel.maxPageButtons, pageSelectorAriaLabel = normalizedModel.pageSelectorAriaLabel, pageSelectorJustifyContent = normalizedModel.pageSelectorJustifyContent, showTextLabel = normalizedModel.showTextLabel;
8
8
  var numPages = Math.ceil(prePagingNumRows / pageSizeOptions[pageSizeIndex]);
9
9
  var pageIndexAwarePageSizeSetter = function (newPageSizeIndex) {
10
10
  var newPageSize = pageSizeOptions[newPageSizeIndex];
@@ -17,7 +17,7 @@ var Pagination = function (_a) {
17
17
  setCurrentPage(maxPages);
18
18
  }
19
19
  };
20
- var pageSizeSelect = (_jsx(PageSizeSelector, { componentSize: componentSize, pageSizeOptions: pageSizeOptions, pageSizeIndex: pageSizeIndex, handleSetPageSize: pageIndexAwarePageSizeSetter }));
20
+ var pageSizeSelect = (_jsx(PageSizeSelector, { componentSize: componentSize, pageSizeOptions: pageSizeOptions, pageSizeIndex: pageSizeIndex, handleSetPageSize: pageIndexAwarePageSizeSetter, showTextLabel: !!showTextLabel }));
21
21
  var pageSelect = (_jsx(PageSelector, { numPages: numPages, pageNum: currentPage, numButtons: maxPageButtons, setPageNum: setCurrentPage, size: componentSize, ariaLabel: pageSelectorAriaLabel, alignment: pageSelectorJustifyContent }));
22
22
  return (_jsx("div", { "data-testid": "rdbg-pagination-ui-container", className: classNames(containerDivClasses || [
23
23
  "d-flex",
@@ -5,4 +5,4 @@ import { ControlledPaginationModel } from "./types";
5
5
  *
6
6
  * @internal
7
7
  */
8
- export type NormalizedPaginationModel = Required<Omit<ControlledPaginationModel, "type" | "pageSelectorAriaLabel" | "pageSelectorJustifyContent">> & Pick<ControlledPaginationModel, "pageSelectorAriaLabel" | "pageSelectorJustifyContent">;
8
+ export type NormalizedPaginationModel = Required<Omit<ControlledPaginationModel, "type" | "pageSelectorAriaLabel" | "pageSelectorJustifyContent" | "showTextLabel">> & Pick<ControlledPaginationModel, "pageSelectorAriaLabel" | "pageSelectorJustifyContent" | "showTextLabel">;
@@ -43,7 +43,7 @@ export interface PaginationOptions {
43
43
  * The ARIA label for the nav element that represents the pagination
44
44
  * component.
45
45
  *
46
- * @defaultValue `undefined` - no ARIA label
46
+ * @defaultValue `"Select page"`
47
47
  */
48
48
  pageSelectorAriaLabel?: string;
49
49
  /**
@@ -53,8 +53,19 @@ export interface PaginationOptions {
53
53
  * @defaultValue `undefined` - no justify-content property is specified, which
54
54
  * acts like "start" based on CSS standards. See
55
55
  * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/justify-content#syntax}.
56
+ *
57
+ * @deprecated This property has no effect under normal circumstances because
58
+ * the enclosing nav element is using the block display type. It is kept
59
+ * around only to avoid breaking existing code.
56
60
  */
57
61
  pageSelectorJustifyContent?: JustifyContentSetting;
62
+ /**
63
+ * Configures whether to show a text label for the page size selector
64
+ * dropdown.
65
+ *
66
+ * @defaultValue `undefined` - the text label is not displayed.
67
+ */
68
+ showTextLabel?: boolean;
58
69
  }
59
70
  /**
60
71
  * Properties specific to configuring pagination in a controlled manner.
@@ -47,6 +47,7 @@ var useCurrentPageRows = function (sortedRows, paginationModel) {
47
47
  componentSize: componentSize,
48
48
  pageSelectorAriaLabel: paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSelectorAriaLabel,
49
49
  pageSelectorJustifyContent: paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSelectorJustifyContent,
50
+ showTextLabel: paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.showTextLabel,
50
51
  };
51
52
  var pageSize = pageSizeOptions[pageSizeIndex];
52
53
  var lowerIndex = pageSize * (currentPage - 1);
@@ -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
package/common.css ADDED
@@ -0,0 +1 @@
1
+ .rbdg-input-label-lg{font-size:1.25rem}.rbdg-input-label-sm{font-size:.875rem}
package/common.scss ADDED
@@ -0,0 +1,7 @@
1
+ .rbdg-input-label-lg {
2
+ font-size: $font-size-lg;
3
+ }
4
+
5
+ .rbdg-input-label-sm {
6
+ font-size: $font-size-sm;
7
+ }
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) {
@@ -33,7 +37,7 @@ var Grid = function (_a) {
33
37
  if (typeof width === "number") {
34
38
  return width;
35
39
  }
36
- return "min-content";
40
+ return "max-content";
37
41
  }
38
42
  var widthProperty = getWidthProperty(width);
39
43
  function getHeightProperties(height) {
@@ -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))) {
@@ -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;
@@ -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.4.0",
4
+ "version": "4.6.0",
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
  */