@stenajs-webui/grid 14.0.2 → 14.1.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,6 +2,7 @@ import { ReactNode } from "react";
2
2
  import { StandardTableConfig } from "../config/StandardTableConfig";
3
3
  import { TableContext } from "../context/StandardTableStateContext";
4
4
  import { StandardTableOnKeyDown } from "../types/StandardTableOnKeyDown";
5
+ import { ResultListBannerState } from "@stenajs-webui/elements";
5
6
  export interface StandardTableProps<TItem, TColumnKey extends string, TColumnGroupKey extends string> {
6
7
  /**
7
8
  * Variant of table
@@ -50,6 +51,10 @@ export interface StandardTableProps<TItem, TColumnKey extends string, TColumnGro
50
51
  * Message displayed when there are no items to display, and it is not loading or has error.
51
52
  */
52
53
  noItemsLabel?: string;
54
+ /**
55
+ * Data used to populate the ResultListBanner component.
56
+ */
57
+ bannerError?: ResultListBannerState;
53
58
  /**
54
59
  * Message displayed when there is an error.
55
60
  */
@@ -3,5 +3,5 @@ import { StandardTableProps, StandardTableVariant } from "./StandardTable";
3
3
  interface Props<TItem, TColumnKey extends string, TColumnGroupKey extends string> extends Omit<StandardTableProps<TItem, TColumnKey, TColumnGroupKey>, "tableContext" | "config"> {
4
4
  variant: StandardTableVariant;
5
5
  }
6
- export declare const StandardTableContent: React.MemoExoticComponent<(<TItem, TColumnKey extends string, TColumnGroupKey extends string>({ error, errorLabel, loading, items, noItemsLabel, noItemsContentRight, noItemsContentBottom, noItemsHeader, colIndexOffset, rowIndexOffset, variant, }: Props<TItem, TColumnKey, TColumnGroupKey>) => JSX.Element)>;
6
+ export declare const StandardTableContent: React.MemoExoticComponent<(<TItem, TColumnKey extends string, TColumnGroupKey extends string>({ error, bannerError, loading, items, noItemsLabel, noItemsContentRight, noItemsContentBottom, noItemsHeader, colIndexOffset, rowIndexOffset, variant, errorLabel, }: Props<TItem, TColumnKey, TColumnGroupKey>) => JSX.Element)>;
7
7
  export {};
@@ -1,8 +1,10 @@
1
1
  import { ReactNode } from "react";
2
2
  import { UseGridCellOptions, UseGridCellResult } from "../../grid-cell/hooks/UseGridCell";
3
3
  import { SortOrderIconVariant } from "../../table-ui/components/table/SortOrderIcon";
4
- export declare type StandardTableColumnConfig<TItem, TItemValue> = StandardTableColumnOptions<TItem, TItemValue> & StandardTableColumnOptionsWithNoGroups & ItemValueResolver<TItem, TItemValue>;
5
- export declare type StandardTableColumnConfigWithGroups<TItem, TItemValue> = StandardTableColumnOptions<TItem, TItemValue> & ItemValueResolver<TItem, TItemValue>;
4
+ import { StandardTableOnKeyDownArgs } from "./StandardTableConfig";
5
+ import * as React from "react";
6
+ export declare type StandardTableColumnConfig<TItem, TItemValue, TColumnKey extends string> = StandardTableColumnOptions<TItem, TItemValue, TColumnKey> & StandardTableColumnOptionsWithNoGroups & ItemValueResolver<TItem, TItemValue>;
7
+ export declare type StandardTableColumnConfigWithGroups<TItem, TItemValue, TColumnKey extends string> = StandardTableColumnOptions<TItem, TItemValue, TColumnKey> & ItemValueResolver<TItem, TItemValue>;
6
8
  export interface StandardTableColumnOptionsWithNoGroups {
7
9
  /**
8
10
  * Enable sticky behaviour to the left make elements scroll in behind this column.
@@ -22,7 +24,7 @@ export interface StandardTableColumnOptionsWithNoGroups {
22
24
  */
23
25
  right?: string;
24
26
  }
25
- export interface StandardTableColumnOptions<TItem, TItemValue> {
27
+ export interface StandardTableColumnOptions<TItem, TItemValue, TColumnKey extends string> {
26
28
  /**
27
29
  * The header label of the column.
28
30
  */
@@ -80,10 +82,24 @@ export interface StandardTableColumnOptions<TItem, TItemValue> {
80
82
  * @param value
81
83
  */
82
84
  onChange?: (item: TItem, value: string | undefined) => void;
85
+ /**
86
+ * The onKeyDown callback on the HTML element with focus.
87
+ * @param ev
88
+ * @param args
89
+ */
90
+ onKeyDown?: (ev: React.KeyboardEvent<HTMLDivElement>, args: StandardTableOnKeyDownArgs<TItem, TColumnKey>) => void;
83
91
  /**
84
92
  * Disables the grid cell functionality for this column.
93
+ * If enable, the user can no longer navigate to or from this column with arrow keys.
94
+ * Focus highlight on the cell is also disabled.
85
95
  */
86
96
  disableGridCell?: boolean;
97
+ /**
98
+ * Grid cell is enabled, but arrow key logic and focus highlight must be applied manually.
99
+ * This makes it possible to move focus to an element inside the cell, instead of on the cell itself.
100
+ * For example, if the cell contains a checkbox, we user can arrow key navigate to the checkbox.
101
+ */
102
+ disableGridCellFocus?: boolean;
87
103
  /**
88
104
  * Grid cell options, if you need custom behaviour.
89
105
  * Not all options are available, since it is controlled by StandardTable.
@@ -134,4 +150,4 @@ export declare type BackgroundResolver<TItem> = (item: TItem) => string | undefi
134
150
  export interface ItemValueResolver<TItem, TItemValue> {
135
151
  itemValueResolver: (item: TItem) => TItemValue;
136
152
  }
137
- export declare const createColumnConfig: <TItem, TItemValue>(itemValueResolver: (item: TItem) => TItemValue, options?: StandardTableColumnOptions<TItem, TItemValue> | undefined) => StandardTableColumnConfig<TItem, TItemValue>;
153
+ export declare const createColumnConfig: <TItem, TItemValue, TColumnKey extends string>(itemValueResolver: (item: TItem) => TItemValue, options?: StandardTableColumnOptions<TItem, TItemValue, TColumnKey> | undefined) => StandardTableColumnConfig<TItem, TItemValue, TColumnKey>;
@@ -15,7 +15,7 @@ export interface StandardTableConfigWithGroups<TItem, TColumnKey extends string,
15
15
  /**
16
16
  * Configs for the columns available in the table.
17
17
  */
18
- columns: Record<TColumnKey, StandardTableColumnConfigWithGroups<TItem, any>>;
18
+ columns: Record<TColumnKey, StandardTableColumnConfigWithGroups<TItem, any, TColumnKey>>;
19
19
  /**
20
20
  * Configs for the column groups available in the table.
21
21
  * If column groups are used, columnOrder will not be used.
@@ -35,7 +35,7 @@ export interface StandardTableConfigWithNoGroups<TItem, TColumnKey extends strin
35
35
  /**
36
36
  * Configs for the columns available in the table.
37
37
  */
38
- columns: Record<TColumnKey, StandardTableColumnConfig<TItem, any>>;
38
+ columns: Record<TColumnKey, StandardTableColumnConfig<TItem, any, TColumnKey>>;
39
39
  /**
40
40
  * The order of the columns. This is a list of keys from `columns`.
41
41
  * If a column is not added, it is not displayed.
@@ -5,6 +5,6 @@ export declare type OffsetPerColumn<TColumnKey extends string> = Record<TColumnK
5
5
  * @param config
6
6
  */
7
7
  export declare const calculateOffsetForColumnInStickyColumnGroups: <TItem, TColumnKey extends string>(config: StandardTableConfigWithGroups<TItem, TColumnKey, string>) => Record<TColumnKey, string>;
8
- export declare const calculateOffsetForColumns: <TItem, TColumnKey extends string>(columnIds: TColumnKey[], columns: Record<TColumnKey, import("../../config/StandardTableColumnConfig").StandardTableColumnConfigWithGroups<TItem, any>> | Record<TColumnKey, import("../../config/StandardTableColumnConfig").StandardTableColumnConfig<TItem, any>>, includeOffsetForCheckboxAndExpand: boolean) => Record<TColumnKey, string>;
8
+ export declare const calculateOffsetForColumns: <TItem, TColumnKey extends string>(columnIds: TColumnKey[], columns: Record<TColumnKey, import("../../config/StandardTableColumnConfig").StandardTableColumnConfigWithGroups<TItem, any, TColumnKey>> | Record<TColumnKey, import("../../config/StandardTableColumnConfig").StandardTableColumnConfig<TItem, any, TColumnKey>>, includeOffsetForCheckboxAndExpand: boolean) => Record<TColumnKey, string>;
9
9
  export declare const getColumnIdsForLeftSideStickyGroup: <TItem, TColumnKey extends string>(config: StandardTableConfigWithGroups<TItem, TColumnKey, string>) => TColumnKey[];
10
10
  export declare const getColumnIdsForRightSideStickyGroup: <TItem, TColumnKey extends string>(config: StandardTableConfigWithGroups<TItem, TColumnKey, string>) => TColumnKey[];
@@ -1,3 +1,3 @@
1
1
  import { StandardTableColumnOptions } from "../../config/StandardTableColumnConfig";
2
- export declare const isSummaryRowVisible: <TColumnKey extends string>(columns: Record<TColumnKey, StandardTableColumnOptions<unknown, unknown>>) => boolean;
3
- export declare const columnHasSummaryCell: (columnConfig: StandardTableColumnOptions<unknown, unknown>) => boolean;
2
+ export declare const isSummaryRowVisible: <TColumnKey extends string>(columns: Record<TColumnKey, StandardTableColumnOptions<unknown, unknown, TColumnKey>>) => boolean;
3
+ export declare const columnHasSummaryCell: <TColumnKey extends string>(columnConfig: StandardTableColumnOptions<unknown, unknown, TColumnKey>) => boolean;
@@ -1,3 +1,3 @@
1
1
  import { StandardTableColumnConfig } from "../config/StandardTableColumnConfig";
2
2
  export declare const useCellBackgroundByColumnId: <T>(columnId: string, item: T) => string | undefined;
3
- export declare const useCellBackgroundByColumnConfig: <TItem, TItemValue>(columnConfig: StandardTableColumnConfig<TItem, TItemValue> | undefined, item: TItem) => string | undefined;
3
+ export declare const useCellBackgroundByColumnConfig: <TItem, TItemValue, TColumnKey extends string>(columnConfig: StandardTableColumnConfig<TItem, TItemValue, TColumnKey> | undefined, item: TItem) => string | undefined;
@@ -1,4 +1,4 @@
1
1
  import { StandardTableColumnConfig } from "../config/StandardTableColumnConfig";
2
- export declare const useColumnConfigById: <TItem, TItemValue>(columnId: string) => StandardTableColumnConfig<TItem, TItemValue>;
3
- export declare const useFirstColumnConfig: <TItem, TItemValue>() => StandardTableColumnConfig<TItem, TItemValue> | undefined;
4
- export declare const useLastColumnConfig: <TItem, TItemValue>() => StandardTableColumnConfig<TItem, TItemValue> | undefined;
2
+ export declare const useColumnConfigById: <TItem, TItemValue, TColumnKey extends string>(columnId: string) => StandardTableColumnConfig<TItem, TItemValue, TColumnKey>;
3
+ export declare const useFirstColumnConfig: <TItem, TItemValue, TColumnKey extends string>() => StandardTableColumnConfig<TItem, TItemValue, TColumnKey> | undefined;
4
+ export declare const useLastColumnConfig: <TItem, TItemValue, TColumnKey extends string>() => StandardTableColumnConfig<TItem, TItemValue, TColumnKey> | undefined;
@@ -6,6 +6,7 @@ export default _default;
6
6
  export declare const Overview: () => JSX.Element;
7
7
  export declare const Variants: () => JSX.Element;
8
8
  export declare const BackgroundResolver: () => JSX.Element;
9
+ export declare const CellOnKeyDown: () => JSX.Element;
9
10
  export declare const NavigationBetweenTables: () => JSX.Element;
10
11
  export declare const OnKeyDown: () => JSX.Element;
11
12
  export declare const SummaryRow: () => JSX.Element;
@@ -13,5 +13,6 @@ export declare const standardTableConfigForStories: StandardTableConfig<ListItem
13
13
  export declare const mockedItems: ListItem[];
14
14
  export declare const useListState: (initialItems: Array<ListItem>) => {
15
15
  onChangeNumPassengers: (item: ListItem, numPassengers: string | undefined) => void;
16
+ onChangeActive: (item: ListItem, active: boolean) => void;
16
17
  items: ListItem[];
17
18
  };
@@ -7,3 +7,4 @@ export declare const MissingItems: () => JSX.Element;
7
7
  export declare const MissingItemsCustomBanner: () => JSX.Element;
8
8
  export declare const Loading: () => JSX.Element;
9
9
  export declare const _Error: () => JSX.Element;
10
+ export declare const BannerError: () => JSX.Element;
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createContext, useMemo, createElement, Fragment, memo, useRef, useState, useCallback, useEffect, useContext, useReducer } from 'react';
2
2
  import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons/faExclamationTriangle';
3
- import { InputSpinner, Icon, stenaArrowRight, FlatButton, Banner } from '@stenajs-webui/elements';
3
+ import { InputSpinner, Icon, stenaArrowRight, FlatButton, ResultListBanner, Banner } from '@stenajs-webui/elements';
4
4
  import { cssColor } from '@stenajs-webui/theme';
5
5
  import { Tooltip, Popover } from '@stenajs-webui/tooltip';
6
6
  import { Text, Indent, Space, Row, Box, exhaustSwitchCaseElseThrow, Heading, useArraySet, useOnScreen, Spacing, booleanOrNumberToNumber, useDomId } from '@stenajs-webui/core';
@@ -18,7 +18,7 @@ import { TextInput, Checkbox } from '@stenajs-webui/forms';
18
18
  import { useDispatch, useSelector } from 'react-redux';
19
19
  import { createSortOrderActions, createSelectedIdsActions, createEntityActions, createSortOrderReducerInitialState, createSelectedIdsReducerInitialState, reducerIdGate, createSortOrderReducer, createSelectedIdsReducer, createEntityReducer, reducerIdGateAction } from '@stenajs-webui/redux';
20
20
  import { combineReducers } from 'redux';
21
- import { ErrorScreen, LoadingScreen } from '@stenajs-webui/panels';
21
+ import { LoadingScreen, ErrorScreen } from '@stenajs-webui/panels';
22
22
  import { compact, upperFirst, lowerCase } from 'lodash';
23
23
  import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
24
24
  import { faChevronRight } from '@fortawesome/free-solid-svg-icons/faChevronRight';
@@ -1506,14 +1506,14 @@ var StandardTableCell = memo(function StandardTableCell(_a) {
1506
1506
  var _c = useStandardTableConfig(), keyResolver = _c.keyResolver, enableGridCell = _c.enableGridCell, gridCellOptionsForTable = _c.gridCellOptions;
1507
1507
  var selectedIds = useStandardTableState().selectedIds.selectedIds;
1508
1508
  var tableId = useStandardTableId();
1509
- var onKeyDown = useOnKeyDownContext();
1509
+ var onKeyDownTable = useOnKeyDownContext();
1510
1510
  var numNavigableColumns = useColumnIndexPerColumnIdContext().numNavigableColumns;
1511
1511
  var stickyPropsPerColumnContext = useStickyPropsPerColumnContext();
1512
1512
  var isSelected = useMemo(function () {
1513
1513
  var itemId = keyResolver(item);
1514
1514
  return selectedIds.indexOf(itemId) >= 0;
1515
1515
  }, [item, keyResolver, selectedIds]);
1516
- var _d = useColumnConfigById(columnId), itemValueResolver = _d.itemValueResolver, itemLabelFormatter = _d.itemLabelFormatter, width = _d.width, minWidth = _d.minWidth, _e = _d.justifyContentCell, justifyContentCell = _e === void 0 ? "flex-start" : _e, borderLeft = _d.borderLeft, renderCell = _d.renderCell, gridCellOptionsForColumn = _d.gridCellOptions, isEditable = _d.isEditable, onChange = _d.onChange, disableGridCell = _d.disableGridCell, zIndex = _d.zIndex;
1516
+ var _d = useColumnConfigById(columnId), itemValueResolver = _d.itemValueResolver, itemLabelFormatter = _d.itemLabelFormatter, width = _d.width, minWidth = _d.minWidth, _e = _d.justifyContentCell, justifyContentCell = _e === void 0 ? "flex-start" : _e, borderLeft = _d.borderLeft, renderCell = _d.renderCell, gridCellOptionsForColumn = _d.gridCellOptions, isEditable = _d.isEditable, onChange = _d.onChange, onKeyDownCell = _d.onKeyDown, disableGridCell = _d.disableGridCell, disableGridCellFocus = _d.disableGridCellFocus, zIndex = _d.zIndex;
1517
1517
  var itemValue = useMemo(function () {
1518
1518
  if (itemValueResolver) {
1519
1519
  return itemValueResolver(item);
@@ -1534,8 +1534,13 @@ var StandardTableCell = memo(function StandardTableCell(_a) {
1534
1534
  ? isEditable(item)
1535
1535
  : undefined;
1536
1536
  var onKeyDownHandler = useCallback(function (ev) {
1537
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(ev, { columnId: columnId, item: item });
1538
- }, [onKeyDown, columnId, item]);
1537
+ onKeyDownTable === null || onKeyDownTable === void 0 ? void 0 : onKeyDownTable(ev, { columnId: columnId, item: item });
1538
+ onKeyDownCell === null || onKeyDownCell === void 0 ? void 0 : onKeyDownCell(ev, { columnId: columnId, item: item });
1539
+ if (ev.key !== "Tab" && (onKeyDownTable || onKeyDownCell)) {
1540
+ ev.preventDefault();
1541
+ ev.stopPropagation();
1542
+ }
1543
+ }, [onKeyDownTable, columnId, item, onKeyDownCell]);
1539
1544
  var gridCell = useGridCell(label, __assign(__assign({ colIndex: colIndex,
1540
1545
  rowIndex: rowIndex,
1541
1546
  numRows: numRows, numCols: numNavigableColumns, tableId: tableId, isEditable: editable, onChange: onChange
@@ -1585,7 +1590,7 @@ var StandardTableCell = memo(function StandardTableCell(_a) {
1585
1590
  height: "var(--current-row-height)",
1586
1591
  background: background,
1587
1592
  } },
1588
- createElement(StandardTableCellUi, { enableGridCell: enableGridCell && !disableGridCell, gridCellRequiredProps: gridCell.requiredProps, isEditing: gridCell.isEditing, width: width, minWidth: minWidth, justifyContent: justifyContentCell, onKeyDown: onKeyDownHandler }, content)));
1593
+ createElement(StandardTableCellUi, { enableGridCell: enableGridCell && !disableGridCell && !disableGridCellFocus, gridCellRequiredProps: gridCell.requiredProps, isEditing: gridCell.isEditing, width: width, minWidth: minWidth, justifyContent: justifyContentCell, onKeyDown: onKeyDownHandler }, content)));
1589
1594
  });
1590
1595
 
1591
1596
  var StandardTableRowExpansion = function StandardTableRowExpansion(_a) {
@@ -1904,14 +1909,24 @@ var StandardTableRowList = memo(function StandardTableRowList(_a) {
1904
1909
  });
1905
1910
 
1906
1911
  var StandardTableContent = memo(function StandardTableContent(_a) {
1907
- var error = _a.error, errorLabel = _a.errorLabel, loading = _a.loading, items = _a.items, _b = _a.noItemsLabel, noItemsLabel = _b === void 0 ? "There is no data available." : _b, noItemsContentRight = _a.noItemsContentRight, noItemsContentBottom = _a.noItemsContentBottom, noItemsHeader = _a.noItemsHeader, colIndexOffset = _a.colIndexOffset, rowIndexOffset = _a.rowIndexOffset, variant = _a.variant;
1912
+ var _b;
1913
+ var error = _a.error, bannerError = _a.bannerError, loading = _a.loading, items = _a.items, _c = _a.noItemsLabel, noItemsLabel = _c === void 0 ? "There is no data available." : _c, noItemsContentRight = _a.noItemsContentRight, noItemsContentBottom = _a.noItemsContentBottom, noItemsHeader = _a.noItemsHeader, colIndexOffset = _a.colIndexOffset, rowIndexOffset = _a.rowIndexOffset, variant = _a.variant, errorLabel = _a.errorLabel;
1908
1914
  var totalNumColumns = useTotalNumColumns();
1909
- if (error) {
1915
+ if (bannerError) {
1910
1916
  return (createElement("tbody", null,
1911
1917
  createElement("tr", null,
1912
1918
  createElement("td", { colSpan: totalNumColumns },
1913
- createElement(Spacing, { num: 4 },
1914
- createElement(ErrorScreen, { text: errorLabel || error.message }))))));
1919
+ createElement(Spacing, { num: 4, justifyContent: "center" },
1920
+ createElement(Box, { alignItems: "center" },
1921
+ createElement(ResultListBanner, { bannerState: bannerError, variant: "error" })))))));
1922
+ }
1923
+ if (error || errorLabel) {
1924
+ return (createElement("tbody", null,
1925
+ createElement("tr", null,
1926
+ createElement("td", { colSpan: totalNumColumns },
1927
+ createElement(Spacing, { num: 4, justifyContent: "center" },
1928
+ createElement(Box, { alignItems: "center" },
1929
+ createElement(Banner, { headerText: (_b = (error ? error.message : errorLabel)) !== null && _b !== void 0 ? _b : "Unknown error", variant: "error" })))))));
1915
1930
  }
1916
1931
  if (loading) {
1917
1932
  return (createElement("tbody", null,
@@ -2170,7 +2185,10 @@ var StandardTable = function StandardTable(_a) {
2170
2185
  return undefined;
2171
2186
  }
2172
2187
  catch (e) {
2173
- return e;
2188
+ if (e instanceof Error) {
2189
+ return e;
2190
+ }
2191
+ return new Error("Unknown error");
2174
2192
  }
2175
2193
  }, [config]);
2176
2194
  if (validationError) {