@absreim/react-bootstrap-data-grid 4.4.0 → 4.5.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.
@@ -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);
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
@@ -33,7 +33,7 @@ var Grid = function (_a) {
33
33
  if (typeof width === "number") {
34
34
  return width;
35
35
  }
36
- return "min-content";
36
+ return "max-content";
37
37
  }
38
38
  var widthProperty = getWidthProperty(width);
39
39
  function getHeightProperties(height) {
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.5.0",
5
5
  "license": "MIT",
6
6
  "author": "Brook Li",
7
7
  "homepage": "https://react-bootstrap-data-grid.vercel.app/",