@vinorcola/dynamic-table 1.2.1 → 1.2.3
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/lib/Controller.d.ts +9 -0
- package/lib/Controller.js +29 -0
- package/lib/DefaultTheme.d.ts +7 -6
- package/lib/DefaultTheme.js +3 -23
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -3
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BaseItem } from "./index.js";
|
|
2
|
+
import type { InternalColumns } from "./useColumns.js";
|
|
3
|
+
interface Props<Item extends BaseItem> {
|
|
4
|
+
columns: InternalColumns<Item>;
|
|
5
|
+
clearFilterState: () => void;
|
|
6
|
+
clearSortState: () => void;
|
|
7
|
+
}
|
|
8
|
+
export default function Controller<Item extends BaseItem>(props: Props<Item>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import cx from "@vinorcola/utils/classNames";
|
|
3
|
+
import { CloseIcon, ColumnsIcon, FilterIcon, SortIcon } from "./Icon.js";
|
|
4
|
+
import { usePopup } from "./UniquePopupProvider.js";
|
|
5
|
+
import DynamicTable from "./index.js";
|
|
6
|
+
import { isSearchable, isSelectable } from "./useFilterState.js";
|
|
7
|
+
import { isMaskable } from "./useMaskableColumns.js";
|
|
8
|
+
import { isSortable } from "./useSortState.js";
|
|
9
|
+
export default function Controller(props) {
|
|
10
|
+
const columnListPopup = usePopup();
|
|
11
|
+
const hasHiddenColumns = props.columns.some((column) => isMaskable(column) && !column.displayed);
|
|
12
|
+
const hasFilteredColumns = props.columns.some((column) => (isSearchable(column) && column.searchText !== null) ||
|
|
13
|
+
(isSelectable(column) && column.hiddenValues.length > 0));
|
|
14
|
+
const hasHiddenFilteredColumns = hasHiddenColumns &&
|
|
15
|
+
hasFilteredColumns &&
|
|
16
|
+
props.columns.some((column) => isMaskable(column) &&
|
|
17
|
+
!column.displayed &&
|
|
18
|
+
((isSearchable(column) && column.searchText !== null) ||
|
|
19
|
+
(isSelectable(column) && column.hiddenValues.length > 0)));
|
|
20
|
+
const hasSortedColumns = props.columns.some((column) => isSortable(column) && column.sorted !== null);
|
|
21
|
+
const hasHiddenSortedColumns = hasHiddenColumns &&
|
|
22
|
+
hasSortedColumns &&
|
|
23
|
+
props.columns.some((column) => isMaskable(column) && !column.displayed && isSortable(column) && column.sorted !== null);
|
|
24
|
+
return (_jsx(DynamicTable.ControllerContainer, { filterButton: _jsx(DynamicTable.Button, { className: cx(hasHiddenFilteredColumns
|
|
25
|
+
? "[--bg-color:var(--color-orange-400)]"
|
|
26
|
+
: hasFilteredColumns && "[--bg-color:var(--color-lime-400)]"), disabled: !hasFilteredColumns, hoverChildren: _jsx(CloseIcon, {}), onClick: props.clearFilterState, children: _jsx(FilterIcon, {}) }), sortButton: _jsx(DynamicTable.Button, { className: cx(hasHiddenSortedColumns
|
|
27
|
+
? "[--bg-color:var(--color-orange-400)]"
|
|
28
|
+
: hasSortedColumns && "[--bg-color:var(--color-sky-400)]"), disabled: !hasSortedColumns, hoverChildren: _jsx(CloseIcon, {}), onClick: props.clearSortState, children: _jsx(SortIcon, {}) }), columnButton: _jsx(DynamicTable.Button, { className: cx(hasHiddenColumns ? "[--bg-color:var(--color-orange-400)]" : "[--bg-default-color:transparent]"), onClick: columnListPopup.show, children: _jsx(ColumnsIcon, {}) }), columnPopup: columnListPopup.display ? (_jsx(DynamicTable.ColumnsPopup, { columns: props.columns, onDismiss: columnListPopup.dismiss })) : undefined }));
|
|
29
|
+
}
|
package/lib/DefaultTheme.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
2
|
import type { BaseItem, Dictionary, Primitive } from "./index.js";
|
|
3
3
|
import type { InternalColumn, InternalColumns } from "./useColumns.js";
|
|
4
4
|
import { type FilterType } from "./useFilterState.js";
|
|
@@ -7,12 +7,13 @@ export interface Props {
|
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
}
|
|
9
9
|
export declare function TableContainer(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export interface
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export interface ControllerButtonsGroupProps {
|
|
11
|
+
filterButton: ReactElement;
|
|
12
|
+
sortButton: ReactElement;
|
|
13
|
+
columnButton: ReactElement;
|
|
14
|
+
columnPopup?: ReactElement;
|
|
14
15
|
}
|
|
15
|
-
export declare function
|
|
16
|
+
export declare function ControllerContainer(props: ControllerButtonsGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
16
17
|
export interface ColumnsPopupProps<Item extends BaseItem> {
|
|
17
18
|
columns: InternalColumns<Item>;
|
|
18
19
|
onDismiss: () => void;
|
package/lib/DefaultTheme.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import cx from "@vinorcola/utils/classNames";
|
|
3
3
|
import { useEffect, useMemo } from "react";
|
|
4
|
-
import { AscSortIcon, CheckedIcon,
|
|
4
|
+
import { AscSortIcon, CheckedIcon, DescSortIcon, FilterIcon, HideIcon, NextIcon, PreviousIcon, SearchIcon, UncheckedIcon, } from "./Icon.js";
|
|
5
5
|
import { usePopup } from "./UniquePopupProvider.js";
|
|
6
6
|
import DynamicTable from "./index.js";
|
|
7
7
|
import { isSearchable, isSelectable } from "./useFilterState.js";
|
|
@@ -10,28 +10,8 @@ import { isSortable } from "./useSortState.js";
|
|
|
10
10
|
export function TableContainer(props) {
|
|
11
11
|
return _jsx("div", { children: props.children });
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
const hasHiddenColumns = props.columns.some((column) => isMaskable(column) && !column.displayed);
|
|
16
|
-
const hasFilteredColumns = props.columns.some((column) => (isSearchable(column) && column.searchText !== null) ||
|
|
17
|
-
(isSelectable(column) && column.hiddenValues.length > 0));
|
|
18
|
-
const hasHiddenFilteredColumns = hasHiddenColumns &&
|
|
19
|
-
hasFilteredColumns &&
|
|
20
|
-
props.columns.some((column) => isMaskable(column) &&
|
|
21
|
-
!column.displayed &&
|
|
22
|
-
((isSearchable(column) && column.searchText !== null) ||
|
|
23
|
-
(isSelectable(column) && column.hiddenValues.length > 0)));
|
|
24
|
-
const hasSortedColumns = props.columns.some((column) => isSortable(column) && column.sorted !== null);
|
|
25
|
-
const hasHiddenSortedColumns = hasHiddenColumns &&
|
|
26
|
-
hasSortedColumns &&
|
|
27
|
-
props.columns.some((column) => isMaskable(column) && !column.displayed && isSortable(column) && column.sorted !== null);
|
|
28
|
-
return (_jsxs("div", { className: "relative", children: [_jsxs("ul", { className: "flex justify-end", children: [_jsx("li", { children: _jsx(DynamicTable.Button, { className: cx(hasHiddenFilteredColumns
|
|
29
|
-
? "[--bg-color:var(--color-orange-400)]"
|
|
30
|
-
: hasFilteredColumns && "[--bg-color:var(--color-lime-400)]"), disabled: !hasFilteredColumns, hoverChildren: _jsx(CloseIcon, {}), onClick: props.clearFilterState, children: _jsx(FilterIcon, {}) }) }), _jsx("li", { children: _jsx(DynamicTable.Button, { className: cx(hasHiddenSortedColumns
|
|
31
|
-
? "[--bg-color:var(--color-orange-400)]"
|
|
32
|
-
: hasSortedColumns && "[--bg-color:var(--color-sky-400)]"), disabled: !hasSortedColumns, hoverChildren: _jsx(CloseIcon, {}), onClick: props.clearSortState, children: _jsx(SortIcon, {}) }) }), _jsx("li", { children: _jsx(DynamicTable.Button, { className: cx(hasHiddenColumns
|
|
33
|
-
? "[--bg-color:var(--color-orange-400)]"
|
|
34
|
-
: "[--bg-default-color:transparent]"), onClick: columnListPopup.show, children: _jsx(ColumnsIcon, {}) }) })] }), columnListPopup.display && (_jsx(DynamicTable.ColumnsPopup, { columns: props.columns, onDismiss: columnListPopup.dismiss }))] }));
|
|
13
|
+
export function ControllerContainer(props) {
|
|
14
|
+
return (_jsxs("div", { className: "relative", children: [_jsxs("ul", { className: "flex justify-end", children: [_jsx("li", { children: props.filterButton }), _jsx("li", { children: props.sortButton }), _jsx("li", { children: props.columnButton })] }), props.columnPopup] }));
|
|
35
15
|
}
|
|
36
16
|
export function ColumnsPopup(props) {
|
|
37
17
|
return (_jsx(DynamicTable.Popup, { className: "right-2", onDismiss: props.onDismiss, children: _jsx("main", { children: _jsx("ul", { className: "min-w-40", children: props.columns.map((column) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type BaseItem = Record<string, any> & {
|
|
|
11
11
|
};
|
|
12
12
|
export type ItemKey<Item extends BaseItem> = Extract<keyof Item, string>;
|
|
13
13
|
export type { ColumnDefinition, ValueResolver } from "./ColumnDefinition.js";
|
|
14
|
-
export { default as Dictionary } from "./Dictionary.js";
|
|
14
|
+
export { default as Dictionary, DictionaryEntry } from "./Dictionary.js";
|
|
15
15
|
export type { FilterState } from "./useFilterState.js";
|
|
16
16
|
export type { SortDirection, SortState } from "./useSortState.js";
|
|
17
17
|
export type { ColumnsMaskState } from "./useMaskableColumns.js";
|
|
@@ -29,7 +29,7 @@ type Props<Item extends BaseItem> = BaseProps<Item> & SelectionOptions<Item>;
|
|
|
29
29
|
declare function DynamicTable<Item extends BaseItem>(props: Props<Item>): import("react/jsx-runtime").JSX.Element;
|
|
30
30
|
declare namespace DynamicTable {
|
|
31
31
|
var TableContainer: typeof import("./DefaultTheme.js").TableContainer;
|
|
32
|
-
var
|
|
32
|
+
var ControllerContainer: typeof import("./DefaultTheme.js").ControllerContainer;
|
|
33
33
|
var ColumnsPopup: typeof import("./DefaultTheme.js").ColumnsPopup;
|
|
34
34
|
var Table: typeof import("./DefaultTheme.js").Table;
|
|
35
35
|
var HeaderContainer: typeof import("./DefaultTheme.js").HeaderContainer;
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import Controller from "./Controller.js";
|
|
3
|
+
import { BodyContainer, Button, Cell, ClickableCell, ColumnsPopup, ControllerContainer, FooterContainer, Header, HeaderActions, HeaderContainer, HeaderLine, HeaderStatus, ItemsPerPageSelector, Line, Loader, PageButton, PageSelector, Popup, SearchFilterPopup, SelectionCell, SelectionFilterPopup, SelectionHeader, Table, TableContainer, } from "./DefaultTheme.js";
|
|
3
4
|
import UniquePopupProvider from "./UniquePopupProvider.js";
|
|
4
5
|
import useColumns from "./useColumns.js";
|
|
5
6
|
import useFilterState from "./useFilterState.js";
|
|
@@ -17,13 +18,13 @@ export default function DynamicTable(props) {
|
|
|
17
18
|
const { allColumns, columns: displayedColumns, items: displayedItems, } = useMaskableColumns(sortedColumns, sortedItems, props.initialColumnsMaskState);
|
|
18
19
|
const { items: paginatedItems, itemsPerPage, onItemsPerPageChange, totalPages, currentPage, onCurrentPageChange, } = usePagination(displayedItems, props.initialPaginationState);
|
|
19
20
|
const { isInSelectionMode, totalSelectedQuantity, unvisibleSelectedQuantity, isItemSelected, onItemSelectionToggle, } = useSelection(props, paginatedItems);
|
|
20
|
-
return (_jsx(UniquePopupProvider, { children: _jsxs(DynamicTable.TableContainer, { children: [_jsx(
|
|
21
|
+
return (_jsx(UniquePopupProvider, { children: _jsxs(DynamicTable.TableContainer, { children: [_jsx(Controller, { columns: allColumns, clearFilterState: clearFilterState, clearSortState: clearSortState }), _jsxs(DynamicTable.Table, { children: [_jsx(DynamicTable.HeaderContainer, { children: _jsxs(DynamicTable.HeaderLine, { children: [isInSelectionMode && (_jsx(DynamicTable.SelectionHeader, { totalSelected: totalSelectedQuantity, unvisibleSelected: unvisibleSelectedQuantity })), displayedColumns.map((column) => (_jsx(DynamicTable.Header, { column: column, children: column.title }, column.id)))] }) }), _jsx(DynamicTable.BodyContainer, { children: paginatedItems.map((item) => (_jsxs(DynamicTable.Line, { children: [isInSelectionMode &&
|
|
21
22
|
(item.isSelectable ? (_jsx(DynamicTable.SelectionCell, { selected: isItemSelected(item), onToggle: onItemSelectionToggle(item) })) : (_jsx(DynamicTable.Cell, {}))), item.target !== null
|
|
22
23
|
? item.values.map((value) => (_jsx(DynamicTable.ClickableCell, { target: item.target, children: value.loading ? _jsx(DynamicTable.Loader, {}) : value.display }, value.column)))
|
|
23
24
|
: item.values.map((value) => (_jsx(DynamicTable.Cell, { children: value.loading ? _jsx(DynamicTable.Loader, {}) : value.display }, value.column)))] }, item.key))) }), _jsx(DynamicTable.FooterContainer, { totalColums: displayedColumns.length, pageSelector: _jsx(DynamicTable.PageSelector, { totalPages: totalPages, currentPage: currentPage, onCurrentPageChange: onCurrentPageChange }), itemsPerPageSelector: _jsx(DynamicTable.ItemsPerPageSelector, { itemsPerPage: itemsPerPage, onItemsPerPageChange: onItemsPerPageChange }) })] })] }) }));
|
|
24
25
|
}
|
|
25
26
|
DynamicTable.TableContainer = TableContainer;
|
|
26
|
-
DynamicTable.
|
|
27
|
+
DynamicTable.ControllerContainer = ControllerContainer;
|
|
27
28
|
DynamicTable.ColumnsPopup = ColumnsPopup;
|
|
28
29
|
DynamicTable.Table = Table;
|
|
29
30
|
DynamicTable.HeaderContainer = HeaderContainer;
|