@absreim/react-bootstrap-data-grid 2.4.1 → 2.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.
- package/InternalGrid.d.ts +1 -0
- package/InternalGrid.js +2 -2
- package/main/BodyRows.d.ts +3 -1
- package/main/BodyRows.js +5 -5
- package/main/ColHeaderCell/index.js +2 -1
- package/package.json +1 -1
- package/pagination/PageSizeSelector.js +1 -1
- package/pipeline/useCombinedPipeline/index.d.ts +2 -2
- package/pipeline/useCombinedPipeline/index.js +2 -2
- package/pipeline/useCombinedPipeline/useCurrentPageRows.d.ts +3 -3
- package/pipeline/useCombinedPipeline/useCurrentPageRows.js +18 -2
- package/pipeline/useCombinedPipeline/useDisplayRows.d.ts +2 -2
- package/pipeline/useCombinedPipeline/useDisplayRows.js +6 -1
- package/pipeline/useCombinedPipeline/useFilter.d.ts +2 -2
- package/pipeline/useCombinedPipeline/useFilter.js +14 -2
- package/pipeline/useCombinedPipeline/useSortedRows.d.ts +3 -3
- package/selection/SelectAllHeaderCell.d.ts +1 -0
- package/selection/SelectAllHeaderCell.js +2 -2
- package/sorting/sortOrderToAriaSort.d.ts +4 -0
- package/sorting/sortOrderToAriaSort.js +11 -0
- package/toolbar/Toolbar.js +59 -4
- package/toolbar/ToolbarContainer.js +0 -2
- package/types.d.ts +9 -5
package/InternalGrid.d.ts
CHANGED
package/InternalGrid.js
CHANGED
|
@@ -12,7 +12,7 @@ import useExportFn from "./export/useExportFn";
|
|
|
12
12
|
import getWidthStyle from "./util/getWidthStyle";
|
|
13
13
|
var InternalGrid = function (_a) {
|
|
14
14
|
var _b;
|
|
15
|
-
var _c = _a.gridProps, rows = _c.rows, cols = _c.cols, pagination = _c.pagination, filterModel = _c.filterModel, selectModel = _c.selectModel, editModel = _c.editModel, caption = _c.caption, styleModel = _c.styleModel, useToolbar = _c.useToolbar, responsive = _c.responsive, displayMode = _c.displayMode, _d = _a.hooks, pipelineOutput = _d.pipelineOutput, selectFns = _d.selectFns, unwrappedStyles = _d.unwrappedStyles, _e = _a.slots, colHeaderCells = _e.colHeaderCells, bodyRows = _e.bodyRows;
|
|
15
|
+
var _c = _a.gridProps, rows = _c.rows, cols = _c.cols, pagination = _c.pagination, filterModel = _c.filterModel, selectModel = _c.selectModel, editModel = _c.editModel, caption = _c.caption, styleModel = _c.styleModel, useToolbar = _c.useToolbar, responsive = _c.responsive, displayMode = _c.displayMode, _d = _a.hooks, pipelineOutput = _d.pipelineOutput, selectFns = _d.selectFns, unwrappedStyles = _d.unwrappedStyles, _e = _a.slots, colHeaderCells = _e.colHeaderCells, bodyRows = _e.bodyRows, prefixHeader = _e.prefixHeader;
|
|
16
16
|
var normalizedTableFilterModel = pipelineOutput.normalizedTableFilterModel, filteredRows = pipelineOutput.filteredRows, filterState = pipelineOutput.filterState, sortedRows = pipelineOutput.sortedRowsOutput.sortedRows, _f = pipelineOutput.currentPageRowsOutput, paginatedRows = _f.paginatedRows, normalizedModel = _f.normalizedModel, showSelectCol = pipelineOutput.showSelectCol;
|
|
17
17
|
var _g = useState(false), filterOptionsVisible = _g[0], setFilterOptionsVisible = _g[1];
|
|
18
18
|
var exportFnInfo = useExportFn({
|
|
@@ -51,7 +51,7 @@ var InternalGrid = function (_a) {
|
|
|
51
51
|
var mainTable = (_jsxs("table", { className: classNames("table", {
|
|
52
52
|
"table-hover": rowsAreSelectable,
|
|
53
53
|
"d-block": displayMode === "block",
|
|
54
|
-
}, unwrappedTableModel.table), "aria-rowcount": filteredRows.length + 1, children: [caption !== undefined && (_jsx("caption", { className: classNames(unwrappedTableModel.caption), children: caption })), _jsx("thead", { className: classNames(unwrappedTableModel.thead), children: _jsxs("tr", { "aria-rowindex": 1, className: classNames(unwrappedTableModel.theadTr), children: [showSelectCol && (_jsx(SelectAllHeaderCell, { style: getWidthStyle(selectModel === null || selectModel === void 0 ? void 0 : selectModel.selectColWidth), selectionInfo: selectionInfo, onClick: selectAllOnClick, totalRows: rows.length, additionalClasses: unwrappedTableModel.rowSelectColTh })), colHeaderCells, editModel && (_jsx("th", { "aria-colindex": cols.length + 1 + (showSelectCol ? 1 : 0), className: classNames(unwrappedTableModel.editColTh), style: getWidthStyle(editModel === null || editModel === void 0 ? void 0 : editModel.editColWidth), children: "Edit Controls" }))] }) }), _jsx("tbody", { className: classNames(unwrappedTableModel.tbody), children: bodyRows })] }));
|
|
54
|
+
}, unwrappedTableModel.table), "aria-rowcount": filteredRows.length + 1, children: [caption !== undefined && (_jsx("caption", { className: classNames(unwrappedTableModel.caption), children: caption })), _jsx("thead", { className: classNames(unwrappedTableModel.thead), children: _jsxs("tr", { "aria-rowindex": 1, className: classNames(unwrappedTableModel.theadTr), children: [prefixHeader, showSelectCol && (_jsx(SelectAllHeaderCell, { style: getWidthStyle(selectModel === null || selectModel === void 0 ? void 0 : selectModel.selectColWidth), selectionInfo: selectionInfo, onClick: selectAllOnClick, totalRows: rows.length, additionalClasses: unwrappedTableModel.rowSelectColTh, colIndexOffset: prefixHeader ? 1 : 0 })), colHeaderCells, editModel && (_jsx("th", { "aria-colindex": cols.length + 1 + (showSelectCol ? 1 : 0), className: classNames(unwrappedTableModel.editColTh), style: getWidthStyle(editModel === null || editModel === void 0 ? void 0 : editModel.editColWidth), children: "Edit Controls" }))] }) }), _jsx("tbody", { className: classNames(unwrappedTableModel.tbody), children: bodyRows })] }));
|
|
55
55
|
return (_jsxs("div", { "data-testid": "rbdg-top-level-div", className: classNames(unwrappedAdditionalStyleModel.topLevelDiv), children: [normalizedTableFilterModel && !useToolbar && (_jsxs("div", { "data-testid": "rbdg-filter-inputs-div", className: classNames(unwrappedAdditionalStyleModel.filterInputsDiv), children: [_jsx(ToggleButton, { isActive: filterOptionsVisible, label: "".concat(filterOptionsVisible ? "Hide" : "Show ", " Filter Options"), onClick: handleToggleFilterOptions, classes: (_b = styleModel === null || styleModel === void 0 ? void 0 : styleModel.additionalComponentsStyleModel) === null || _b === void 0 ? void 0 : _b.filterUiToggleButton }), filterOptionsVisible && (_jsx(FilterOptionsTable, { caption: filterModel.filterTableCaption, filterState: filterState, setFilterState: normalizedTableFilterModel.setTableFilterState, styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.filterInputTableStyleModel }))] })), useToolbar && (_jsx(ToolbarContainer, { interfaces: toolbarInterfaces, styleModel: styleModel === null || styleModel === void 0 ? void 0 : styleModel.toolbarStyleModel })), _jsxs("div", { "data-testid": "rbdg-table-and-pagination-div", className: classNames(unwrappedAdditionalStyleModel.tableAndPaginationDiv), children: [responsive ? (_jsx("div", { "data-testid": "rbdg-table-div", className: "table-responsive", children: mainTable })) : (_jsx(_Fragment, { children: mainTable })), normalizedModel && (_jsx(Pagination, { normalizedModel: normalizedModel, prePagingNumRows: sortedRows.length, containerDivClasses: unwrappedAdditionalStyleModel.paginationUiDiv }))] })] }));
|
|
56
56
|
};
|
|
57
57
|
export default InternalGrid;
|
package/main/BodyRows.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AugFormattedRow } from "../types";
|
|
2
|
-
import { FC } from "react";
|
|
2
|
+
import { FC, ReactNode } from "react";
|
|
3
3
|
import { UseGridSelectionFnsHook } from "../pipeline/useGridSelectionFns";
|
|
4
4
|
import { UseUnwrappedGridStylesHook } from "../pipeline/useUnwrappedGridStyles";
|
|
5
5
|
import { UseCombinedPipelineHook } from "../pipeline/useCombinedPipeline";
|
|
@@ -14,6 +14,8 @@ interface BodyRowsProps {
|
|
|
14
14
|
selectModel: SelectModel | undefined;
|
|
15
15
|
editModel: EditModel | undefined;
|
|
16
16
|
getInputStrSubmitCallback: UseGetInputStrSubmitCallbackHook;
|
|
17
|
+
additionalColIndexOffset?: number;
|
|
18
|
+
renderPrefixCells?: (augFormattedRows: AugFormattedRow) => ReactNode;
|
|
17
19
|
}
|
|
18
20
|
declare const BodyRows: FC<BodyRowsProps>;
|
|
19
21
|
export default BodyRows;
|
package/main/BodyRows.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import EditableRow from "../editing/EditableRow";
|
|
3
3
|
import classNames from "classnames";
|
|
4
4
|
import getWidthStyle from "../util/getWidthStyle";
|
|
5
5
|
import SelectionInput from "../selection/SelectionInput";
|
|
6
6
|
var BodyRows = function (_a) {
|
|
7
|
-
var augFormattedRows = _a.augFormattedRows, _b = _a.gridSelectionFns, selectedSet = _b.selectedSet, getSelectInputModel = _b.getSelectInputModel, getSelectHandler = _b.getSelectHandler, getRowClickHandler = _b.getRowClickHandler, getAriaSelectedValue = _b.getAriaSelectedValue, unwrappedTableModel = _a.unwrappedStyles.unwrappedTableModel, _c = _a.combinedPipelineOutput, showSelectCol = _c.showSelectCol, ariaColIndexOffset = _c.ariaColIndexOffset, selectModel = _a.selectModel, editModel = _a.editModel, getInputStrSubmitCallback = _a.getInputStrSubmitCallback;
|
|
7
|
+
var augFormattedRows = _a.augFormattedRows, _b = _a.gridSelectionFns, selectedSet = _b.selectedSet, getSelectInputModel = _b.getSelectInputModel, getSelectHandler = _b.getSelectHandler, getRowClickHandler = _b.getRowClickHandler, getAriaSelectedValue = _b.getAriaSelectedValue, unwrappedTableModel = _a.unwrappedStyles.unwrappedTableModel, _c = _a.combinedPipelineOutput, showSelectCol = _c.showSelectCol, ariaColIndexOffset = _c.ariaColIndexOffset, selectModel = _a.selectModel, editModel = _a.editModel, getInputStrSubmitCallback = _a.getInputStrSubmitCallback, additionalColIndexOffset = _a.additionalColIndexOffset, renderPrefixCells = _a.renderPrefixCells;
|
|
8
8
|
return augFormattedRows.map(function (row, index) {
|
|
9
|
-
return (
|
|
9
|
+
return (_jsxs(EditableRow, { onClick: getRowClickHandler(row.id), className: classNames({
|
|
10
10
|
"table-active": selectedSet.has(row.id),
|
|
11
|
-
}, unwrappedTableModel.tbodyTr(row.id, index)), "aria-rowindex":
|
|
11
|
+
}, unwrappedTableModel.tbodyTr(row.id, index)), "aria-rowindex": row.prePaginationIndex + 2, dataRowId: row.id, "aria-selected": getAriaSelectedValue(row.id), ariaColIndexOffset: ariaColIndexOffset + (additionalColIndexOffset || 0), cellData: row.contents, updateCallback: getInputStrSubmitCallback && getInputStrSubmitCallback(row.id), deleteCallback: (editModel === null || editModel === void 0 ? void 0 : editModel.getDeleteCallback) && editModel.getDeleteCallback(row.id), dataCellClasses: function (colIndex) {
|
|
12
12
|
return unwrappedTableModel.tbodyTd(row.id, index, colIndex);
|
|
13
13
|
}, dataCellInputClasses: function (colIndex) {
|
|
14
14
|
return unwrappedTableModel.tbodyTdInput(row.id, index, colIndex);
|
|
15
|
-
}, editCellClasses: unwrappedTableModel.editColTd(row.id, index), saveButtonClasses: unwrappedTableModel.editSaveButton(row.id, index), deleteButtonClasses: unwrappedTableModel.editDeleteButton(row.id, index), startButtonClasses: unwrappedTableModel.editStartButton(row.id, index), cancelButtonClasses: unwrappedTableModel.editCancelButton(row.id, index), children: showSelectCol && (_jsx("td", { className: classNames(unwrappedTableModel.rowSelectColTd(row.id, index)), "aria-colindex": 1, style: getWidthStyle(selectModel.selectColWidth), children: _jsx(SelectionInput, { selected: selectedSet.has(row.id), selectionInputModel: getSelectInputModel(row.id, selectModel), selectCallback: getSelectHandler(row.id), additionalClasses: unwrappedTableModel.rowSelectInput(row.id, index) }) })) }, row.id));
|
|
15
|
+
}, editCellClasses: unwrappedTableModel.editColTd(row.id, index), saveButtonClasses: unwrappedTableModel.editSaveButton(row.id, index), deleteButtonClasses: unwrappedTableModel.editDeleteButton(row.id, index), startButtonClasses: unwrappedTableModel.editStartButton(row.id, index), cancelButtonClasses: unwrappedTableModel.editCancelButton(row.id, index), children: [renderPrefixCells && renderPrefixCells(row), showSelectCol && (_jsx("td", { className: classNames(unwrappedTableModel.rowSelectColTd(row.id, index)), "aria-colindex": 1 + (additionalColIndexOffset || 0), style: getWidthStyle(selectModel.selectColWidth), children: _jsx(SelectionInput, { selected: selectedSet.has(row.id), selectionInputModel: getSelectInputModel(row.id, selectModel), selectCallback: getSelectHandler(row.id), additionalClasses: unwrappedTableModel.rowSelectInput(row.id, index) }) }))] }, row.id));
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
export default BodyRows;
|
|
@@ -3,6 +3,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import classNames from "classnames";
|
|
4
4
|
import getWidthStyle from "../../util/getWidthStyle";
|
|
5
5
|
import useSortHeaderStates from "./useSortHeaderStates";
|
|
6
|
+
import sortOrderToAriaSort from "../../sorting/sortOrderToAriaSort";
|
|
6
7
|
var ColHeaderCell = function (_a) {
|
|
7
8
|
var label = _a.label, sortModel = _a.sortModel, ariaColIndex = _a.ariaColIndex, additionalClasses = _a.additionalClasses, width = _a.width;
|
|
8
9
|
var _b = useSortHeaderStates(sortModel), handleClick = _b.handleClick, handleMouseOver = _b.handleMouseOver, handleMouseOut = _b.handleMouseOut, sortSymbol = _b.sortSymbol;
|
|
@@ -11,6 +12,6 @@ var ColHeaderCell = function (_a) {
|
|
|
11
12
|
"table-active": sortModel === null || sortModel === void 0 ? void 0 : sortModel.sortOrder,
|
|
12
13
|
}, additionalClasses || []), onClick: sortModel && handleClick, onMouseOver: handleMouseOver, onMouseOut: handleMouseOut, "aria-description": sortModel
|
|
13
14
|
? "Column header"
|
|
14
|
-
: "Column header that can be clicked to change the sorting mode", "aria-colindex": ariaColIndex, style: getWidthStyle(width), children: [label, sortSymbol] }));
|
|
15
|
+
: "Column header that can be clicked to change the sorting mode", "aria-colindex": ariaColIndex, "aria-sort": sortModel ? sortOrderToAriaSort(sortModel.sortOrder) : undefined, style: getWidthStyle(width), children: [label, sortSymbol] }));
|
|
15
16
|
};
|
|
16
17
|
export default ColHeaderCell;
|
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": "2.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Brook Li",
|
|
7
7
|
"homepage": "https://react-bootstrap-data-grid.vercel.app/",
|
|
@@ -6,7 +6,7 @@ var PageSizeSelector = function (_a) {
|
|
|
6
6
|
var pageSizeIndex = Number(event.target.value);
|
|
7
7
|
handleSetPageSize(pageSizeIndex);
|
|
8
8
|
};
|
|
9
|
-
return (_jsx("div", { children: _jsx("select", { className: classNames({
|
|
9
|
+
return (_jsx("div", { children: _jsx("select", { name: "rowsPerPage", className: classNames({
|
|
10
10
|
"form-select": true,
|
|
11
11
|
"form-select-lg": componentSize === "large",
|
|
12
12
|
"form-select-sm": componentSize === "small",
|
|
@@ -15,5 +15,5 @@ export interface UseCombinedPipelineHook {
|
|
|
15
15
|
ariaColIndexOffset: number;
|
|
16
16
|
displayRows: FormattedRow[];
|
|
17
17
|
}
|
|
18
|
-
declare const
|
|
19
|
-
export default
|
|
18
|
+
declare const useCombinedPipeline: (params: CombinedPipelineParams) => UseCombinedPipelineHook;
|
|
19
|
+
export default useCombinedPipeline;
|
|
@@ -4,7 +4,7 @@ import useFilterStateFromEditable from "./useFilterStateFromEditable";
|
|
|
4
4
|
import useSortedRows from "./useSortedRows";
|
|
5
5
|
import useCurrentPageRows from "./useCurrentPageRows";
|
|
6
6
|
import useDisplayRows from "./useDisplayRows";
|
|
7
|
-
var
|
|
7
|
+
var useCombinedPipeline = function (_a) {
|
|
8
8
|
var filterModel = _a.filterModel, cols = _a.cols, rows = _a.rows, sortModel = _a.sortModel, pagination = _a.pagination, selectModel = _a.selectModel;
|
|
9
9
|
var normalizedTableFilterModel = useFilterStateStore(filterModel, cols);
|
|
10
10
|
var editableFilterState = (normalizedTableFilterModel === null || normalizedTableFilterModel === void 0 ? void 0 : normalizedTableFilterModel.tableFilterState) || null;
|
|
@@ -28,4 +28,4 @@ var UseCombinedPipeline = function (_a) {
|
|
|
28
28
|
displayRows: displayRows,
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
export default
|
|
31
|
+
export default useCombinedPipeline;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AugRowDef, PostPaginationRowDef } from "../../types";
|
|
2
2
|
import { NormalizedPaginationModel, GridPaginationState } from "../../pagination/types";
|
|
3
3
|
export interface CurrentPageRowsOutput {
|
|
4
|
-
paginatedRows:
|
|
4
|
+
paginatedRows: PostPaginationRowDef[];
|
|
5
5
|
normalizedModel: NormalizedPaginationModel | null;
|
|
6
6
|
}
|
|
7
|
-
declare const useCurrentPageRows: (sortedRows:
|
|
7
|
+
declare const useCurrentPageRows: (sortedRows: AugRowDef[], paginationModel: GridPaginationState | undefined) => CurrentPageRowsOutput;
|
|
8
8
|
export default useCurrentPageRows;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
import { useMemo, useState } from "react";
|
|
2
13
|
var useCurrentPageRows = function (sortedRows, paginationModel) {
|
|
3
14
|
var componentSize = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.componentSize) || "medium";
|
|
@@ -19,7 +30,10 @@ var useCurrentPageRows = function (sortedRows, paginationModel) {
|
|
|
19
30
|
var maxPageButtons = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.maxPageButtons) || 5;
|
|
20
31
|
return useMemo(function () {
|
|
21
32
|
if (paginationModel === undefined) {
|
|
22
|
-
return {
|
|
33
|
+
return {
|
|
34
|
+
paginatedRows: sortedRows.map(function (row, index) { return (__assign(__assign({}, row), { prePaginationIndex: index })); }),
|
|
35
|
+
normalizedModel: null,
|
|
36
|
+
};
|
|
23
37
|
}
|
|
24
38
|
var pageSizeOptions = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSizeOptions) || [10, 25, 100];
|
|
25
39
|
var normalizedModel = {
|
|
@@ -36,7 +50,9 @@ var useCurrentPageRows = function (sortedRows, paginationModel) {
|
|
|
36
50
|
var pageSize = pageSizeOptions[pageSizeIndex];
|
|
37
51
|
var lowerIndex = pageSize * (currentPage - 1);
|
|
38
52
|
var upperIndex = lowerIndex + pageSize;
|
|
39
|
-
var paginatedRows = sortedRows
|
|
53
|
+
var paginatedRows = sortedRows
|
|
54
|
+
.slice(lowerIndex, upperIndex)
|
|
55
|
+
.map(function (row, index) { return (__assign(__assign({}, row), { prePaginationIndex: lowerIndex + index })); });
|
|
40
56
|
return { paginatedRows: paginatedRows, normalizedModel: normalizedModel };
|
|
41
57
|
}, [
|
|
42
58
|
paginationModel,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const useDisplayRows: (currentPageRows:
|
|
1
|
+
import { FormattedRow, ColDef, PostPaginationRowDef } from "../../types";
|
|
2
|
+
declare const useDisplayRows: (currentPageRows: PostPaginationRowDef[], cols: ColDef[], ariaColIndexOffset: number) => FormattedRow[];
|
|
3
3
|
export default useDisplayRows;
|
|
@@ -53,7 +53,12 @@ var useDisplayRows = function (currentPageRows, cols, ariaColIndexOffset) {
|
|
|
53
53
|
label: cols[index].label,
|
|
54
54
|
};
|
|
55
55
|
});
|
|
56
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
contents: displayRow,
|
|
58
|
+
id: row.id,
|
|
59
|
+
origIndex: row.origIndex,
|
|
60
|
+
prePaginationIndex: row.prePaginationIndex,
|
|
61
|
+
};
|
|
57
62
|
});
|
|
58
63
|
}, [currentPageRows, cols, ariaColIndexOffset]);
|
|
59
64
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RowDef } from "../../types";
|
|
1
|
+
import { AugRowDef, RowDef } from "../../types";
|
|
2
2
|
import { EditableTableFilterState } from "../../filtering/types";
|
|
3
|
-
declare const useFilter: (rows: RowDef[], filterState: EditableTableFilterState | null) =>
|
|
3
|
+
declare const useFilter: (rows: RowDef[], filterState: EditableTableFilterState | null) => AugRowDef[];
|
|
4
4
|
export default useFilter;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
import { useMemo } from "react";
|
|
2
13
|
var useFilter = function (rows, filterState) {
|
|
3
14
|
return useMemo(function () {
|
|
15
|
+
var augRows = rows.map(function (row, index) { return (__assign({ origIndex: index }, row)); });
|
|
4
16
|
if (filterState === null) {
|
|
5
|
-
return
|
|
17
|
+
return augRows;
|
|
6
18
|
}
|
|
7
|
-
return
|
|
19
|
+
return augRows.filter(function (row) {
|
|
8
20
|
function checkIfPassesStringFilter(value, state) {
|
|
9
21
|
switch (state.scheme) {
|
|
10
22
|
case "contains": {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AugRowDef, ColDefBase } from "../../types";
|
|
2
2
|
import { SortColDef, TableSortModel } from "../../sorting/types";
|
|
3
3
|
export interface SortedRowsOutput {
|
|
4
|
-
sortedRows:
|
|
4
|
+
sortedRows: AugRowDef[];
|
|
5
5
|
sortingEnabled: boolean;
|
|
6
6
|
sortColDef: SortColDef | null | undefined;
|
|
7
7
|
setSortColDef: ((sortColDef: SortColDef | null) => void) | undefined;
|
|
8
8
|
}
|
|
9
|
-
declare const useSortedRows: (rows:
|
|
9
|
+
declare const useSortedRows: (rows: AugRowDef[], cols: ColDefBase[], sortModel: TableSortModel | undefined) => SortedRowsOutput;
|
|
10
10
|
export default useSortedRows;
|
|
@@ -41,14 +41,14 @@ var getCheckboxState = function (selectionInfo, noRows) {
|
|
|
41
41
|
return disabledState;
|
|
42
42
|
};
|
|
43
43
|
var SelectAllHeaderCell = function (_a) {
|
|
44
|
-
var onClick = _a.onClick, selectionInfo = _a.selectionInfo, totalRows = _a.totalRows, additionalClasses = _a.additionalClasses, style = _a.style;
|
|
44
|
+
var onClick = _a.onClick, selectionInfo = _a.selectionInfo, totalRows = _a.totalRows, additionalClasses = _a.additionalClasses, style = _a.style, colIndexOffset = _a.colIndexOffset;
|
|
45
45
|
var noRows = totalRows === 0;
|
|
46
46
|
var _b = getCheckboxState(selectionInfo, noRows), indeterminate = _b.indeterminate, checked = _b.checked, disabled = _b.disabled, description = _b.description;
|
|
47
47
|
var ref = useRef(null);
|
|
48
48
|
useEffect(function () {
|
|
49
49
|
ref.current.indeterminate = indeterminate;
|
|
50
50
|
}, [indeterminate]);
|
|
51
|
-
return (_jsx("th", { style: style, "aria-colindex": 1, title: description, "aria-description": description, className: classNames({
|
|
51
|
+
return (_jsx("th", { style: style, "aria-colindex": 1 + (colIndexOffset || 0), title: description, "aria-description": description, className: classNames({
|
|
52
52
|
"btn-primary": !additionalClasses || additionalClasses.length === 0,
|
|
53
53
|
}, additionalClasses || []), children: _jsx("input", { type: "checkbox", checked: checked, ref: ref, disabled: disabled, "aria-label": description, onChange: onClick }) }));
|
|
54
54
|
};
|
package/toolbar/Toolbar.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, } from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
4
|
var buttonSpecs = {
|
|
4
5
|
filtering: {
|
|
@@ -10,14 +11,68 @@ var buttonSpecs = {
|
|
|
10
11
|
icon: (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "currentColor", viewBox: "0 0 16 16", children: [_jsx("path", { d: "M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5" }), _jsx("path", { d: "M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z" })] })),
|
|
11
12
|
},
|
|
12
13
|
};
|
|
13
|
-
// TODO: figure out tabindex and accessibility
|
|
14
14
|
var Toolbar = function (_a) {
|
|
15
15
|
var enabledFeatures = _a.enabledFeatures, option = _a.option, setOption = _a.setOption, toolbarClasses = _a.toolbarClasses, activeClasses = _a.activeClasses, inactiveClasses = _a.inactiveClasses;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
var enabledOptions = useMemo(function () {
|
|
17
|
+
return Object.keys(buttonSpecs).filter(function (toolbarOption) { return !!enabledFeatures[toolbarOption]; });
|
|
18
|
+
}, [enabledFeatures]);
|
|
19
|
+
var _b = useState(enabledOptions[0] || null), focusableOption = _b[0], setFocusableOption = _b[1];
|
|
20
|
+
var divRef = useRef(null);
|
|
21
|
+
// Deals with cases where selected option is no longer available due to enabledFeatures prop getting changed.
|
|
22
|
+
var actualOption = useMemo(function () {
|
|
23
|
+
if (focusableOption === null || !enabledOptions.includes(focusableOption)) {
|
|
24
|
+
return enabledOptions[0] || null;
|
|
25
|
+
}
|
|
26
|
+
return focusableOption;
|
|
27
|
+
}, [enabledOptions, focusableOption]);
|
|
28
|
+
var onKeydown = function (event) {
|
|
29
|
+
if (actualOption === null) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var currentIndex = enabledOptions.findIndex(function (option) { return option === actualOption; });
|
|
33
|
+
if (currentIndex === -1) {
|
|
34
|
+
// Should not happen due normalization of the value by the actualOption useMemo hook.
|
|
35
|
+
// This branch is put here anyway for explanatory purposes.
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (event.code === "ArrowLeft" && currentIndex - 1 < 0) {
|
|
39
|
+
setFocusableOption(enabledOptions[enabledOptions.length - 1]);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (event.code === "ArrowLeft" && currentIndex - 1 >= 0) {
|
|
43
|
+
setFocusableOption(enabledOptions[currentIndex - 1]);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (event.code === "ArrowRight" &&
|
|
47
|
+
currentIndex + 1 >= enabledOptions.length) {
|
|
48
|
+
setFocusableOption(enabledOptions[0]);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (event.code === "ArrowRight" &&
|
|
52
|
+
currentIndex + 1 < enabledOptions.length) {
|
|
53
|
+
setFocusableOption(enabledOptions[currentIndex + 1]);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
useEffect(function () {
|
|
58
|
+
if (actualOption === null) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (divRef.current === null) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!divRef.current.contains(document.activeElement)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
var focusTarget = divRef.current.querySelector(":scope > button[data-toolbar-option=\"".concat(actualOption, "\"]"));
|
|
68
|
+
if (focusTarget) {
|
|
69
|
+
focusTarget.focus();
|
|
70
|
+
}
|
|
71
|
+
}, [actualOption]);
|
|
72
|
+
return (_jsx("div", { ref: divRef, className: classNames(toolbarClasses || ["hstack", "gap-2", "justify-content-start", "px-2"]), role: "toolbar", onKeyDown: onKeydown, children: enabledOptions.map(function (toolbarOption) { return (_jsx("button", { tabIndex: actualOption === toolbarOption ? 0 : -1, "data-toolbar-option": toolbarOption, "aria-label": buttonSpecs[toolbarOption].label, "aria-roledescription": "Grouped toggle button to show/hide ".concat(toolbarOption, " UI"), "aria-pressed": option === toolbarOption, className: classNames.apply(void 0, (option === toolbarOption
|
|
19
73
|
? activeClasses || ["btn", "btn-outline-secondary", "active"]
|
|
20
74
|
: inactiveClasses || ["btn", "btn-outline-secondary"])), title: buttonSpecs[toolbarOption].label, onClick: function () {
|
|
75
|
+
setFocusableOption(toolbarOption);
|
|
21
76
|
setOption(option === toolbarOption
|
|
22
77
|
? null
|
|
23
78
|
: toolbarOption);
|
|
@@ -10,8 +10,6 @@ var ToolbarContainer = function (_a) {
|
|
|
10
10
|
!!interfaces[toolbarOption];
|
|
11
11
|
return prev;
|
|
12
12
|
}, {});
|
|
13
|
-
// TODO: mention in documentation that Bootstrap 5.3 is required due to the
|
|
14
|
-
// use of the z-index utility
|
|
15
13
|
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) || [
|
|
16
14
|
"position-absolute",
|
|
17
15
|
"z-1",
|
package/types.d.ts
CHANGED
|
@@ -16,17 +16,22 @@ export interface ColDefBase<ValueType = any> {
|
|
|
16
16
|
export type ColDef<ValueType = any> = ColDefBase<ValueType> & {
|
|
17
17
|
width?: number;
|
|
18
18
|
};
|
|
19
|
-
type ValidRowData = Record<string, any>;
|
|
19
|
+
export type ValidRowData = Record<string, any>;
|
|
20
20
|
export type RowData<Data extends ValidRowData = ValidRowData> = Data;
|
|
21
21
|
export type RowId = string | number;
|
|
22
22
|
export interface RowDef<Data extends ValidRowData = ValidRowData> {
|
|
23
23
|
id: RowId;
|
|
24
24
|
data: RowData<Data>;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
26
|
+
export type AugRowDef<Data extends ValidRowData = ValidRowData> = RowDef<Data> & {
|
|
27
|
+
origIndex: number;
|
|
28
|
+
};
|
|
29
|
+
export type PostPaginationRowDef<Data extends ValidRowData = ValidRowData> = AugRowDef & {
|
|
30
|
+
prePaginationIndex: number;
|
|
31
|
+
};
|
|
32
|
+
export type FormattedRow = {
|
|
27
33
|
contents: CellData[];
|
|
28
|
-
|
|
29
|
-
}
|
|
34
|
+
} & Omit<PostPaginationRowDef, "data">;
|
|
30
35
|
export type AugCellData = CellData & {
|
|
31
36
|
width?: number;
|
|
32
37
|
};
|
|
@@ -60,4 +65,3 @@ export interface ColHeaderCellProps {
|
|
|
60
65
|
additionalClasses?: string[];
|
|
61
66
|
width?: number;
|
|
62
67
|
}
|
|
63
|
-
export {};
|