@deepnoid/ui 0.0.80 → 0.0.83
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/{chunk-TDMXAHWR.mjs → chunk-6U736HAX.mjs} +30 -4
- package/dist/{chunk-DLVQWKQG.mjs → chunk-BHSCW5D6.mjs} +23 -18
- package/dist/{chunk-G3CX6IWH.mjs → chunk-PUFNT5LS.mjs} +18 -6
- package/dist/components/table/index.d.mts +1 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/index.js +68 -25
- package/dist/components/table/index.mjs +3 -3
- package/dist/components/table/table-body.d.mts +5 -2
- package/dist/components/table/table-body.d.ts +5 -2
- package/dist/components/table/table-body.js +23 -18
- package/dist/components/table/table-body.mjs +1 -1
- package/dist/components/table/table-head.d.mts +4 -2
- package/dist/components/table/table-head.d.ts +4 -2
- package/dist/components/table/table-head.js +18 -6
- package/dist/components/table/table-head.mjs +1 -1
- package/dist/components/table/table.d.mts +32 -59
- package/dist/components/table/table.d.ts +32 -59
- package/dist/components/table/table.js +68 -25
- package/dist/components/table/table.mjs +3 -3
- package/dist/components/table/table.test.js +70 -27
- package/dist/components/table/table.test.mjs +3 -3
- package/dist/index.js +68 -25
- package/dist/index.mjs +11 -11
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
table_head_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PUFNT5LS.mjs";
|
|
5
5
|
import {
|
|
6
6
|
table_body_default
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-BHSCW5D6.mjs";
|
|
8
8
|
import {
|
|
9
9
|
clsx
|
|
10
10
|
} from "./chunk-27Y6K5NK.mjs";
|
|
@@ -13,12 +13,13 @@ import {
|
|
|
13
13
|
} from "./chunk-E3G5QXSH.mjs";
|
|
14
14
|
|
|
15
15
|
// src/components/table/table.tsx
|
|
16
|
-
import { forwardRef, useCallback, useMemo } from "react";
|
|
16
|
+
import { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from "react";
|
|
17
17
|
import { tv } from "tailwind-variants";
|
|
18
18
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
19
|
var Table = forwardRef((originalProps, ref) => {
|
|
20
20
|
const [props, variantProps] = mapPropsVariants(originalProps, table.variantKeys);
|
|
21
21
|
const { classNames, rows, columns, isLoading, className, emptyContent, onRowAction, ...tableComponentsProps } = props;
|
|
22
|
+
const [selectedRows, setSelectedRows] = useState(/* @__PURE__ */ new Set());
|
|
22
23
|
const slots = useMemo(() => table({ ...variantProps }), [...Object.values(variantProps)]);
|
|
23
24
|
const getBaseProps = useCallback(
|
|
24
25
|
(props2) => ({
|
|
@@ -34,6 +35,23 @@ var Table = forwardRef((originalProps, ref) => {
|
|
|
34
35
|
}),
|
|
35
36
|
[classNames == null ? void 0 : classNames.table, slots]
|
|
36
37
|
);
|
|
38
|
+
const handleSelectAll = (isSelected) => {
|
|
39
|
+
const newSelectedRows = isSelected ? new Set(rows.map((_, index) => index)) : /* @__PURE__ */ new Set();
|
|
40
|
+
setSelectedRows(newSelectedRows);
|
|
41
|
+
};
|
|
42
|
+
const handleSelectRow = (index) => {
|
|
43
|
+
const newSelectedRows = new Set(selectedRows);
|
|
44
|
+
if (newSelectedRows.has(index)) {
|
|
45
|
+
newSelectedRows.delete(index);
|
|
46
|
+
} else {
|
|
47
|
+
newSelectedRows.add(index);
|
|
48
|
+
}
|
|
49
|
+
setSelectedRows(newSelectedRows);
|
|
50
|
+
};
|
|
51
|
+
useImperativeHandle(ref, () => ({
|
|
52
|
+
selectedRows,
|
|
53
|
+
setSelectedRows
|
|
54
|
+
}));
|
|
37
55
|
return /* @__PURE__ */ jsx("div", { ref, "data-table": "base", ...getBaseProps(), children: /* @__PURE__ */ jsxs("table", { ...getTableProps(tableComponentsProps), children: [
|
|
38
56
|
/* @__PURE__ */ jsx(
|
|
39
57
|
table_head_default,
|
|
@@ -44,7 +62,9 @@ var Table = forwardRef((originalProps, ref) => {
|
|
|
44
62
|
size: originalProps.size,
|
|
45
63
|
color: originalProps.color === "neutral" ? "primary" : originalProps.color,
|
|
46
64
|
isSelected: originalProps.isSelected,
|
|
47
|
-
isExpanded: originalProps.isExpanded
|
|
65
|
+
isExpanded: originalProps.isExpanded,
|
|
66
|
+
onSelectAll: handleSelectAll,
|
|
67
|
+
isAllSelected: selectedRows.size === rows.length
|
|
48
68
|
}
|
|
49
69
|
),
|
|
50
70
|
/* @__PURE__ */ jsx(
|
|
@@ -56,10 +76,13 @@ var Table = forwardRef((originalProps, ref) => {
|
|
|
56
76
|
size: originalProps.size,
|
|
57
77
|
color: originalProps.color === "neutral" ? "primary" : originalProps.color,
|
|
58
78
|
isSelected: originalProps.isSelected,
|
|
79
|
+
isSelectedRow: originalProps.isSelectedRow,
|
|
59
80
|
isExpanded: originalProps.isExpanded,
|
|
60
81
|
isLoading,
|
|
61
82
|
classNames,
|
|
62
83
|
emptyContent,
|
|
84
|
+
selectedRows,
|
|
85
|
+
onSelectRow: handleSelectRow,
|
|
63
86
|
onRowAction
|
|
64
87
|
}
|
|
65
88
|
)
|
|
@@ -161,6 +184,9 @@ var table = tv({
|
|
|
161
184
|
isSelected: {
|
|
162
185
|
true: {}
|
|
163
186
|
},
|
|
187
|
+
isSelectedRow: {
|
|
188
|
+
true: {}
|
|
189
|
+
},
|
|
164
190
|
hideHeader: {
|
|
165
191
|
true: {
|
|
166
192
|
thead: "hidden"
|
|
@@ -20,12 +20,15 @@ var TableBody = ({
|
|
|
20
20
|
slots,
|
|
21
21
|
rows,
|
|
22
22
|
columns,
|
|
23
|
-
isSelected,
|
|
24
23
|
isExpanded,
|
|
24
|
+
isSelected,
|
|
25
|
+
isSelectedRow,
|
|
26
|
+
selectedRows,
|
|
25
27
|
emptyContent,
|
|
28
|
+
onSelectRow,
|
|
26
29
|
onRowAction
|
|
27
30
|
}) => {
|
|
28
|
-
const
|
|
31
|
+
const COL_SPAN_COUNT = columns.length + (isExpanded ? 1 : 0) + (isSelected ? 1 : 0);
|
|
29
32
|
const [expandedRows, setExpandedRows] = useState(/* @__PURE__ */ new Set());
|
|
30
33
|
useEffect(() => {
|
|
31
34
|
setExpandedRows(/* @__PURE__ */ new Set());
|
|
@@ -77,20 +80,22 @@ var TableBody = ({
|
|
|
77
80
|
},
|
|
78
81
|
[classNames == null ? void 0 : classNames.td, columns, slots]
|
|
79
82
|
);
|
|
83
|
+
const onChangeExpandedRow = (index) => {
|
|
84
|
+
setExpandedRows((prevIndices) => {
|
|
85
|
+
const newIndices = new Set(prevIndices);
|
|
86
|
+
if (newIndices.has(index)) {
|
|
87
|
+
newIndices.delete(index);
|
|
88
|
+
} else {
|
|
89
|
+
newIndices.add(index);
|
|
90
|
+
}
|
|
91
|
+
return newIndices;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
80
94
|
const handleRowClick = (index) => (e) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (isExpanded)
|
|
84
|
-
|
|
85
|
-
const newIndices = new Set(prevIndices);
|
|
86
|
-
if (newIndices.has(index)) {
|
|
87
|
-
newIndices.delete(index);
|
|
88
|
-
} else {
|
|
89
|
-
newIndices.add(index);
|
|
90
|
-
}
|
|
91
|
-
return newIndices;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
if (isExpanded) onChangeExpandedRow(index);
|
|
98
|
+
if (isSelected && isSelectedRow) onSelectRow(index);
|
|
94
99
|
const row = rows[index];
|
|
95
100
|
if (row !== void 0) {
|
|
96
101
|
onRowAction == null ? void 0 : onRowAction(e, row);
|
|
@@ -100,7 +105,7 @@ var TableBody = ({
|
|
|
100
105
|
const keys = Object.keys(row);
|
|
101
106
|
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
102
107
|
/* @__PURE__ */ jsxs("tr", { ...getTrProps(rowIndex), onClick: handleRowClick(rowIndex), children: [
|
|
103
|
-
isSelected && /* @__PURE__ */ jsx("td", { ...getTdProps({ field: "checkbox" }, row, keys), children: /* @__PURE__ */ jsx(checkbox_default, { color, size }) }),
|
|
108
|
+
isSelected && /* @__PURE__ */ jsx("td", { ...getTdProps({ field: "checkbox" }, row, keys), onClick: () => onSelectRow(rowIndex), children: /* @__PURE__ */ jsx(checkbox_default, { color, size, checked: selectedRows.has(rowIndex) }) }),
|
|
104
109
|
isExpanded && /* @__PURE__ */ jsx("td", { ...getTdProps({ field: "expandIcon" }, row, keys), children: /* @__PURE__ */ jsx(
|
|
105
110
|
Icon_default,
|
|
106
111
|
{
|
|
@@ -111,9 +116,9 @@ var TableBody = ({
|
|
|
111
116
|
) }),
|
|
112
117
|
columns.map((column, colIndex) => /* @__PURE__ */ createElement("td", { ...getTdProps(column, row, keys), key: colIndex }))
|
|
113
118
|
] }),
|
|
114
|
-
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ jsx("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ jsx("td", { colSpan:
|
|
119
|
+
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ jsx("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ jsx("td", { colSpan: COL_SPAN_COUNT, ...getTdProps({ field: "expandedRow" }, row, keys), children: row.renderExpandedRow && row.renderExpandedRow() }) })
|
|
115
120
|
] }, rowIndex);
|
|
116
|
-
}) : /* @__PURE__ */ jsx("tr", { ...getTrProps(-1), children: /* @__PURE__ */ jsx("td", { colSpan:
|
|
121
|
+
}) : /* @__PURE__ */ jsx("tr", { ...getTrProps(-1), children: /* @__PURE__ */ jsx("td", { colSpan: COL_SPAN_COUNT, children: emptyContent }) }) });
|
|
117
122
|
};
|
|
118
123
|
var table_body_default = TableBody;
|
|
119
124
|
|
|
@@ -10,7 +10,17 @@ import {
|
|
|
10
10
|
import { useCallback } from "react";
|
|
11
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { createElement } from "react";
|
|
13
|
-
var TableHead = ({
|
|
13
|
+
var TableHead = ({
|
|
14
|
+
columns,
|
|
15
|
+
slots,
|
|
16
|
+
size,
|
|
17
|
+
color,
|
|
18
|
+
isExpanded,
|
|
19
|
+
isSelected,
|
|
20
|
+
isAllSelected,
|
|
21
|
+
classNames,
|
|
22
|
+
onSelectAll
|
|
23
|
+
}) => {
|
|
14
24
|
const getTheadProps = useCallback(
|
|
15
25
|
() => ({
|
|
16
26
|
className: slots.thead({ class: clsx(classNames == null ? void 0 : classNames.thead) })
|
|
@@ -27,14 +37,16 @@ var TableHead = ({ columns, slots, size, color, isSelected, isExpanded, classNam
|
|
|
27
37
|
({ className }) => ({
|
|
28
38
|
className: slots.th({ class: clsx(classNames == null ? void 0 : classNames.th, className) })
|
|
29
39
|
}),
|
|
30
|
-
[classNames == null ? void 0 : classNames.th,
|
|
40
|
+
[classNames == null ? void 0 : classNames.th, slots]
|
|
31
41
|
);
|
|
42
|
+
const handleClickSelectAll = (e) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
onSelectAll(!isAllSelected);
|
|
45
|
+
};
|
|
32
46
|
return /* @__PURE__ */ jsx("thead", { ...getTheadProps(), children: /* @__PURE__ */ jsxs("tr", { ...getTrProps(), children: [
|
|
33
|
-
isSelected && /* @__PURE__ */ jsx("th", { className: "w-[40px]", children: /* @__PURE__ */ jsx(checkbox_default, { size, color, classNames: { wrapper: "bg-background" } }) }),
|
|
47
|
+
isSelected && /* @__PURE__ */ jsx("th", { className: "w-[40px]", onClick: handleClickSelectAll, children: /* @__PURE__ */ jsx(checkbox_default, { size, color, checked: isAllSelected, classNames: { wrapper: "bg-background" } }) }),
|
|
34
48
|
isExpanded && /* @__PURE__ */ jsx("th", { className: "w-[40px]" }),
|
|
35
|
-
columns.map((column, index) => {
|
|
36
|
-
return /* @__PURE__ */ createElement("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName);
|
|
37
|
-
})
|
|
49
|
+
columns.map((column, index) => /* @__PURE__ */ createElement("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName))
|
|
38
50
|
] }) });
|
|
39
51
|
};
|
|
40
52
|
var table_head_default = TableHead;
|
|
@@ -307,7 +307,17 @@ var checkbox = tv({
|
|
|
307
307
|
// src/components/table/table-head.tsx
|
|
308
308
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
309
309
|
var import_react3 = require("react");
|
|
310
|
-
var TableHead = ({
|
|
310
|
+
var TableHead = ({
|
|
311
|
+
columns,
|
|
312
|
+
slots,
|
|
313
|
+
size,
|
|
314
|
+
color,
|
|
315
|
+
isExpanded,
|
|
316
|
+
isSelected,
|
|
317
|
+
isAllSelected,
|
|
318
|
+
classNames,
|
|
319
|
+
onSelectAll
|
|
320
|
+
}) => {
|
|
311
321
|
const getTheadProps = (0, import_react2.useCallback)(
|
|
312
322
|
() => ({
|
|
313
323
|
className: slots.thead({ class: clsx(classNames == null ? void 0 : classNames.thead) })
|
|
@@ -324,14 +334,16 @@ var TableHead = ({ columns, slots, size, color, isSelected, isExpanded, classNam
|
|
|
324
334
|
({ className }) => ({
|
|
325
335
|
className: slots.th({ class: clsx(classNames == null ? void 0 : classNames.th, className) })
|
|
326
336
|
}),
|
|
327
|
-
[classNames == null ? void 0 : classNames.th,
|
|
337
|
+
[classNames == null ? void 0 : classNames.th, slots]
|
|
328
338
|
);
|
|
339
|
+
const handleClickSelectAll = (e) => {
|
|
340
|
+
e.preventDefault();
|
|
341
|
+
onSelectAll(!isAllSelected);
|
|
342
|
+
};
|
|
329
343
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { ...getTheadProps(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { ...getTrProps(), children: [
|
|
330
|
-
isSelected && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(checkbox_default, { size, color, classNames: { wrapper: "bg-background" } }) }),
|
|
344
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]", onClick: handleClickSelectAll, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(checkbox_default, { size, color, checked: isAllSelected, classNames: { wrapper: "bg-background" } }) }),
|
|
331
345
|
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]" }),
|
|
332
|
-
columns.map((column, index) => {
|
|
333
|
-
return /* @__PURE__ */ (0, import_react3.createElement)("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName);
|
|
334
|
-
})
|
|
346
|
+
columns.map((column, index) => /* @__PURE__ */ (0, import_react3.createElement)("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName))
|
|
335
347
|
] }) });
|
|
336
348
|
};
|
|
337
349
|
var table_head_default = TableHead;
|
|
@@ -2740,12 +2752,15 @@ var TableBody = ({
|
|
|
2740
2752
|
slots,
|
|
2741
2753
|
rows,
|
|
2742
2754
|
columns,
|
|
2743
|
-
isSelected,
|
|
2744
2755
|
isExpanded,
|
|
2756
|
+
isSelected,
|
|
2757
|
+
isSelectedRow,
|
|
2758
|
+
selectedRows,
|
|
2745
2759
|
emptyContent,
|
|
2760
|
+
onSelectRow,
|
|
2746
2761
|
onRowAction
|
|
2747
2762
|
}) => {
|
|
2748
|
-
const
|
|
2763
|
+
const COL_SPAN_COUNT = columns.length + (isExpanded ? 1 : 0) + (isSelected ? 1 : 0);
|
|
2749
2764
|
const [expandedRows, setExpandedRows] = (0, import_react4.useState)(/* @__PURE__ */ new Set());
|
|
2750
2765
|
(0, import_react4.useEffect)(() => {
|
|
2751
2766
|
setExpandedRows(/* @__PURE__ */ new Set());
|
|
@@ -2797,20 +2812,22 @@ var TableBody = ({
|
|
|
2797
2812
|
},
|
|
2798
2813
|
[classNames == null ? void 0 : classNames.td, columns, slots]
|
|
2799
2814
|
);
|
|
2815
|
+
const onChangeExpandedRow = (index) => {
|
|
2816
|
+
setExpandedRows((prevIndices) => {
|
|
2817
|
+
const newIndices = new Set(prevIndices);
|
|
2818
|
+
if (newIndices.has(index)) {
|
|
2819
|
+
newIndices.delete(index);
|
|
2820
|
+
} else {
|
|
2821
|
+
newIndices.add(index);
|
|
2822
|
+
}
|
|
2823
|
+
return newIndices;
|
|
2824
|
+
});
|
|
2825
|
+
};
|
|
2800
2826
|
const handleRowClick = (index) => (e) => {
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
if (isExpanded)
|
|
2804
|
-
|
|
2805
|
-
const newIndices = new Set(prevIndices);
|
|
2806
|
-
if (newIndices.has(index)) {
|
|
2807
|
-
newIndices.delete(index);
|
|
2808
|
-
} else {
|
|
2809
|
-
newIndices.add(index);
|
|
2810
|
-
}
|
|
2811
|
-
return newIndices;
|
|
2812
|
-
});
|
|
2813
|
-
}
|
|
2827
|
+
e.stopPropagation();
|
|
2828
|
+
e.preventDefault();
|
|
2829
|
+
if (isExpanded) onChangeExpandedRow(index);
|
|
2830
|
+
if (isSelected && isSelectedRow) onSelectRow(index);
|
|
2814
2831
|
const row = rows[index];
|
|
2815
2832
|
if (row !== void 0) {
|
|
2816
2833
|
onRowAction == null ? void 0 : onRowAction(e, row);
|
|
@@ -2820,7 +2837,7 @@ var TableBody = ({
|
|
|
2820
2837
|
const keys = Object.keys(row);
|
|
2821
2838
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_react4.default.Fragment, { children: [
|
|
2822
2839
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("tr", { ...getTrProps(rowIndex), onClick: handleRowClick(rowIndex), children: [
|
|
2823
|
-
isSelected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { ...getTdProps({ field: "checkbox" }, row, keys), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(checkbox_default, { color, size }) }),
|
|
2840
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { ...getTdProps({ field: "checkbox" }, row, keys), onClick: () => onSelectRow(rowIndex), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(checkbox_default, { color, size, checked: selectedRows.has(rowIndex) }) }),
|
|
2824
2841
|
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { ...getTdProps({ field: "expandIcon" }, row, keys), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2825
2842
|
Icon_default,
|
|
2826
2843
|
{
|
|
@@ -2831,9 +2848,9 @@ var TableBody = ({
|
|
|
2831
2848
|
) }),
|
|
2832
2849
|
columns.map((column, colIndex) => /* @__PURE__ */ (0, import_react5.createElement)("td", { ...getTdProps(column, row, keys), key: colIndex }))
|
|
2833
2850
|
] }),
|
|
2834
|
-
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { colSpan:
|
|
2851
|
+
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { colSpan: COL_SPAN_COUNT, ...getTdProps({ field: "expandedRow" }, row, keys), children: row.renderExpandedRow && row.renderExpandedRow() }) })
|
|
2835
2852
|
] }, rowIndex);
|
|
2836
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { ...getTrProps(-1), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { colSpan:
|
|
2853
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { ...getTrProps(-1), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { colSpan: COL_SPAN_COUNT, children: emptyContent }) }) });
|
|
2837
2854
|
};
|
|
2838
2855
|
var table_body_default = TableBody;
|
|
2839
2856
|
|
|
@@ -2843,6 +2860,7 @@ var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
|
2843
2860
|
var Table = (0, import_react6.forwardRef)((originalProps, ref) => {
|
|
2844
2861
|
const [props, variantProps] = mapPropsVariants(originalProps, table.variantKeys);
|
|
2845
2862
|
const { classNames, rows, columns, isLoading, className, emptyContent, onRowAction, ...tableComponentsProps } = props;
|
|
2863
|
+
const [selectedRows, setSelectedRows] = (0, import_react6.useState)(/* @__PURE__ */ new Set());
|
|
2846
2864
|
const slots = (0, import_react6.useMemo)(() => table({ ...variantProps }), [...Object.values(variantProps)]);
|
|
2847
2865
|
const getBaseProps = (0, import_react6.useCallback)(
|
|
2848
2866
|
(props2) => ({
|
|
@@ -2858,6 +2876,23 @@ var Table = (0, import_react6.forwardRef)((originalProps, ref) => {
|
|
|
2858
2876
|
}),
|
|
2859
2877
|
[classNames == null ? void 0 : classNames.table, slots]
|
|
2860
2878
|
);
|
|
2879
|
+
const handleSelectAll = (isSelected) => {
|
|
2880
|
+
const newSelectedRows = isSelected ? new Set(rows.map((_, index) => index)) : /* @__PURE__ */ new Set();
|
|
2881
|
+
setSelectedRows(newSelectedRows);
|
|
2882
|
+
};
|
|
2883
|
+
const handleSelectRow = (index) => {
|
|
2884
|
+
const newSelectedRows = new Set(selectedRows);
|
|
2885
|
+
if (newSelectedRows.has(index)) {
|
|
2886
|
+
newSelectedRows.delete(index);
|
|
2887
|
+
} else {
|
|
2888
|
+
newSelectedRows.add(index);
|
|
2889
|
+
}
|
|
2890
|
+
setSelectedRows(newSelectedRows);
|
|
2891
|
+
};
|
|
2892
|
+
(0, import_react6.useImperativeHandle)(ref, () => ({
|
|
2893
|
+
selectedRows,
|
|
2894
|
+
setSelectedRows
|
|
2895
|
+
}));
|
|
2861
2896
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { ref, "data-table": "base", ...getBaseProps(), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("table", { ...getTableProps(tableComponentsProps), children: [
|
|
2862
2897
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2863
2898
|
table_head_default,
|
|
@@ -2868,7 +2903,9 @@ var Table = (0, import_react6.forwardRef)((originalProps, ref) => {
|
|
|
2868
2903
|
size: originalProps.size,
|
|
2869
2904
|
color: originalProps.color === "neutral" ? "primary" : originalProps.color,
|
|
2870
2905
|
isSelected: originalProps.isSelected,
|
|
2871
|
-
isExpanded: originalProps.isExpanded
|
|
2906
|
+
isExpanded: originalProps.isExpanded,
|
|
2907
|
+
onSelectAll: handleSelectAll,
|
|
2908
|
+
isAllSelected: selectedRows.size === rows.length
|
|
2872
2909
|
}
|
|
2873
2910
|
),
|
|
2874
2911
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
@@ -2880,10 +2917,13 @@ var Table = (0, import_react6.forwardRef)((originalProps, ref) => {
|
|
|
2880
2917
|
size: originalProps.size,
|
|
2881
2918
|
color: originalProps.color === "neutral" ? "primary" : originalProps.color,
|
|
2882
2919
|
isSelected: originalProps.isSelected,
|
|
2920
|
+
isSelectedRow: originalProps.isSelectedRow,
|
|
2883
2921
|
isExpanded: originalProps.isExpanded,
|
|
2884
2922
|
isLoading,
|
|
2885
2923
|
classNames,
|
|
2886
2924
|
emptyContent,
|
|
2925
|
+
selectedRows,
|
|
2926
|
+
onSelectRow: handleSelectRow,
|
|
2887
2927
|
onRowAction
|
|
2888
2928
|
}
|
|
2889
2929
|
)
|
|
@@ -2985,6 +3025,9 @@ var table = (0, import_tailwind_variants3.tv)({
|
|
|
2985
3025
|
isSelected: {
|
|
2986
3026
|
true: {}
|
|
2987
3027
|
},
|
|
3028
|
+
isSelectedRow: {
|
|
3029
|
+
true: {}
|
|
3030
|
+
},
|
|
2988
3031
|
hideHeader: {
|
|
2989
3032
|
true: {
|
|
2990
3033
|
thead: "hidden"
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import "../../chunk-2UUH2MBF.mjs";
|
|
3
3
|
import {
|
|
4
4
|
table_default
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
5
|
+
} from "../../chunk-6U736HAX.mjs";
|
|
6
|
+
import "../../chunk-PUFNT5LS.mjs";
|
|
7
|
+
import "../../chunk-BHSCW5D6.mjs";
|
|
8
8
|
import "../../chunk-QZ3LVYJW.mjs";
|
|
9
9
|
import "../../chunk-BE2OG6M4.mjs";
|
|
10
10
|
import "../../chunk-27Y6K5NK.mjs";
|
|
@@ -14,10 +14,13 @@ type TableBodyProps = {
|
|
|
14
14
|
columns: TableColumn[];
|
|
15
15
|
isLoading?: boolean;
|
|
16
16
|
isExpanded?: boolean;
|
|
17
|
-
emptyContent?: ReactNode;
|
|
18
17
|
isSelected?: boolean;
|
|
18
|
+
isSelectedRow?: boolean;
|
|
19
|
+
selectedRows: Set<number>;
|
|
20
|
+
emptyContent?: ReactNode;
|
|
21
|
+
onSelectRow: (index: number) => void;
|
|
19
22
|
onRowAction?: (e: react__default.MouseEvent, params: TableRow) => void;
|
|
20
23
|
};
|
|
21
|
-
declare const TableBody: ({ classNames, size, color, slots, rows, columns, isSelected,
|
|
24
|
+
declare const TableBody: ({ classNames, size, color, slots, rows, columns, isExpanded, isSelected, isSelectedRow, selectedRows, emptyContent, onSelectRow, onRowAction, }: TableBodyProps) => react_jsx_runtime.JSX.Element;
|
|
22
25
|
|
|
23
26
|
export { TableBody as default };
|
|
@@ -14,10 +14,13 @@ type TableBodyProps = {
|
|
|
14
14
|
columns: TableColumn[];
|
|
15
15
|
isLoading?: boolean;
|
|
16
16
|
isExpanded?: boolean;
|
|
17
|
-
emptyContent?: ReactNode;
|
|
18
17
|
isSelected?: boolean;
|
|
18
|
+
isSelectedRow?: boolean;
|
|
19
|
+
selectedRows: Set<number>;
|
|
20
|
+
emptyContent?: ReactNode;
|
|
21
|
+
onSelectRow: (index: number) => void;
|
|
19
22
|
onRowAction?: (e: react__default.MouseEvent, params: TableRow) => void;
|
|
20
23
|
};
|
|
21
|
-
declare const TableBody: ({ classNames, size, color, slots, rows, columns, isSelected,
|
|
24
|
+
declare const TableBody: ({ classNames, size, color, slots, rows, columns, isExpanded, isSelected, isSelectedRow, selectedRows, emptyContent, onSelectRow, onRowAction, }: TableBodyProps) => react_jsx_runtime.JSX.Element;
|
|
22
25
|
|
|
23
26
|
export { TableBody as default };
|
|
@@ -2700,12 +2700,15 @@ var TableBody = ({
|
|
|
2700
2700
|
slots,
|
|
2701
2701
|
rows,
|
|
2702
2702
|
columns,
|
|
2703
|
-
isSelected,
|
|
2704
2703
|
isExpanded,
|
|
2704
|
+
isSelected,
|
|
2705
|
+
isSelectedRow,
|
|
2706
|
+
selectedRows,
|
|
2705
2707
|
emptyContent,
|
|
2708
|
+
onSelectRow,
|
|
2706
2709
|
onRowAction
|
|
2707
2710
|
}) => {
|
|
2708
|
-
const
|
|
2711
|
+
const COL_SPAN_COUNT = columns.length + (isExpanded ? 1 : 0) + (isSelected ? 1 : 0);
|
|
2709
2712
|
const [expandedRows, setExpandedRows] = (0, import_react2.useState)(/* @__PURE__ */ new Set());
|
|
2710
2713
|
(0, import_react2.useEffect)(() => {
|
|
2711
2714
|
setExpandedRows(/* @__PURE__ */ new Set());
|
|
@@ -2757,20 +2760,22 @@ var TableBody = ({
|
|
|
2757
2760
|
},
|
|
2758
2761
|
[classNames == null ? void 0 : classNames.td, columns, slots]
|
|
2759
2762
|
);
|
|
2763
|
+
const onChangeExpandedRow = (index) => {
|
|
2764
|
+
setExpandedRows((prevIndices) => {
|
|
2765
|
+
const newIndices = new Set(prevIndices);
|
|
2766
|
+
if (newIndices.has(index)) {
|
|
2767
|
+
newIndices.delete(index);
|
|
2768
|
+
} else {
|
|
2769
|
+
newIndices.add(index);
|
|
2770
|
+
}
|
|
2771
|
+
return newIndices;
|
|
2772
|
+
});
|
|
2773
|
+
};
|
|
2760
2774
|
const handleRowClick = (index) => (e) => {
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
if (isExpanded)
|
|
2764
|
-
|
|
2765
|
-
const newIndices = new Set(prevIndices);
|
|
2766
|
-
if (newIndices.has(index)) {
|
|
2767
|
-
newIndices.delete(index);
|
|
2768
|
-
} else {
|
|
2769
|
-
newIndices.add(index);
|
|
2770
|
-
}
|
|
2771
|
-
return newIndices;
|
|
2772
|
-
});
|
|
2773
|
-
}
|
|
2775
|
+
e.stopPropagation();
|
|
2776
|
+
e.preventDefault();
|
|
2777
|
+
if (isExpanded) onChangeExpandedRow(index);
|
|
2778
|
+
if (isSelected && isSelectedRow) onSelectRow(index);
|
|
2774
2779
|
const row = rows[index];
|
|
2775
2780
|
if (row !== void 0) {
|
|
2776
2781
|
onRowAction == null ? void 0 : onRowAction(e, row);
|
|
@@ -2780,7 +2785,7 @@ var TableBody = ({
|
|
|
2780
2785
|
const keys = Object.keys(row);
|
|
2781
2786
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react2.default.Fragment, { children: [
|
|
2782
2787
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("tr", { ...getTrProps(rowIndex), onClick: handleRowClick(rowIndex), children: [
|
|
2783
|
-
isSelected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { ...getTdProps({ field: "checkbox" }, row, keys), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(checkbox_default, { color, size }) }),
|
|
2788
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { ...getTdProps({ field: "checkbox" }, row, keys), onClick: () => onSelectRow(rowIndex), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(checkbox_default, { color, size, checked: selectedRows.has(rowIndex) }) }),
|
|
2784
2789
|
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { ...getTdProps({ field: "expandIcon" }, row, keys), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2785
2790
|
Icon_default,
|
|
2786
2791
|
{
|
|
@@ -2791,8 +2796,8 @@ var TableBody = ({
|
|
|
2791
2796
|
) }),
|
|
2792
2797
|
columns.map((column, colIndex) => /* @__PURE__ */ (0, import_react3.createElement)("td", { ...getTdProps(column, row, keys), key: colIndex }))
|
|
2793
2798
|
] }),
|
|
2794
|
-
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { colSpan:
|
|
2799
|
+
isExpanded && expandedRows.has(rowIndex) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tr", { ...getExpandedContentProps(), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { colSpan: COL_SPAN_COUNT, ...getTdProps({ field: "expandedRow" }, row, keys), children: row.renderExpandedRow && row.renderExpandedRow() }) })
|
|
2795
2800
|
] }, rowIndex);
|
|
2796
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tr", { ...getTrProps(-1), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { colSpan:
|
|
2801
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("tr", { ...getTrProps(-1), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("td", { colSpan: COL_SPAN_COUNT, children: emptyContent }) }) });
|
|
2797
2802
|
};
|
|
2798
2803
|
var table_body_default = TableBody;
|
|
@@ -10,10 +10,12 @@ type TableHeadProps = {
|
|
|
10
10
|
slots: TableReturnType;
|
|
11
11
|
size?: "md" | "sm" | "lg";
|
|
12
12
|
color?: "primary" | "secondary";
|
|
13
|
-
isSelected?: boolean;
|
|
14
13
|
isExpanded?: boolean;
|
|
14
|
+
isSelected?: boolean;
|
|
15
|
+
isAllSelected: boolean;
|
|
15
16
|
classNames?: SlotsToClasses<TableSlots>;
|
|
17
|
+
onSelectAll: (isSelected: boolean) => void;
|
|
16
18
|
};
|
|
17
|
-
declare const TableHead: ({ columns, slots, size, color, isSelected,
|
|
19
|
+
declare const TableHead: ({ columns, slots, size, color, isExpanded, isSelected, isAllSelected, classNames, onSelectAll, }: TableHeadProps) => react_jsx_runtime.JSX.Element;
|
|
18
20
|
|
|
19
21
|
export { TableHead as default };
|
|
@@ -10,10 +10,12 @@ type TableHeadProps = {
|
|
|
10
10
|
slots: TableReturnType;
|
|
11
11
|
size?: "md" | "sm" | "lg";
|
|
12
12
|
color?: "primary" | "secondary";
|
|
13
|
-
isSelected?: boolean;
|
|
14
13
|
isExpanded?: boolean;
|
|
14
|
+
isSelected?: boolean;
|
|
15
|
+
isAllSelected: boolean;
|
|
15
16
|
classNames?: SlotsToClasses<TableSlots>;
|
|
17
|
+
onSelectAll: (isSelected: boolean) => void;
|
|
16
18
|
};
|
|
17
|
-
declare const TableHead: ({ columns, slots, size, color, isSelected,
|
|
19
|
+
declare const TableHead: ({ columns, slots, size, color, isExpanded, isSelected, isAllSelected, classNames, onSelectAll, }: TableHeadProps) => react_jsx_runtime.JSX.Element;
|
|
18
20
|
|
|
19
21
|
export { TableHead as default };
|
|
@@ -292,7 +292,17 @@ var checkbox = tv({
|
|
|
292
292
|
// src/components/table/table-head.tsx
|
|
293
293
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
294
294
|
var import_react3 = require("react");
|
|
295
|
-
var TableHead = ({
|
|
295
|
+
var TableHead = ({
|
|
296
|
+
columns,
|
|
297
|
+
slots,
|
|
298
|
+
size,
|
|
299
|
+
color,
|
|
300
|
+
isExpanded,
|
|
301
|
+
isSelected,
|
|
302
|
+
isAllSelected,
|
|
303
|
+
classNames,
|
|
304
|
+
onSelectAll
|
|
305
|
+
}) => {
|
|
296
306
|
const getTheadProps = (0, import_react2.useCallback)(
|
|
297
307
|
() => ({
|
|
298
308
|
className: slots.thead({ class: clsx(classNames == null ? void 0 : classNames.thead) })
|
|
@@ -309,14 +319,16 @@ var TableHead = ({ columns, slots, size, color, isSelected, isExpanded, classNam
|
|
|
309
319
|
({ className }) => ({
|
|
310
320
|
className: slots.th({ class: clsx(classNames == null ? void 0 : classNames.th, className) })
|
|
311
321
|
}),
|
|
312
|
-
[classNames == null ? void 0 : classNames.th,
|
|
322
|
+
[classNames == null ? void 0 : classNames.th, slots]
|
|
313
323
|
);
|
|
324
|
+
const handleClickSelectAll = (e) => {
|
|
325
|
+
e.preventDefault();
|
|
326
|
+
onSelectAll(!isAllSelected);
|
|
327
|
+
};
|
|
314
328
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("thead", { ...getTheadProps(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tr", { ...getTrProps(), children: [
|
|
315
|
-
isSelected && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(checkbox_default, { size, color, classNames: { wrapper: "bg-background" } }) }),
|
|
329
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]", onClick: handleClickSelectAll, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(checkbox_default, { size, color, checked: isAllSelected, classNames: { wrapper: "bg-background" } }) }),
|
|
316
330
|
isExpanded && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("th", { className: "w-[40px]" }),
|
|
317
|
-
columns.map((column, index) => {
|
|
318
|
-
return /* @__PURE__ */ (0, import_react3.createElement)("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName);
|
|
319
|
-
})
|
|
331
|
+
columns.map((column, index) => /* @__PURE__ */ (0, import_react3.createElement)("th", { ...getThProps(column), key: column.field + index + "th" }, column.headerName))
|
|
320
332
|
] }) });
|
|
321
333
|
};
|
|
322
334
|
var table_head_default = TableHead;
|