@symply.io/basic-components 1.6.11-alpha.6 → 1.7.0-alpha.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/DataTable/{TableCore/TableBody.d.ts → TableBody.d.ts} +1 -1
- package/DataTable/TableBody.js +32 -0
- package/DataTable/{TableCore/TableBodyRow.d.ts → TableBodyRow.d.ts} +1 -1
- package/DataTable/{TableCore/TableBodyRow.js → TableBodyRow.js} +14 -19
- package/DataTable/TableFooter.d.ts +3 -0
- package/DataTable/{TableCore/TableFooter.js → TableFooter.js} +5 -7
- package/DataTable/TableHeader.d.ts +3 -0
- package/DataTable/{TableCore/TableHeader.js → TableHeader.js} +5 -7
- package/DataTable/index.js +42 -16
- package/DataTable/types.d.ts +10 -23
- package/DataTable/useTable.d.ts +2 -2
- package/DataTable/useTable.js +3 -3
- package/README.md +71 -0
- package/VirtualGrid/GridCore/GridBody.d.ts +4 -0
- package/{DataTable/TableCore/TableBody.js → VirtualGrid/GridCore/GridBody.js} +8 -7
- package/VirtualGrid/GridCore/GridBodyRow.d.ts +4 -0
- package/VirtualGrid/GridCore/GridBodyRow.js +145 -0
- package/VirtualGrid/GridCore/GridFooter.d.ts +4 -0
- package/VirtualGrid/GridCore/GridFooter.js +109 -0
- package/VirtualGrid/GridCore/GridHeader.d.ts +4 -0
- package/VirtualGrid/GridCore/GridHeader.js +114 -0
- package/VirtualGrid/GridCore/index.d.ts +4 -0
- package/{DataTable/TableCore → VirtualGrid/GridCore}/index.js +10 -8
- package/VirtualGrid/GridVirtualizerContext.d.ts +3 -0
- package/{DataTable/VirtualizerContext.js → VirtualGrid/GridVirtualizerContext.js} +24 -16
- package/VirtualGrid/index.d.ts +6 -0
- package/VirtualGrid/index.js +36 -0
- package/VirtualGrid/types.d.ts +106 -0
- package/VirtualGrid/types.js +1 -0
- package/VirtualGrid/useVirtualGrid.d.ts +3 -0
- package/VirtualGrid/useVirtualGrid.js +103 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/DataTable/TableCore/TableFooter.d.ts +0 -5
- package/DataTable/TableCore/TableHeader.d.ts +0 -5
- package/DataTable/TableCore/index.d.ts +0 -3
- package/DataTable/VirtualizerContext.d.ts +0 -3
@@ -0,0 +1,106 @@
|
|
1
|
+
import type { ReactNode, RefObject, MouseEvent, ReactElement, CSSProperties } from "react";
|
2
|
+
import type { VirtualItem } from "@tanstack/react-virtual";
|
3
|
+
declare type HexColor = `#${string}`;
|
4
|
+
export declare type CustomVirtualGridRowBgColor = {
|
5
|
+
normal?: HexColor;
|
6
|
+
hover?: HexColor;
|
7
|
+
};
|
8
|
+
export declare type VirtualGridOrderType = "ASC" | "DESC" | "NONE";
|
9
|
+
export declare type VirtualGridSortingProps = {
|
10
|
+
accessor: string;
|
11
|
+
order: VirtualGridOrderType;
|
12
|
+
};
|
13
|
+
declare type InitialVirtualGridStateProps = {
|
14
|
+
sortBy?: VirtualGridSortingProps;
|
15
|
+
};
|
16
|
+
export declare type VirtualGridColumnProps = {
|
17
|
+
headerTip?: string;
|
18
|
+
Header: ReactElement;
|
19
|
+
Body: ReactElement;
|
20
|
+
Footer?: ReactElement;
|
21
|
+
align?: "left" | "center" | "right";
|
22
|
+
accessor: string;
|
23
|
+
sortable?: boolean;
|
24
|
+
fixable?: "left" | "right";
|
25
|
+
width: number;
|
26
|
+
};
|
27
|
+
export declare type UseVirtualGridBaseProps<RowProps extends Record<string, any>> = {
|
28
|
+
data: Array<RowProps>;
|
29
|
+
columns: Array<VirtualGridColumnProps>;
|
30
|
+
initialState?: InitialVirtualGridStateProps;
|
31
|
+
disableSortBy?: boolean;
|
32
|
+
onSort?: (props: VirtualGridSortingProps) => unknown;
|
33
|
+
};
|
34
|
+
export declare type UseVirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = UseVirtualGridBaseProps<RowProps> & ExtendedProps;
|
35
|
+
export declare type VirtualGridHeaderCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
36
|
+
Cell: ReactElement;
|
37
|
+
title: string;
|
38
|
+
onSort: ({ accessor, }: Pick<VirtualGridSortingProps, "accessor">) => unknown;
|
39
|
+
};
|
40
|
+
export declare type VirtualGridBodyCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
41
|
+
Cell: ReactElement;
|
42
|
+
};
|
43
|
+
export declare type VirtualGridFooterCellProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Pick<VirtualGridColumnProps, "align" | "accessor" | "fixable" | "width"> & Omit<UseVirtualGridProps<RowProps, ExtendedProps>, keyof UseVirtualGridBaseProps<RowProps>> & {
|
44
|
+
Cell: ReactElement;
|
45
|
+
};
|
46
|
+
export declare type UseVirtualGridReturns<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
47
|
+
headers: Array<VirtualGridHeaderCellProps<RowProps, ExtendedProps>>;
|
48
|
+
footers: Array<VirtualGridFooterCellProps<RowProps, ExtendedProps>>;
|
49
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
50
|
+
rows: Array<RowProps>;
|
51
|
+
onResetSorting: () => void;
|
52
|
+
};
|
53
|
+
export declare type VirtualGridHeaderProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
54
|
+
headers: Array<VirtualGridHeaderCellProps<RowProps, ExtendedProps>>;
|
55
|
+
headerBgColor?: CSSProperties["color"];
|
56
|
+
headerTextColor?: CSSProperties["color"];
|
57
|
+
noData?: boolean;
|
58
|
+
};
|
59
|
+
export declare type VirtualGridBodyProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
60
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
61
|
+
rows: Array<RowProps>;
|
62
|
+
noDataText?: string;
|
63
|
+
onRowClick?: (row: RowProps) => unknown;
|
64
|
+
onContextMenu?: (event: MouseEvent<HTMLTableRowElement>, row: RowProps) => unknown;
|
65
|
+
onCustomizeRowBgColor?: ({ row, columns, }: {
|
66
|
+
row: RowProps;
|
67
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
68
|
+
}) => CustomVirtualGridRowBgColor;
|
69
|
+
};
|
70
|
+
export declare type VirtualGridBodyRowProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Omit<VirtualGridBodyProps<RowProps, ExtendedProps>, "noDataText"> & {
|
71
|
+
rowIndex: number;
|
72
|
+
virtualRow: VirtualItem;
|
73
|
+
};
|
74
|
+
export declare type VirtualGridFooterProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = {
|
75
|
+
footers?: Array<VirtualGridFooterCellProps<RowProps, ExtendedProps>>;
|
76
|
+
footerBgColor?: CSSProperties["color"];
|
77
|
+
footerTextColor?: CSSProperties["color"];
|
78
|
+
noData?: boolean;
|
79
|
+
};
|
80
|
+
export declare type VirtualGridCoreProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = Omit<VirtualGridHeaderProps<RowProps, ExtendedProps>, "noData"> & VirtualGridBodyProps<RowProps, ExtendedProps> & Omit<VirtualGridFooterProps<RowProps, ExtendedProps>, "noData"> & {
|
81
|
+
dense?: boolean;
|
82
|
+
primaryColor?: CSSProperties["color"];
|
83
|
+
secondaryColor?: CSSProperties["color"];
|
84
|
+
};
|
85
|
+
export declare type VirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = VirtualGridCoreProps<RowProps, ExtendedProps> & {
|
86
|
+
estimateRowHeight?: number;
|
87
|
+
primaryColor?: CSSProperties["color"];
|
88
|
+
secondaryColor?: CSSProperties["color"];
|
89
|
+
};
|
90
|
+
export interface GridVirtualizerContextProviderProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> {
|
91
|
+
dense?: boolean;
|
92
|
+
children: ReactNode;
|
93
|
+
rows: Array<RowProps>;
|
94
|
+
estimateRowHeight?: number;
|
95
|
+
columns: Array<VirtualGridBodyCellProps<RowProps, ExtendedProps>>;
|
96
|
+
}
|
97
|
+
export interface IGridVirtualizerContext {
|
98
|
+
tableRef: RefObject<HTMLDivElement>;
|
99
|
+
virtualRows: Array<VirtualItem>;
|
100
|
+
leftShadowVisible: boolean;
|
101
|
+
rightShadowVisible: boolean;
|
102
|
+
getTotalSize: () => number;
|
103
|
+
onMeasureElement: (node: Element | null | undefined) => void;
|
104
|
+
onProcessShadowVisible: () => void;
|
105
|
+
}
|
106
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,103 @@
|
|
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
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
+
import { cloneElement, useState, useMemo, useCallback } from "react";
|
25
|
+
function useVirtualGrid(props) {
|
26
|
+
var data = props.data, columns = props.columns, initialState = props.initialState, disableSortBy = props.disableSortBy, onSort = props.onSort, rest = __rest(props, ["data", "columns", "initialState", "disableSortBy", "onSort"]);
|
27
|
+
if (!data) {
|
28
|
+
throw new Error('"data" is required but got null or undefined');
|
29
|
+
}
|
30
|
+
if (!columns) {
|
31
|
+
throw new Error('"columns" is required but got null or undefined');
|
32
|
+
}
|
33
|
+
var initialSortingProps = useMemo(function () {
|
34
|
+
var sortBy = (initialState || {}).sortBy;
|
35
|
+
var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
|
36
|
+
return {
|
37
|
+
accessor: accessor || "",
|
38
|
+
order: !!accessor ? order || "NONE" : "NONE",
|
39
|
+
};
|
40
|
+
}, [initialState]);
|
41
|
+
var _a = useState(initialSortingProps), sortingProps = _a[0], setSortingProps = _a[1];
|
42
|
+
var handleSort = useCallback(function (_a) {
|
43
|
+
var accessor = _a.accessor;
|
44
|
+
if (!disableSortBy) {
|
45
|
+
var newSortingProps = __assign({}, sortingProps);
|
46
|
+
if (accessor !== sortingProps.accessor ||
|
47
|
+
sortingProps.order === "NONE") {
|
48
|
+
newSortingProps = { accessor: accessor, order: "ASC" };
|
49
|
+
}
|
50
|
+
else if (sortingProps.order === "ASC") {
|
51
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "DESC" });
|
52
|
+
}
|
53
|
+
else {
|
54
|
+
newSortingProps = __assign(__assign({}, sortingProps), { order: "NONE" });
|
55
|
+
}
|
56
|
+
if (onSort) {
|
57
|
+
onSort(__assign({}, newSortingProps));
|
58
|
+
}
|
59
|
+
setSortingProps(__assign({}, newSortingProps));
|
60
|
+
}
|
61
|
+
}, [disableSortBy, onSort, sortingProps]);
|
62
|
+
var onResetSorting = useCallback(function () {
|
63
|
+
if (onSort) {
|
64
|
+
onSort(__assign({}, initialSortingProps));
|
65
|
+
}
|
66
|
+
setSortingProps(__assign({}, initialSortingProps));
|
67
|
+
}, [initialSortingProps, onSort]);
|
68
|
+
var renderSortingSymbol = useCallback(function (accessor) {
|
69
|
+
var field = sortingProps.accessor, order = sortingProps.order;
|
70
|
+
if (accessor !== field || order === "NONE") {
|
71
|
+
return "";
|
72
|
+
}
|
73
|
+
if (order === "ASC") {
|
74
|
+
return "↑";
|
75
|
+
}
|
76
|
+
return "↓";
|
77
|
+
}, [sortingProps]);
|
78
|
+
var rows = useMemo(function () { return data.map(function (d) { return d; }); }, [data]);
|
79
|
+
var cols = useMemo(function () {
|
80
|
+
return columns.map(function (col) {
|
81
|
+
var Body = col.Body;
|
82
|
+
return __assign(__assign({ Cell: cloneElement(Body || _jsx(_Fragment, {}), { column: col }) }, col), rest);
|
83
|
+
});
|
84
|
+
}, [columns, rest]);
|
85
|
+
var headers = useMemo(function () {
|
86
|
+
return columns.map(function (col) {
|
87
|
+
var Header = col.Header, accessor = col.accessor, sortable = col.sortable, headerTip = col.headerTip;
|
88
|
+
var canSortBy = sortable && !disableSortBy;
|
89
|
+
return __assign(__assign({ Cell: (_jsxs(_Fragment, { children: [cloneElement(Header || _jsx(_Fragment, {}), { column: col }), canSortBy && renderSortingSymbol(accessor)] })), title: "".concat(headerTip || "").concat(canSortBy ? " (Click to sort)" : ""), sortable: canSortBy, onSort: canSortBy ? handleSort : function () { } }, col), rest);
|
90
|
+
});
|
91
|
+
}, [columns, disableSortBy, handleSort, renderSortingSymbol, rest]);
|
92
|
+
var footers = useMemo(function () {
|
93
|
+
return columns.map(function (col) {
|
94
|
+
var Footer = col.Footer;
|
95
|
+
return __assign(__assign({ Cell: cloneElement(Footer || _jsx(_Fragment, {}), {
|
96
|
+
column: col,
|
97
|
+
rows: rows,
|
98
|
+
}) }, col), rest);
|
99
|
+
});
|
100
|
+
}, [columns, rest, rows]);
|
101
|
+
return { headers: headers, footers: footers, columns: cols, rows: rows, onResetSorting: onResetSorting };
|
102
|
+
}
|
103
|
+
export default useVirtualGrid;
|
package/index.d.ts
CHANGED
@@ -29,6 +29,7 @@ export * from "./TablePagination";
|
|
29
29
|
export * from "./TextInput";
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
|
+
export * from "./VirtualGrid";
|
32
33
|
export { default as AlertDialog } from "./AlertDialog";
|
33
34
|
export { default as Autocomplete } from "./Autocomplete";
|
34
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -57,3 +58,4 @@ export { default as TabGroup } from "./TabGroup";
|
|
57
58
|
export { default as TablePagination } from "./TablePagination";
|
58
59
|
export { default as TextInput } from "./TextInput";
|
59
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
61
|
+
export { default as VirtualGrid } from "./VirtualGrid";
|
package/index.js
CHANGED
@@ -29,6 +29,7 @@ export * from "./TablePagination";
|
|
29
29
|
export * from "./TextInput";
|
30
30
|
export * from "./ToastPrompt";
|
31
31
|
export * from "./VideoPlayerModal";
|
32
|
+
export * from "./VirtualGrid";
|
32
33
|
export { default as AlertDialog } from "./AlertDialog";
|
33
34
|
export { default as Autocomplete } from "./Autocomplete";
|
34
35
|
export { default as AutocompleteWithFilter } from "./AutocompleteWithFilter";
|
@@ -57,3 +58,4 @@ export { default as TabGroup } from "./TabGroup";
|
|
57
58
|
export { default as TablePagination } from "./TablePagination";
|
58
59
|
export { default as TextInput } from "./TextInput";
|
59
60
|
export { default as VideoPlayerModal } from "./VideoPlayerModal";
|
61
|
+
export { default as VirtualGrid } from "./VirtualGrid";
|
package/package.json
CHANGED
@@ -1,5 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import type { TableFooterProps, KvProps } from "../types";
|
3
|
-
declare function TableFooter<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
4
|
-
declare const _default: import("react").MemoExoticComponent<typeof TableFooter>;
|
5
|
-
export default _default;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import type { TableHeaderProps, KvProps } from "../types";
|
3
|
-
declare function TableHeader<RowProps extends KvProps, ExtendedProps extends KvProps>(props: TableHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
4
|
-
declare const _default: import("react").MemoExoticComponent<typeof TableHeader>;
|
5
|
-
export default _default;
|
@@ -1,3 +0,0 @@
|
|
1
|
-
import type { KvProps, IVirtualizerContext, VirtualizerContextProviderProps } from "./types";
|
2
|
-
export declare function VirtualizerContextProvider<RowProps extends KvProps, ExtendedProps extends KvProps>(props: VirtualizerContextProviderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
|
3
|
-
export declare const useTableVirtualizer: () => IVirtualizerContext;
|