@symply.io/basic-components 1.7.0-alpha.2 → 1.7.0-alpha.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.
@@ -0,0 +1,3 @@
1
+ import type { VirtualTableProps, TVirtualTableRow } from "./types";
2
+ declare function VirtualDataTable<RowProps extends TVirtualTableRow>(props: VirtualTableProps<RowProps>): import("react/jsx-runtime").JSX.Element;
3
+ export default VirtualDataTable;
@@ -0,0 +1,167 @@
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
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { forwardRef, cloneElement, useMemo, useCallback } from "react";
14
+ import { TableVirtuoso } from "react-virtuoso";
15
+ import Paper from "@mui/material/Paper";
16
+ import Table from "@mui/material/Table";
17
+ import TableRow from "@mui/material/TableRow";
18
+ import TableBody from "@mui/material/TableBody";
19
+ import TableCell from "@mui/material/TableCell";
20
+ import TableHead from "@mui/material/TableHead";
21
+ import TableFooter from "@mui/material/TableFooter";
22
+ import TableContainer from "@mui/material/TableContainer";
23
+ import useMediaQuery from "@mui/material/useMediaQuery";
24
+ import useTheme from "@mui/material/styles/useTheme";
25
+ function VirtualDataTable(props) {
26
+ var rows = props.rows, columns = props.columns, dense = props.dense;
27
+ var theme = useTheme();
28
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
29
+ var _a = useMemo(function () {
30
+ if (isUpMd) {
31
+ var left = columns.filter(function (c) { return c.fixable === "left"; });
32
+ var right = columns.filter(function (c) { return c.fixable === "right"; });
33
+ var dynamic = columns.filter(function (c) { return !c.fixable; });
34
+ return [left, dynamic, right];
35
+ }
36
+ else {
37
+ return [[], columns, []];
38
+ }
39
+ }, [isUpMd, columns]), pinnedLeftCols = _a[0], normalCols = _a[1], pinnedRightCols = _a[2];
40
+ var VirtuosoTableComponents = useMemo(function () { return ({
41
+ Scroller: forwardRef(function (props, ref) { return (_jsx(TableContainer, __assign({ component: Paper }, props, { ref: ref, sx: {
42
+ maxHeight: "inherit",
43
+ borderWidth: "thin",
44
+ borderColor: "#e5e5e5",
45
+ borderStyle: "solid",
46
+ borderRadius: "4px",
47
+ borderCollapse: "unset !important",
48
+ transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
49
+ } }))); }),
50
+ Table: function (props) { return (_jsx(Table, __assign({}, props, { size: dense ? "small" : "medium", sx: {
51
+ borderCollapse: "separate",
52
+ minWidth: 600,
53
+ tableLayout: "fixed",
54
+ } }))); },
55
+ TableHead: forwardRef(function (props, ref) { return (_jsx(TableHead, __assign({}, props, { ref: ref }))); }),
56
+ TableRow: TableRow,
57
+ TableBody: forwardRef(function (props, ref) { return (_jsx(TableBody, __assign({}, props, { ref: ref }))); }),
58
+ TableFoot: forwardRef(function (props, ref) { return (_jsx(TableFooter, __assign({}, props, { ref: ref }))); }),
59
+ }); }, []);
60
+ var fixedHeaderContent = useCallback(function () {
61
+ return (_jsxs(TableRow, { children: [pinnedLeftCols.map(function (column, index) {
62
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
63
+ var left = pinnedLeftCols
64
+ .slice(0, index)
65
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
66
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
67
+ position: "sticky",
68
+ left: left,
69
+ zIndex: 20,
70
+ width: width,
71
+ cursor: sortable ? "pointer" : "default",
72
+ backgroundColor: "background.paper",
73
+ } }, { children: cloneElement(Header) }), accessor));
74
+ }), normalCols.map(function (column) {
75
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
76
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
77
+ zIndex: 9,
78
+ width: width,
79
+ cursor: sortable ? "pointer" : "default",
80
+ backgroundColor: "background.paper",
81
+ } }, { children: cloneElement(Header) }), accessor));
82
+ }), pinnedRightCols.map(function (column, index) {
83
+ var align = column.align, width = column.width, Header = column.Header, accessor = column.accessor, headerTip = column.headerTip, sortable = column.sortable;
84
+ var right = pinnedRightCols
85
+ .slice(0, pinnedRightCols.length - 1 - index)
86
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
87
+ return (_jsx(TableCell, __assign({ variant: "head", title: headerTip, align: align, sx: {
88
+ position: "sticky",
89
+ right: right,
90
+ zIndex: 20,
91
+ width: width,
92
+ cursor: sortable ? "pointer" : "default",
93
+ backgroundColor: "background.paper",
94
+ } }, { children: cloneElement(Header) }), accessor));
95
+ })] }));
96
+ }, []);
97
+ var fixedFooterContent = useCallback(function () {
98
+ return (_jsxs(TableRow, { children: [pinnedLeftCols.map(function (column, index) {
99
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
100
+ var left = pinnedLeftCols
101
+ .slice(0, index)
102
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
103
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
104
+ position: "sticky",
105
+ left: left,
106
+ zIndex: 20,
107
+ width: width,
108
+ backgroundColor: "background.paper",
109
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
110
+ }), normalCols.map(function (column) {
111
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
112
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
113
+ zIndex: 9,
114
+ width: width,
115
+ backgroundColor: "background.paper",
116
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
117
+ }), pinnedRightCols.map(function (column, index) {
118
+ var align = column.align, width = column.width, Footer = column.Footer, accessor = column.accessor;
119
+ var right = pinnedRightCols
120
+ .slice(0, pinnedRightCols.length - 1 - index)
121
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
122
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
123
+ position: "sticky",
124
+ right: right,
125
+ zIndex: 20,
126
+ width: width,
127
+ backgroundColor: "background.paper",
128
+ } }, { children: Footer ? cloneElement(Footer) : _jsx(_Fragment, {}) }), accessor));
129
+ })] }));
130
+ }, []);
131
+ var itemContent = useCallback(function (rowIndex, row) {
132
+ return (_jsxs(_Fragment, { children: [pinnedLeftCols.map(function (column, index) {
133
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
134
+ var left = pinnedLeftCols
135
+ .slice(0, index)
136
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
137
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
138
+ position: "sticky",
139
+ left: left,
140
+ zIndex: 20,
141
+ width: width,
142
+ backgroundColor: "background.paper",
143
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
144
+ }), normalCols.map(function (column) {
145
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
146
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
147
+ zIndex: 9,
148
+ width: width,
149
+ backgroundColor: "background.paper",
150
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
151
+ }), pinnedRightCols.map(function (column, index) {
152
+ var align = column.align, width = column.width, Body = column.Body, accessor = column.accessor;
153
+ var right = pinnedRightCols
154
+ .slice(0, pinnedRightCols.length - 1 - index)
155
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
156
+ return (_jsx(TableCell, __assign({ variant: "footer", align: align, sx: {
157
+ position: "sticky",
158
+ right: right,
159
+ zIndex: 20,
160
+ width: width,
161
+ backgroundColor: "background.paper",
162
+ } }, { children: cloneElement(Body, { column: column, row: row, rows: rows, rowIndex: rowIndex }) }), accessor));
163
+ })] }));
164
+ }, []);
165
+ return (_jsx(TableVirtuoso, { data: rows, components: VirtuosoTableComponents, fixedHeaderContent: fixedHeaderContent, fixedFooterContent: fixedFooterContent, itemContent: itemContent }));
166
+ }
167
+ export default VirtualDataTable;
@@ -0,0 +1,20 @@
1
+ import type { ReactElement, CSSProperties } from "react";
2
+ export declare type TVirtualTableRow = Record<string, any>;
3
+ export declare type TVirtualTableColumn = {
4
+ headerTip?: string;
5
+ Header: ReactElement;
6
+ Body: ReactElement;
7
+ Footer?: ReactElement;
8
+ align?: "left" | "center" | "right";
9
+ accessor: string;
10
+ sortable?: boolean;
11
+ fixable?: "left" | "right";
12
+ width: number;
13
+ };
14
+ export interface VirtualTableProps<RowProps extends TVirtualTableRow> {
15
+ dense?: boolean;
16
+ rows: Array<RowProps>;
17
+ columns: Array<TVirtualTableColumn>;
18
+ primaryColor?: CSSProperties["color"];
19
+ secondaryColor?: CSSProperties["color"];
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -18,7 +18,6 @@ import useTheme from "@mui/material/styles/useTheme";
18
18
  import { useGridVirtualizer } from "../GridVirtualizerContext";
19
19
  function VirtualGridBodyRow(props) {
20
20
  var rows = props.rows, columns = props.columns, rowIndex = props.rowIndex, virtualRow = props.virtualRow, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
21
- console.log({ virtualRow: virtualRow });
22
21
  var theme = useTheme();
23
22
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
23
  var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible, onMeasureElement = _a.onMeasureElement;
@@ -79,8 +79,6 @@ export declare type VirtualGridFooterProps<RowProps extends Record<string, any>,
79
79
  };
80
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
81
  dense?: boolean;
82
- primaryColor?: CSSProperties["color"];
83
- secondaryColor?: CSSProperties["color"];
84
82
  };
85
83
  export declare type VirtualGridProps<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>> = VirtualGridCoreProps<RowProps, ExtendedProps> & {
86
84
  estimateRowHeight?: number;
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 "./VirtualDataTable";
32
33
  export * from "./VirtualGrid";
33
34
  export { default as AlertDialog } from "./AlertDialog";
34
35
  export { default as Autocomplete } from "./Autocomplete";
@@ -58,4 +59,5 @@ export { default as TabGroup } from "./TabGroup";
58
59
  export { default as TablePagination } from "./TablePagination";
59
60
  export { default as TextInput } from "./TextInput";
60
61
  export { default as VideoPlayerModal } from "./VideoPlayerModal";
62
+ export { default as VirtualDataTable } from "./VirtualDataTable";
61
63
  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 "./VirtualDataTable";
32
33
  export * from "./VirtualGrid";
33
34
  export { default as AlertDialog } from "./AlertDialog";
34
35
  export { default as Autocomplete } from "./Autocomplete";
@@ -58,4 +59,5 @@ export { default as TabGroup } from "./TabGroup";
58
59
  export { default as TablePagination } from "./TablePagination";
59
60
  export { default as TextInput } from "./TextInput";
60
61
  export { default as VideoPlayerModal } from "./VideoPlayerModal";
62
+ export { default as VirtualDataTable } from "./VirtualDataTable";
61
63
  export { default as VirtualGrid } from "./VirtualGrid";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.7.0-alpha.2",
3
+ "version": "1.7.0-alpha.3",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",
@@ -60,6 +60,7 @@
60
60
  "color-alpha": "^1.1.3",
61
61
  "react-dropzone": "14.2.3",
62
62
  "react-player": "2.11.0",
63
+ "react-virtuoso": "^4.12.0",
63
64
  "rifm": "^0.12.1"
64
65
  },
65
66
  "resolutions": {