@redis-ui/table 2.18.0 → 2.23.2
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/dist/Table/Table.cjs +30 -4
- package/dist/Table/Table.context.d.ts +1 -0
- package/dist/Table/Table.d.ts +26 -21
- package/dist/Table/Table.js +30 -4
- package/dist/Table/Table.style.cjs +37 -9
- package/dist/Table/Table.style.d.ts +277 -5
- package/dist/Table/Table.style.js +37 -9
- package/dist/Table/Table.types.d.ts +3 -1
- package/dist/Table/components/Compose/Compose.cjs +4 -1
- package/dist/Table/components/Compose/Compose.d.ts +1 -1
- package/dist/Table/components/Compose/Compose.js +4 -1
- package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.cjs +20 -0
- package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.d.ts +8 -0
- package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.js +20 -0
- package/dist/Table/components/ExpandRowButton/ExpandAllRowsButton.test.d.ts +1 -0
- package/dist/Table/components/ExpandRowButton/useExpanderColumn.cjs +19 -0
- package/dist/Table/components/ExpandRowButton/useExpanderColumn.d.ts +6 -0
- package/dist/Table/components/ExpandRowButton/useExpanderColumn.js +19 -0
- package/dist/Table/components/ExpandRowButton/useExpanderColumn.test.d.ts +1 -0
- package/dist/Table/components/PluggableTable/compositionComponents.d.ts +6 -6
- package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.cjs +1 -0
- package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.d.ts +1 -1
- package/dist/Table/components/RowSelection/HeaderMultiRowSelectionButton.js +1 -0
- package/dist/Table/components/RowSelection/useRowSelectionColumn.cjs +26 -0
- package/dist/Table/components/RowSelection/useRowSelectionColumn.d.ts +8 -0
- package/dist/Table/components/RowSelection/useRowSelectionColumn.js +26 -0
- package/dist/Table/components/RowSelection/useRowSelectionColumn.test.d.ts +1 -0
- package/dist/Table/components/ShowOnRowHover/ShowOnRowHover.style.cjs +3 -1
- package/dist/Table/components/ShowOnRowHover/ShowOnRowHover.style.js +3 -1
- package/dist/Table/components/TableBody/TableBody.d.ts +1 -1
- package/dist/Table/components/TableBody/components/Compose/Compose.cjs +2 -3
- package/dist/Table/components/TableBody/components/Compose/Compose.js +2 -3
- package/dist/Table/components/TableBodyCell/TableBodyCell.cjs +1 -5
- package/dist/Table/components/TableBodyCell/TableBodyCell.d.ts +4 -7
- package/dist/Table/components/TableBodyCell/TableBodyCell.js +1 -5
- package/dist/Table/components/TableBodyCell/components/Compose/Compose.cjs +21 -1
- package/dist/Table/components/TableBodyCell/components/Compose/Compose.d.ts +8 -2
- package/dist/Table/components/TableBodyCell/components/Compose/Compose.js +21 -1
- package/dist/Table/components/TableBodyCell/components/Compose/Compose.test.d.ts +1 -0
- package/dist/Table/components/TableBodyRow/TableBodyRow.cjs +12 -2
- package/dist/Table/components/TableBodyRow/TableBodyRow.d.ts +3 -3
- package/dist/Table/components/TableBodyRow/TableBodyRow.js +12 -2
- package/dist/Table/components/TableBodyRow/components/Compose/Compose.d.ts +2 -1
- package/dist/Table/components/TableHeader/TableHeader.d.ts +3 -3
- package/dist/Table/components/TableHeader/components/Compose/Compose.d.ts +2 -1
- package/dist/Table/components/TableHeaderCell/SRSortingNotification.cjs +4 -5
- package/dist/Table/components/TableHeaderCell/SRSortingNotification.d.ts +1 -1
- package/dist/Table/components/TableHeaderCell/SRSortingNotification.js +4 -5
- package/dist/Table/components/TableHeaderCell/TableHeaderCell.cjs +2 -6
- package/dist/Table/components/TableHeaderCell/TableHeaderCell.d.ts +2 -2
- package/dist/Table/components/TableHeaderCell/TableHeaderCell.js +2 -6
- package/dist/Table/components/TableHeaderCell/components/Compose/Compose.cjs +13 -5
- package/dist/Table/components/TableHeaderCell/components/Compose/Compose.js +13 -5
- package/dist/Table/components/TableHeaderCell/components/Compose/Compose.test.d.ts +1 -0
- package/dist/Table/components/TableHeaderCell/components/Heading/Heading.cjs +6 -5
- package/dist/Table/components/TableHeaderCell/components/Heading/Heading.js +7 -6
- package/dist/Table/components/TableHeaderCell/components/SortableHeading/SortableHeading.d.ts +1 -1
- package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/Compose/Compose.cjs +1 -0
- package/dist/Table/components/TableHeaderCell/components/SortableHeading/components/Compose/Compose.js +1 -0
- package/dist/Table/components/TablePagination/TablePagination.cjs +4 -2
- package/dist/Table/components/TablePagination/TablePagination.js +4 -2
- package/dist/Table/components/TableRoot/TableRoot.cjs +9 -1
- package/dist/Table/components/TableRoot/TableRoot.d.ts +2 -1
- package/dist/Table/components/TableRoot/TableRoot.js +9 -1
- package/dist/Table/plugins/ExpandableRowPlugin.cjs +11 -5
- package/dist/Table/plugins/ExpandableRowPlugin.d.ts +7 -1
- package/dist/Table/plugins/ExpandableRowPlugin.js +11 -5
- package/dist/Table/plugins/PaginationPlugin.cjs +2 -0
- package/dist/Table/plugins/PaginationPlugin.d.ts +2 -1
- package/dist/Table/plugins/PaginationPlugin.js +2 -0
- package/dist/Table/plugins/RowNavigationPlugin.cjs +139 -0
- package/dist/Table/plugins/RowNavigationPlugin.d.ts +44 -0
- package/dist/Table/plugins/RowNavigationPlugin.js +139 -0
- package/dist/Table/plugins/SortingPlugin.cjs +1 -1
- package/dist/Table/plugins/SortingPlugin.d.ts +1 -1
- package/dist/Table/plugins/SortingPlugin.js +1 -1
- package/dist/Table/tanStackExtendedTypes.d.ts +9 -0
- package/dist/Table/utils/plugin.utils.d.ts +1 -1
- package/dist/Table/utils/table.utils.cjs +13 -0
- package/dist/Table/utils/table.utils.d.ts +2 -0
- package/dist/Table/utils/table.utils.js +13 -0
- package/dist/Table/utils/table.utils.test.d.ts +1 -0
- package/package.json +5 -5
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "../../../../../node_modules/react/jsx-runtime.js";
|
|
2
2
|
import { flexRender } from "../../../../../node_modules/@tanstack/react-table/build/lib/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isTextualNode } from "@redislabsdev/redis-ui-components";
|
|
4
4
|
import { VisuallyHidden } from "../../../../../node_modules/@radix-ui/react-visually-hidden/dist/index.js";
|
|
5
5
|
import { useTableHeaderCellContext } from "../../TableHeaderCell.context.js";
|
|
6
6
|
import { HeaderTitleWrapper } from "../../../../Table.style.js";
|
|
7
7
|
const DEFAULT_HIDDEN_HEADER = "Actions";
|
|
8
8
|
const TableHeaderCellHeading = (props) => {
|
|
9
|
-
var _a;
|
|
10
9
|
const {
|
|
11
10
|
header
|
|
12
11
|
} = useTableHeaderCellContext();
|
|
13
12
|
const content = flexRender(header.column.columnDef.header, header.getContext());
|
|
14
|
-
if (header.column.columnDef.isHeaderCustom)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
if (header.column.columnDef.isHeaderCustom) {
|
|
14
|
+
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {
|
|
15
|
+
children: content
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const text = typeof content === "string" ? content.trim() : content;
|
|
18
19
|
if (!text || header.column.columnDef.isHeaderHidden) {
|
|
19
20
|
return jsxRuntimeExports.jsx(VisuallyHidden, {
|
|
20
21
|
children: text || DEFAULT_HIDDEN_HEADER
|
package/dist/Table/components/TableHeaderCell/components/SortableHeading/SortableHeading.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ComposeElementProps } from '@redislabsdev/redis-ui-components';
|
|
3
3
|
export declare const SortableHeading: (({ children, ...restProps }: ComposeElementProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
4
|
-
Compose: ((props: ComposeElementProps<
|
|
4
|
+
Compose: ((props: ComposeElementProps<HTMLElement>) => import("react/jsx-runtime").JSX.Element) & {
|
|
5
5
|
SortIndicator: () => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
6
6
|
};
|
|
7
7
|
SortIndicator: () => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -14,6 +14,7 @@ const SortableHeadingCompose = Object.assign((props) => {
|
|
|
14
14
|
{
|
|
15
15
|
"aria-description": TableHeaderCell_utils.getColumnSortLabel(header, TableHeaderCell_utils.formatColumnSortNotification),
|
|
16
16
|
...props,
|
|
17
|
+
"$custom": header.column.columnDef.isHeaderCustom || false,
|
|
17
18
|
as: header.column.getCanSort() ? void 0 : "div"
|
|
18
19
|
}
|
|
19
20
|
);
|
|
@@ -12,6 +12,7 @@ const SortableHeadingCompose = Object.assign((props) => {
|
|
|
12
12
|
{
|
|
13
13
|
"aria-description": getColumnSortLabel(header, formatColumnSortNotification),
|
|
14
14
|
...props,
|
|
15
|
+
"$custom": header.column.columnDef.isHeaderCustom || false,
|
|
15
16
|
as: header.column.getCanSort() ? void 0 : "div"
|
|
16
17
|
}
|
|
17
18
|
);
|
|
@@ -7,8 +7,10 @@ const Compose = require("./components/Compose/Compose.cjs");
|
|
|
7
7
|
const TablePagination_style = require("./TablePagination.style.cjs");
|
|
8
8
|
const renderRowCount = ({
|
|
9
9
|
visibleItemCount,
|
|
10
|
-
totalItemCount
|
|
11
|
-
|
|
10
|
+
totalItemCount = 0,
|
|
11
|
+
pageCount,
|
|
12
|
+
pageSize
|
|
13
|
+
}) => totalItemCount > pageSize || pageCount === 1 ? `Showing ${visibleItemCount} out of ${totalItemCount} rows` : `Showing ${visibleItemCount} rows`;
|
|
12
14
|
const renderPageCount = ({
|
|
13
15
|
pageIndex,
|
|
14
16
|
pageCount
|
|
@@ -5,8 +5,10 @@ import { TablePaginationCompose } from "./components/Compose/Compose.js";
|
|
|
5
5
|
import { PaginationBar, InfoLabel, PageSelect, PageSizeSelect, NavigationButton, PageSizeGroup, PageNavGroup, PageSelectGroup } from "./TablePagination.style.js";
|
|
6
6
|
const renderRowCount = ({
|
|
7
7
|
visibleItemCount,
|
|
8
|
-
totalItemCount
|
|
9
|
-
|
|
8
|
+
totalItemCount = 0,
|
|
9
|
+
pageCount,
|
|
10
|
+
pageSize
|
|
11
|
+
}) => totalItemCount > pageSize || pageCount === 1 ? `Showing ${visibleItemCount} out of ${totalItemCount} rows` : `Showing ${visibleItemCount} rows`;
|
|
10
12
|
const renderPageCount = ({
|
|
11
13
|
pageIndex,
|
|
12
14
|
pageCount
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("../../../node_modules/react/jsx-runtime.cjs");
|
|
3
4
|
const Table_style = require("../../Table.style.cjs");
|
|
4
|
-
const
|
|
5
|
+
const RowNavigationPlugin = require("../../plugins/RowNavigationPlugin.cjs");
|
|
6
|
+
const TableRoot = (props) => {
|
|
7
|
+
const navigationProps = RowNavigationPlugin.useHandleRowNavigationOnTable(props);
|
|
8
|
+
return jsxRuntime.jsxRuntimeExports.jsx(Table_style.Table, {
|
|
9
|
+
...props,
|
|
10
|
+
...navigationProps
|
|
11
|
+
});
|
|
12
|
+
};
|
|
5
13
|
exports.TableRoot = TableRoot;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
export declare const TableRoot: (props: HTMLAttributes<HTMLTableElement>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../../../node_modules/react/jsx-runtime.js";
|
|
1
2
|
import { Table } from "../../Table.style.js";
|
|
2
|
-
|
|
3
|
+
import { useHandleRowNavigationOnTable } from "../../plugins/RowNavigationPlugin.js";
|
|
4
|
+
const TableRoot = (props) => {
|
|
5
|
+
const navigationProps = useHandleRowNavigationOnTable(props);
|
|
6
|
+
return jsxRuntimeExports.jsx(Table, {
|
|
7
|
+
...props,
|
|
8
|
+
...navigationProps
|
|
9
|
+
});
|
|
10
|
+
};
|
|
3
11
|
export {
|
|
4
12
|
TableRoot
|
|
5
13
|
};
|
|
@@ -7,21 +7,27 @@ const index = require("../../node_modules/@tanstack/table-core/build/lib/index.c
|
|
|
7
7
|
const getTrue = () => true;
|
|
8
8
|
const TableExpandableRowContextKey = "expandableRow";
|
|
9
9
|
const useExpandableRowPlugin = ({
|
|
10
|
+
defaultExpanded,
|
|
10
11
|
getRowCanExpand,
|
|
11
12
|
renderExpandedRow,
|
|
12
13
|
expandRowOnClick,
|
|
13
|
-
expandedRowComponent
|
|
14
|
+
expandedRowComponent,
|
|
15
|
+
getSubRows
|
|
14
16
|
}) => {
|
|
15
17
|
const clickablePluginData = ClickableRowPlugin.useClickableRowPlugin({
|
|
16
18
|
getCanRowClick: (row) => !!(expandRowOnClick && row.getCanExpand()),
|
|
17
19
|
onRowClick: (row) => row.toggleExpanded(),
|
|
18
20
|
shouldClickOnEnter: true
|
|
19
21
|
});
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
+
if (!renderExpandedRow && !getSubRows) return void 0;
|
|
23
|
+
return {
|
|
22
24
|
tableOptions: {
|
|
23
25
|
getExpandedRowModel: index.getExpandedRowModel(),
|
|
24
|
-
getRowCanExpand: getRowCanExpand || getTrue
|
|
26
|
+
getRowCanExpand: getRowCanExpand || (getSubRows ? void 0 : getTrue),
|
|
27
|
+
getSubRows,
|
|
28
|
+
initialState: defaultExpanded ? {
|
|
29
|
+
expanded: defaultExpanded
|
|
30
|
+
} : void 0
|
|
25
31
|
},
|
|
26
32
|
context: {
|
|
27
33
|
...plugin_utils.buildPluginContext(TableExpandableRowContextKey, {
|
|
@@ -30,7 +36,7 @@ const useExpandableRowPlugin = ({
|
|
|
30
36
|
}),
|
|
31
37
|
...expandRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
|
|
32
38
|
}
|
|
33
|
-
}
|
|
39
|
+
};
|
|
34
40
|
};
|
|
35
41
|
const useExpandableRowContext = () => Table_context.usePluginContext(TableExpandableRowContextKey);
|
|
36
42
|
exports.TableExpandableRowContextKey = TableExpandableRowContextKey;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import { type Row } from '@tanstack/react-table';
|
|
3
|
+
import { ExpandedState } from '@tanstack/table-core/src/features/RowExpanding';
|
|
3
4
|
import { TablePluginData } from '../utils/plugin.utils';
|
|
4
5
|
import type { TableExpandedRowProps } from '../components/TableExpandedRow';
|
|
5
6
|
export declare const TableExpandableRowContextKey = "expandableRow";
|
|
@@ -17,6 +18,11 @@ export interface TableExpandableRowParams<T extends object> extends TableExpanda
|
|
|
17
18
|
expandRowOnClick?: boolean;
|
|
18
19
|
/** Allows individual rows to be expandable */
|
|
19
20
|
getRowCanExpand?: (row: Row<T>) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Enables tree-list (hierarchical) data.<br/>
|
|
23
|
+
* When this prop is set, the `renderExpandedRow` and `expandedRowComponent` parameters are not used. */
|
|
24
|
+
getSubRows?: (rowData: T, index: number) => T[] | undefined;
|
|
25
|
+
defaultExpanded?: ExpandedState;
|
|
20
26
|
}
|
|
21
|
-
export declare const useExpandableRowPlugin: <T extends object>({ getRowCanExpand, renderExpandedRow, expandRowOnClick, expandedRowComponent }: TableExpandableRowParams<T>) => TablePluginData<T>;
|
|
27
|
+
export declare const useExpandableRowPlugin: <T extends object>({ defaultExpanded, getRowCanExpand, renderExpandedRow, expandRowOnClick, expandedRowComponent, getSubRows }: TableExpandableRowParams<T>) => TablePluginData<T>;
|
|
22
28
|
export declare const useExpandableRowContext: <T extends object>() => TableExpandableRowContext<T> | undefined;
|
|
@@ -5,21 +5,27 @@ import { getExpandedRowModel } from "../../node_modules/@tanstack/table-core/bui
|
|
|
5
5
|
const getTrue = () => true;
|
|
6
6
|
const TableExpandableRowContextKey = "expandableRow";
|
|
7
7
|
const useExpandableRowPlugin = ({
|
|
8
|
+
defaultExpanded,
|
|
8
9
|
getRowCanExpand,
|
|
9
10
|
renderExpandedRow,
|
|
10
11
|
expandRowOnClick,
|
|
11
|
-
expandedRowComponent
|
|
12
|
+
expandedRowComponent,
|
|
13
|
+
getSubRows
|
|
12
14
|
}) => {
|
|
13
15
|
const clickablePluginData = useClickableRowPlugin({
|
|
14
16
|
getCanRowClick: (row) => !!(expandRowOnClick && row.getCanExpand()),
|
|
15
17
|
onRowClick: (row) => row.toggleExpanded(),
|
|
16
18
|
shouldClickOnEnter: true
|
|
17
19
|
});
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
+
if (!renderExpandedRow && !getSubRows) return void 0;
|
|
21
|
+
return {
|
|
20
22
|
tableOptions: {
|
|
21
23
|
getExpandedRowModel: getExpandedRowModel(),
|
|
22
|
-
getRowCanExpand: getRowCanExpand || getTrue
|
|
24
|
+
getRowCanExpand: getRowCanExpand || (getSubRows ? void 0 : getTrue),
|
|
25
|
+
getSubRows,
|
|
26
|
+
initialState: defaultExpanded ? {
|
|
27
|
+
expanded: defaultExpanded
|
|
28
|
+
} : void 0
|
|
23
29
|
},
|
|
24
30
|
context: {
|
|
25
31
|
...buildPluginContext(TableExpandableRowContextKey, {
|
|
@@ -28,7 +34,7 @@ const useExpandableRowPlugin = ({
|
|
|
28
34
|
}),
|
|
29
35
|
...expandRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
|
|
30
36
|
}
|
|
31
|
-
}
|
|
37
|
+
};
|
|
32
38
|
};
|
|
33
39
|
const useExpandableRowContext = () => usePluginContext(TableExpandableRowContextKey);
|
|
34
40
|
export {
|
|
@@ -15,6 +15,7 @@ const usePaginationPlugin = ({
|
|
|
15
15
|
onPaginationChange,
|
|
16
16
|
manualPagination,
|
|
17
17
|
totalRowCount,
|
|
18
|
+
totalPageCount,
|
|
18
19
|
pageSizes,
|
|
19
20
|
paginationEnabled = (pagination || defaultPagination || onPaginationChange || pageSizes) !== void 0 || manualPagination !== void 0
|
|
20
21
|
}) => {
|
|
@@ -32,6 +33,7 @@ const usePaginationPlugin = ({
|
|
|
32
33
|
onPaginationChange: setPaginationState,
|
|
33
34
|
manualPagination,
|
|
34
35
|
rowCount: totalRowCount,
|
|
36
|
+
pageCount: totalPageCount,
|
|
35
37
|
autoResetPageIndex: false
|
|
36
38
|
},
|
|
37
39
|
context: plugin_utils.buildPluginContext(TablePaginationContextKey, {
|
|
@@ -11,6 +11,7 @@ export interface TablePaginationParams extends TablePaginationContext {
|
|
|
11
11
|
onPaginationChange?: (state: PaginationState) => void;
|
|
12
12
|
manualPagination?: boolean;
|
|
13
13
|
totalRowCount?: number;
|
|
14
|
+
totalPageCount?: number;
|
|
14
15
|
}
|
|
15
|
-
export declare const usePaginationPlugin: <T extends object>({ pagination, defaultPagination, onPaginationChange, manualPagination, totalRowCount, pageSizes, paginationEnabled }: TablePaginationParams) => TablePluginData<T>;
|
|
16
|
+
export declare const usePaginationPlugin: <T extends object>({ pagination, defaultPagination, onPaginationChange, manualPagination, totalRowCount, totalPageCount, pageSizes, paginationEnabled }: TablePaginationParams) => TablePluginData<T>;
|
|
16
17
|
export declare const usePaginationContext: () => TablePaginationContext | undefined;
|
|
@@ -13,6 +13,7 @@ const usePaginationPlugin = ({
|
|
|
13
13
|
onPaginationChange,
|
|
14
14
|
manualPagination,
|
|
15
15
|
totalRowCount,
|
|
16
|
+
totalPageCount,
|
|
16
17
|
pageSizes,
|
|
17
18
|
paginationEnabled = (pagination || defaultPagination || onPaginationChange || pageSizes) !== void 0 || manualPagination !== void 0
|
|
18
19
|
}) => {
|
|
@@ -30,6 +31,7 @@ const usePaginationPlugin = ({
|
|
|
30
31
|
onPaginationChange: setPaginationState,
|
|
31
32
|
manualPagination,
|
|
32
33
|
rowCount: totalRowCount,
|
|
34
|
+
pageCount: totalPageCount,
|
|
33
35
|
autoResetPageIndex: false
|
|
34
36
|
},
|
|
35
37
|
context: buildPluginContext(TablePaginationContextKey, {
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const redisUiComponents = require("@redislabsdev/redis-ui-components");
|
|
5
|
+
const index = require("../../node_modules/@radix-ui/react-compose-refs/dist/index.cjs");
|
|
6
|
+
const plugin_utils = require("../utils/plugin.utils.cjs");
|
|
7
|
+
const Table_context = require("../Table.context.cjs");
|
|
8
|
+
const TableRowNavigationContextKey = "RowNavigation";
|
|
9
|
+
const useRowNavigationPlugin = ({
|
|
10
|
+
enableRowNavigation = true
|
|
11
|
+
}) => {
|
|
12
|
+
const [activeRowId, setActiveRowId] = React.useState();
|
|
13
|
+
const rowRefs = React.useRef(/* @__PURE__ */ new Map());
|
|
14
|
+
const unregisterRow = React.useCallback((rowId) => {
|
|
15
|
+
rowRefs.current.delete(rowId);
|
|
16
|
+
}, []);
|
|
17
|
+
const registerRow = React.useCallback((rowId, rowEl) => {
|
|
18
|
+
if (rowEl) rowRefs.current.set(rowId, rowEl);
|
|
19
|
+
else unregisterRow(rowId);
|
|
20
|
+
}, [unregisterRow]);
|
|
21
|
+
const goToRowId = (rowId, noScroll) => {
|
|
22
|
+
var _a;
|
|
23
|
+
return rowId && ((_a = rowRefs.current.get(rowId)) == null ? void 0 : _a.focus({
|
|
24
|
+
preventScroll: noScroll
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
const getGoToRow = (getTargetRow) => (table) => {
|
|
28
|
+
const {
|
|
29
|
+
rows
|
|
30
|
+
} = table.getRowModel();
|
|
31
|
+
if (!rows.length) return false;
|
|
32
|
+
const targetRow = getTargetRow(rows);
|
|
33
|
+
if (!targetRow) return false;
|
|
34
|
+
setActiveRowId(targetRow.id);
|
|
35
|
+
goToRowId(targetRow.id);
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
const findActiveIndex = (rows) => rows.findIndex((row) => row.id === activeRowId);
|
|
39
|
+
const goToNextRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) + 1] || rows.at(0));
|
|
40
|
+
const goToPrevRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) - 1] || rows.at(-1));
|
|
41
|
+
const goToFirstRow = getGoToRow((rows) => rows.at(0));
|
|
42
|
+
const goToLastRow = getGoToRow((rows) => rows.at(-1));
|
|
43
|
+
return enableRowNavigation ? {
|
|
44
|
+
tableOptions: {},
|
|
45
|
+
context: plugin_utils.buildPluginContext(TableRowNavigationContextKey, {
|
|
46
|
+
registerRow,
|
|
47
|
+
unregisterRow,
|
|
48
|
+
activeRowId,
|
|
49
|
+
setActiveRowId,
|
|
50
|
+
goToNextRow,
|
|
51
|
+
goToPrevRow,
|
|
52
|
+
goToFirstRow,
|
|
53
|
+
goToLastRow,
|
|
54
|
+
goToRowId
|
|
55
|
+
})
|
|
56
|
+
} : void 0;
|
|
57
|
+
};
|
|
58
|
+
const useRowNavigationContext = () => Table_context.usePluginContext(TableRowNavigationContextKey);
|
|
59
|
+
const useHandleRowNavigationOnRow = ({
|
|
60
|
+
row,
|
|
61
|
+
onFocus,
|
|
62
|
+
ref
|
|
63
|
+
}) => {
|
|
64
|
+
const {
|
|
65
|
+
registerRow,
|
|
66
|
+
setActiveRowId,
|
|
67
|
+
activeRowId
|
|
68
|
+
} = useRowNavigationContext() || {};
|
|
69
|
+
const innerRowRef = registerRow && ((rowEl) => registerRow(row.id, rowEl));
|
|
70
|
+
const composedRowRef = index.useComposedRefs(ref, innerRowRef);
|
|
71
|
+
const handleFocus = redisUiComponents.combineHandlers(setActiveRowId && (() => setActiveRowId(row.id)), onFocus);
|
|
72
|
+
return {
|
|
73
|
+
ref: composedRowRef,
|
|
74
|
+
onFocus: handleFocus,
|
|
75
|
+
...setActiveRowId && {
|
|
76
|
+
tabIndex: activeRowId === row.id ? 0 : -1
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const useHandleRowNavigationOnTable = ({
|
|
81
|
+
onKeyDown,
|
|
82
|
+
onFocus
|
|
83
|
+
}) => {
|
|
84
|
+
const {
|
|
85
|
+
table
|
|
86
|
+
} = Table_context.useTableContext();
|
|
87
|
+
const nav = useRowNavigationContext();
|
|
88
|
+
if (!nav) {
|
|
89
|
+
return {
|
|
90
|
+
...onKeyDown && {
|
|
91
|
+
onKeyDown
|
|
92
|
+
},
|
|
93
|
+
...onFocus && {
|
|
94
|
+
onFocus
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const {
|
|
99
|
+
goToNextRow,
|
|
100
|
+
goToPrevRow,
|
|
101
|
+
goToFirstRow,
|
|
102
|
+
goToLastRow,
|
|
103
|
+
goToRowId,
|
|
104
|
+
activeRowId
|
|
105
|
+
} = nav;
|
|
106
|
+
const handleKeyDown = redisUiComponents.combineHandlers((e) => {
|
|
107
|
+
if (e.key === "ArrowDown") {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
goToNextRow(table);
|
|
110
|
+
}
|
|
111
|
+
if (e.key === "ArrowUp") {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
goToPrevRow(table);
|
|
114
|
+
}
|
|
115
|
+
if (e.key === "Home") {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
goToFirstRow(table);
|
|
118
|
+
}
|
|
119
|
+
if (e.key === "End") {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
goToLastRow(table);
|
|
122
|
+
}
|
|
123
|
+
}, onKeyDown);
|
|
124
|
+
const handleFocus = redisUiComponents.combineHandlers((e) => {
|
|
125
|
+
if (e.target === e.currentTarget) {
|
|
126
|
+
goToRowId(activeRowId, !e.target.matches(":focus-visible"));
|
|
127
|
+
}
|
|
128
|
+
}, onFocus);
|
|
129
|
+
return {
|
|
130
|
+
onKeyDown: handleKeyDown,
|
|
131
|
+
onFocus: handleFocus,
|
|
132
|
+
tabIndex: 0
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.TableRowNavigationContextKey = TableRowNavigationContextKey;
|
|
136
|
+
exports.useHandleRowNavigationOnRow = useHandleRowNavigationOnRow;
|
|
137
|
+
exports.useHandleRowNavigationOnTable = useHandleRowNavigationOnTable;
|
|
138
|
+
exports.useRowNavigationContext = useRowNavigationContext;
|
|
139
|
+
exports.useRowNavigationPlugin = useRowNavigationPlugin;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FocusEventHandler, KeyboardEventHandler, Ref } from 'react';
|
|
2
|
+
import { Row, Table } from '@tanstack/react-table';
|
|
3
|
+
import { TablePluginData } from '../utils/plugin.utils';
|
|
4
|
+
export declare const TableRowNavigationContextKey = "RowNavigation";
|
|
5
|
+
export type TableRowNavigationContext = {
|
|
6
|
+
registerRow: (rowId: string, rowEl: HTMLTableRowElement | null) => void;
|
|
7
|
+
unregisterRow: (rowId: string) => void;
|
|
8
|
+
activeRowId: string | undefined;
|
|
9
|
+
setActiveRowId: (rowId: string) => void;
|
|
10
|
+
goToNextRow: (table: Table<object>) => void;
|
|
11
|
+
goToPrevRow: (table: Table<object>) => void;
|
|
12
|
+
goToFirstRow: (table: Table<object>) => void;
|
|
13
|
+
goToLastRow: (table: Table<object>) => void;
|
|
14
|
+
goToRowId: (rowId: string | undefined, noScroll?: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
export type TableRowNavigationParams = {
|
|
17
|
+
enableRowNavigation?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const useRowNavigationPlugin: <T extends object>({ enableRowNavigation }: TableRowNavigationParams) => TablePluginData<T>;
|
|
20
|
+
export declare const useRowNavigationContext: () => TableRowNavigationContext | undefined;
|
|
21
|
+
type UseHandleRowNavigationOnRowParams<T extends object> = {
|
|
22
|
+
row: Row<T>;
|
|
23
|
+
onFocus?: FocusEventHandler<HTMLTableRowElement>;
|
|
24
|
+
ref?: Ref<HTMLTableRowElement>;
|
|
25
|
+
};
|
|
26
|
+
export declare const useHandleRowNavigationOnRow: <T extends object>({ row, onFocus, ref }: UseHandleRowNavigationOnRowParams<T>) => {
|
|
27
|
+
tabIndex?: number | undefined;
|
|
28
|
+
ref: (node: HTMLTableRowElement) => void;
|
|
29
|
+
onFocus: FocusEventHandler<HTMLTableRowElement> | undefined;
|
|
30
|
+
};
|
|
31
|
+
type UseHandleRowNavigationOnTableParams = {
|
|
32
|
+
onKeyDown?: KeyboardEventHandler<HTMLTableElement>;
|
|
33
|
+
onFocus?: FocusEventHandler<HTMLTableElement>;
|
|
34
|
+
};
|
|
35
|
+
export declare const useHandleRowNavigationOnTable: ({ onKeyDown, onFocus }: UseHandleRowNavigationOnTableParams) => {
|
|
36
|
+
onFocus?: FocusEventHandler<HTMLTableElement> | undefined;
|
|
37
|
+
onKeyDown?: KeyboardEventHandler<HTMLTableElement> | undefined;
|
|
38
|
+
tabIndex?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
onKeyDown: KeyboardEventHandler<HTMLTableElement> | undefined;
|
|
41
|
+
onFocus: FocusEventHandler<HTMLTableElement> | undefined;
|
|
42
|
+
tabIndex: number;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useState, useRef, useCallback } from "react";
|
|
2
|
+
import { combineHandlers } from "@redislabsdev/redis-ui-components";
|
|
3
|
+
import { useComposedRefs } from "../../node_modules/@radix-ui/react-compose-refs/dist/index.js";
|
|
4
|
+
import { buildPluginContext } from "../utils/plugin.utils.js";
|
|
5
|
+
import { usePluginContext, useTableContext } from "../Table.context.js";
|
|
6
|
+
const TableRowNavigationContextKey = "RowNavigation";
|
|
7
|
+
const useRowNavigationPlugin = ({
|
|
8
|
+
enableRowNavigation = true
|
|
9
|
+
}) => {
|
|
10
|
+
const [activeRowId, setActiveRowId] = useState();
|
|
11
|
+
const rowRefs = useRef(/* @__PURE__ */ new Map());
|
|
12
|
+
const unregisterRow = useCallback((rowId) => {
|
|
13
|
+
rowRefs.current.delete(rowId);
|
|
14
|
+
}, []);
|
|
15
|
+
const registerRow = useCallback((rowId, rowEl) => {
|
|
16
|
+
if (rowEl) rowRefs.current.set(rowId, rowEl);
|
|
17
|
+
else unregisterRow(rowId);
|
|
18
|
+
}, [unregisterRow]);
|
|
19
|
+
const goToRowId = (rowId, noScroll) => {
|
|
20
|
+
var _a;
|
|
21
|
+
return rowId && ((_a = rowRefs.current.get(rowId)) == null ? void 0 : _a.focus({
|
|
22
|
+
preventScroll: noScroll
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
const getGoToRow = (getTargetRow) => (table) => {
|
|
26
|
+
const {
|
|
27
|
+
rows
|
|
28
|
+
} = table.getRowModel();
|
|
29
|
+
if (!rows.length) return false;
|
|
30
|
+
const targetRow = getTargetRow(rows);
|
|
31
|
+
if (!targetRow) return false;
|
|
32
|
+
setActiveRowId(targetRow.id);
|
|
33
|
+
goToRowId(targetRow.id);
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
const findActiveIndex = (rows) => rows.findIndex((row) => row.id === activeRowId);
|
|
37
|
+
const goToNextRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) + 1] || rows.at(0));
|
|
38
|
+
const goToPrevRow = getGoToRow((rows) => activeRowId && rows[findActiveIndex(rows) - 1] || rows.at(-1));
|
|
39
|
+
const goToFirstRow = getGoToRow((rows) => rows.at(0));
|
|
40
|
+
const goToLastRow = getGoToRow((rows) => rows.at(-1));
|
|
41
|
+
return enableRowNavigation ? {
|
|
42
|
+
tableOptions: {},
|
|
43
|
+
context: buildPluginContext(TableRowNavigationContextKey, {
|
|
44
|
+
registerRow,
|
|
45
|
+
unregisterRow,
|
|
46
|
+
activeRowId,
|
|
47
|
+
setActiveRowId,
|
|
48
|
+
goToNextRow,
|
|
49
|
+
goToPrevRow,
|
|
50
|
+
goToFirstRow,
|
|
51
|
+
goToLastRow,
|
|
52
|
+
goToRowId
|
|
53
|
+
})
|
|
54
|
+
} : void 0;
|
|
55
|
+
};
|
|
56
|
+
const useRowNavigationContext = () => usePluginContext(TableRowNavigationContextKey);
|
|
57
|
+
const useHandleRowNavigationOnRow = ({
|
|
58
|
+
row,
|
|
59
|
+
onFocus,
|
|
60
|
+
ref
|
|
61
|
+
}) => {
|
|
62
|
+
const {
|
|
63
|
+
registerRow,
|
|
64
|
+
setActiveRowId,
|
|
65
|
+
activeRowId
|
|
66
|
+
} = useRowNavigationContext() || {};
|
|
67
|
+
const innerRowRef = registerRow && ((rowEl) => registerRow(row.id, rowEl));
|
|
68
|
+
const composedRowRef = useComposedRefs(ref, innerRowRef);
|
|
69
|
+
const handleFocus = combineHandlers(setActiveRowId && (() => setActiveRowId(row.id)), onFocus);
|
|
70
|
+
return {
|
|
71
|
+
ref: composedRowRef,
|
|
72
|
+
onFocus: handleFocus,
|
|
73
|
+
...setActiveRowId && {
|
|
74
|
+
tabIndex: activeRowId === row.id ? 0 : -1
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const useHandleRowNavigationOnTable = ({
|
|
79
|
+
onKeyDown,
|
|
80
|
+
onFocus
|
|
81
|
+
}) => {
|
|
82
|
+
const {
|
|
83
|
+
table
|
|
84
|
+
} = useTableContext();
|
|
85
|
+
const nav = useRowNavigationContext();
|
|
86
|
+
if (!nav) {
|
|
87
|
+
return {
|
|
88
|
+
...onKeyDown && {
|
|
89
|
+
onKeyDown
|
|
90
|
+
},
|
|
91
|
+
...onFocus && {
|
|
92
|
+
onFocus
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const {
|
|
97
|
+
goToNextRow,
|
|
98
|
+
goToPrevRow,
|
|
99
|
+
goToFirstRow,
|
|
100
|
+
goToLastRow,
|
|
101
|
+
goToRowId,
|
|
102
|
+
activeRowId
|
|
103
|
+
} = nav;
|
|
104
|
+
const handleKeyDown = combineHandlers((e) => {
|
|
105
|
+
if (e.key === "ArrowDown") {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
goToNextRow(table);
|
|
108
|
+
}
|
|
109
|
+
if (e.key === "ArrowUp") {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
goToPrevRow(table);
|
|
112
|
+
}
|
|
113
|
+
if (e.key === "Home") {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
goToFirstRow(table);
|
|
116
|
+
}
|
|
117
|
+
if (e.key === "End") {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
goToLastRow(table);
|
|
120
|
+
}
|
|
121
|
+
}, onKeyDown);
|
|
122
|
+
const handleFocus = combineHandlers((e) => {
|
|
123
|
+
if (e.target === e.currentTarget) {
|
|
124
|
+
goToRowId(activeRowId, !e.target.matches(":focus-visible"));
|
|
125
|
+
}
|
|
126
|
+
}, onFocus);
|
|
127
|
+
return {
|
|
128
|
+
onKeyDown: handleKeyDown,
|
|
129
|
+
onFocus: handleFocus,
|
|
130
|
+
tabIndex: 0
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
export {
|
|
134
|
+
TableRowNavigationContextKey,
|
|
135
|
+
useHandleRowNavigationOnRow,
|
|
136
|
+
useHandleRowNavigationOnTable,
|
|
137
|
+
useRowNavigationContext,
|
|
138
|
+
useRowNavigationPlugin
|
|
139
|
+
};
|
|
@@ -13,7 +13,7 @@ const useSortingPlugin = ({
|
|
|
13
13
|
manualSorting = false,
|
|
14
14
|
enableSorting = true
|
|
15
15
|
// added plugin is enabled by default
|
|
16
|
-
}) => {
|
|
16
|
+
} = {}) => {
|
|
17
17
|
const [sortedByUser, setSortedByUser] = React.useState(false);
|
|
18
18
|
const [sortingState, setSortingState] = index.useControllableState({
|
|
19
19
|
prop: sorting,
|
|
@@ -14,5 +14,5 @@ export interface TableSortingParams {
|
|
|
14
14
|
/** Set false to disable sorting */
|
|
15
15
|
enableSorting?: boolean;
|
|
16
16
|
}
|
|
17
|
-
export declare const useSortingPlugin: <T extends object>({ defaultSorting, onSortingChange, sorting, manualSorting, enableSorting }
|
|
17
|
+
export declare const useSortingPlugin: <T extends object>({ defaultSorting, onSortingChange, sorting, manualSorting, enableSorting }?: TableSortingParams) => TablePluginData<T>;
|
|
18
18
|
export declare const useSortingContext: () => TableSortingContext | undefined;
|
|
@@ -11,7 +11,7 @@ const useSortingPlugin = ({
|
|
|
11
11
|
manualSorting = false,
|
|
12
12
|
enableSorting = true
|
|
13
13
|
// added plugin is enabled by default
|
|
14
|
-
}) => {
|
|
14
|
+
} = {}) => {
|
|
15
15
|
const [sortedByUser, setSortedByUser] = useState(false);
|
|
16
16
|
const [sortingState, setSortingState] = useControllableState({
|
|
17
17
|
prop: sorting,
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import '@tanstack/table-core';
|
|
2
|
+
import { Cell, Header } from '@tanstack/react-table';
|
|
3
|
+
import { HTMLAttributes } from 'react';
|
|
2
4
|
declare module '@tanstack/table-core' {
|
|
5
|
+
type CellSizingUnits = 'fraction' | 'px' | 'rem';
|
|
3
6
|
interface StringHeaderIdentifier {
|
|
4
7
|
isHeaderHidden?: boolean;
|
|
5
8
|
isHeaderCustom?: boolean;
|
|
9
|
+
sizeUnit?: CellSizingUnits;
|
|
10
|
+
getHeaderCellProps?: VoidFunction;
|
|
11
|
+
getCellProps?: VoidFunction;
|
|
6
12
|
}
|
|
7
13
|
interface IdIdentifier<TData, TValue> {
|
|
8
14
|
isHeaderHidden?: boolean;
|
|
9
15
|
isHeaderCustom?: boolean;
|
|
16
|
+
sizeUnit?: CellSizingUnits;
|
|
17
|
+
getHeaderCellProps?: (header: Header<TData, unknown>) => HTMLAttributes<HTMLTableCellElement> & Record<string, unknown>;
|
|
18
|
+
getCellProps?: (data: TData, cell: Cell<TData, unknown>) => HTMLAttributes<HTMLTableCellElement> & Record<string, unknown>;
|
|
10
19
|
}
|
|
11
20
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TableOptions } from '@tanstack/table-core';
|
|
2
2
|
import { RowData } from '@tanstack/react-table';
|
|
3
|
-
export type PartialTableOptions<T extends RowData> = Partial<Omit<TableOptions<T>, 'columns' | 'data' | 'getRowId' | '
|
|
3
|
+
export type PartialTableOptions<T extends RowData> = Partial<Omit<TableOptions<T>, 'columns' | 'data' | 'getRowId' | 'onStateChange' | 'getCoreRowModel' | 'defaultColumn' | 'debugTable' | 'debugRows' | 'debugHeaders' | 'debugColumns' | 'debugCells' | 'debugAll' | 'autoResetAll' | 'meta'>>;
|
|
4
4
|
export type TablePluginData<T extends RowData> = {
|
|
5
5
|
/** Partial table options that will be smartly merged with other table options */
|
|
6
6
|
tableOptions: PartialTableOptions<T>;
|