@expcat/tigercat-react 0.3.70 → 0.4.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/{chunk-ZTVATZB6.js → chunk-6OVVMHZJ.js} +137 -70
- package/dist/{chunk-ZGQOYCQT.mjs → chunk-FX2IBA4W.mjs} +1 -1
- package/dist/{chunk-PWZB45Z7.js → chunk-JQK354YN.js} +11 -9
- package/dist/chunk-JWFEJ4XG.js +543 -0
- package/dist/chunk-PEGJ2KHC.js +273 -0
- package/dist/{chunk-3577FW3I.mjs → chunk-PJ7NS7NX.mjs} +139 -72
- package/dist/chunk-PJCY45UP.mjs +536 -0
- package/dist/{chunk-IRH2ZVD3.js → chunk-Q7GUWWG5.js} +2 -2
- package/dist/chunk-RCNTRSUA.mjs +271 -0
- package/dist/chunk-SHT4TU3T.mjs +26 -0
- package/dist/{chunk-OUAZM7NY.mjs → chunk-SMC2RV3V.mjs} +12 -10
- package/dist/{chunk-OESNOOOT.js → chunk-YWTZALG5.js} +8 -4
- package/dist/components/ActivityFeed.js +4 -4
- package/dist/components/ActivityFeed.mjs +2 -2
- package/dist/components/DataTableWithToolbar.js +4 -4
- package/dist/components/DataTableWithToolbar.mjs +2 -2
- package/dist/components/InputNumber.d.mts +24 -0
- package/dist/components/InputNumber.d.ts +24 -0
- package/dist/components/InputNumber.js +10 -0
- package/dist/components/InputNumber.mjs +1 -0
- package/dist/components/Sidebar.js +2 -2
- package/dist/components/Sidebar.mjs +1 -1
- package/dist/components/SubMenu.js +2 -2
- package/dist/components/SubMenu.mjs +1 -1
- package/dist/components/Table.d.mts +5 -1
- package/dist/components/Table.d.ts +5 -1
- package/dist/components/Table.js +2 -2
- package/dist/components/Table.mjs +1 -1
- package/dist/components/TaskBoard.d.mts +13 -0
- package/dist/components/TaskBoard.d.ts +13 -0
- package/dist/components/TaskBoard.js +17 -0
- package/dist/components/TaskBoard.mjs +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +50 -40
- package/dist/index.mjs +13 -11
- package/package.json +2 -2
- package/dist/chunk-RITTIFCJ.mjs +0 -22
- package/dist/{chunk-IOM7DWWQ.js → chunk-J3HKED4B.js} +1 -1
- package/dist/{chunk-FTY2W4L2.mjs → chunk-MTL2QUM3.mjs} +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var tigercatCore = require('@expcat/tigercat-core');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/components/InputNumber.tsx
|
|
8
|
+
var InputNumber = ({
|
|
9
|
+
value: controlledValue,
|
|
10
|
+
defaultValue,
|
|
11
|
+
size = "md",
|
|
12
|
+
status = "default",
|
|
13
|
+
min = -Infinity,
|
|
14
|
+
max = Infinity,
|
|
15
|
+
step = 1,
|
|
16
|
+
precision,
|
|
17
|
+
disabled = false,
|
|
18
|
+
readonly = false,
|
|
19
|
+
placeholder,
|
|
20
|
+
name,
|
|
21
|
+
id,
|
|
22
|
+
keyboard = true,
|
|
23
|
+
controls = true,
|
|
24
|
+
controlsPosition = "right",
|
|
25
|
+
formatter,
|
|
26
|
+
parser,
|
|
27
|
+
autoFocus = false,
|
|
28
|
+
onChange,
|
|
29
|
+
onFocus,
|
|
30
|
+
onBlur,
|
|
31
|
+
className
|
|
32
|
+
}) => {
|
|
33
|
+
const isControlled = controlledValue !== void 0;
|
|
34
|
+
const inputRef = react.useRef(null);
|
|
35
|
+
const [focused, setFocused] = react.useState(false);
|
|
36
|
+
const [internalValue, setInternalValue] = react.useState(
|
|
37
|
+
defaultValue ?? controlledValue ?? null
|
|
38
|
+
);
|
|
39
|
+
const [displayValue, setDisplayValue] = react.useState("");
|
|
40
|
+
const currentValue = isControlled ? controlledValue ?? null : internalValue;
|
|
41
|
+
const toDisplayValue = react.useCallback(
|
|
42
|
+
(val) => {
|
|
43
|
+
if (val === null || val === void 0) return "";
|
|
44
|
+
if (formatter) return formatter(val);
|
|
45
|
+
if (precision !== void 0) return val.toFixed(precision);
|
|
46
|
+
return String(val);
|
|
47
|
+
},
|
|
48
|
+
[formatter, precision]
|
|
49
|
+
);
|
|
50
|
+
const parseValue = react.useCallback(
|
|
51
|
+
(str) => {
|
|
52
|
+
if (str === "" || str === "-") return null;
|
|
53
|
+
if (parser) return parser(str);
|
|
54
|
+
const num = Number(str);
|
|
55
|
+
return Number.isNaN(num) ? null : num;
|
|
56
|
+
},
|
|
57
|
+
[parser]
|
|
58
|
+
);
|
|
59
|
+
react.useEffect(() => {
|
|
60
|
+
if (!focused) {
|
|
61
|
+
setDisplayValue(toDisplayValue(currentValue));
|
|
62
|
+
}
|
|
63
|
+
}, [currentValue, focused, toDisplayValue]);
|
|
64
|
+
react.useEffect(() => {
|
|
65
|
+
if (autoFocus && inputRef.current) {
|
|
66
|
+
inputRef.current.focus();
|
|
67
|
+
}
|
|
68
|
+
}, [autoFocus]);
|
|
69
|
+
const commitValue = react.useCallback(
|
|
70
|
+
(val) => {
|
|
71
|
+
let finalVal = val;
|
|
72
|
+
if (finalVal !== null) {
|
|
73
|
+
finalVal = tigercatCore.clampValue(finalVal, min, max);
|
|
74
|
+
if (precision !== void 0) {
|
|
75
|
+
finalVal = tigercatCore.formatPrecision(finalVal, precision);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!isControlled) {
|
|
79
|
+
setInternalValue(finalVal);
|
|
80
|
+
}
|
|
81
|
+
onChange?.(finalVal);
|
|
82
|
+
setDisplayValue(toDisplayValue(finalVal));
|
|
83
|
+
},
|
|
84
|
+
[min, max, precision, isControlled, onChange, toDisplayValue]
|
|
85
|
+
);
|
|
86
|
+
const handleStep = react.useCallback(
|
|
87
|
+
(direction) => {
|
|
88
|
+
if (disabled || readonly) return;
|
|
89
|
+
const next = tigercatCore.stepValue(currentValue, step, direction, min, max, precision);
|
|
90
|
+
commitValue(next);
|
|
91
|
+
},
|
|
92
|
+
[currentValue, step, min, max, precision, disabled, readonly, commitValue]
|
|
93
|
+
);
|
|
94
|
+
const handleInput = react.useCallback((e) => {
|
|
95
|
+
setDisplayValue(e.target.value);
|
|
96
|
+
}, []);
|
|
97
|
+
const handleBlur = react.useCallback(
|
|
98
|
+
(e) => {
|
|
99
|
+
setFocused(false);
|
|
100
|
+
const parsed = parseValue(displayValue);
|
|
101
|
+
commitValue(parsed);
|
|
102
|
+
onBlur?.(e);
|
|
103
|
+
},
|
|
104
|
+
[displayValue, parseValue, commitValue, onBlur]
|
|
105
|
+
);
|
|
106
|
+
const handleFocus = react.useCallback(
|
|
107
|
+
(e) => {
|
|
108
|
+
setFocused(true);
|
|
109
|
+
if (formatter && currentValue !== null) {
|
|
110
|
+
setDisplayValue(String(currentValue));
|
|
111
|
+
}
|
|
112
|
+
onFocus?.(e);
|
|
113
|
+
},
|
|
114
|
+
[formatter, currentValue, onFocus]
|
|
115
|
+
);
|
|
116
|
+
const handleKeyDown = react.useCallback(
|
|
117
|
+
(e) => {
|
|
118
|
+
if (!keyboard || disabled || readonly) return;
|
|
119
|
+
if (e.key === "ArrowUp") {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
handleStep("up");
|
|
122
|
+
} else if (e.key === "ArrowDown") {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
handleStep("down");
|
|
125
|
+
} else if (e.key === "Enter") {
|
|
126
|
+
const parsed = parseValue(displayValue);
|
|
127
|
+
commitValue(parsed);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
[keyboard, disabled, readonly, handleStep, parseValue, displayValue, commitValue]
|
|
131
|
+
);
|
|
132
|
+
const atMin = tigercatCore.isAtMin(currentValue, min);
|
|
133
|
+
const atMax = tigercatCore.isAtMax(currentValue, max);
|
|
134
|
+
const wrapperClasses = react.useMemo(
|
|
135
|
+
() => tigercatCore.classNames(
|
|
136
|
+
tigercatCore.getInputNumberWrapperClasses(disabled),
|
|
137
|
+
tigercatCore.getInputNumberStatusClasses(status),
|
|
138
|
+
tigercatCore.getInputNumberSizeClasses(size),
|
|
139
|
+
focused && `ring-2 ${tigercatCore.getInputNumberFocusRingColor(status)}`,
|
|
140
|
+
className
|
|
141
|
+
),
|
|
142
|
+
[disabled, status, size, focused, className]
|
|
143
|
+
);
|
|
144
|
+
const inputClasses = react.useMemo(
|
|
145
|
+
() => tigercatCore.getInputNumberInputClasses(
|
|
146
|
+
size,
|
|
147
|
+
controls && controlsPosition === "right",
|
|
148
|
+
controls && controlsPosition === "both"
|
|
149
|
+
),
|
|
150
|
+
[size, controls, controlsPosition]
|
|
151
|
+
);
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: wrapperClasses, children: [
|
|
153
|
+
controls && controlsPosition === "both" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
154
|
+
"button",
|
|
155
|
+
{
|
|
156
|
+
type: "button",
|
|
157
|
+
tabIndex: -1,
|
|
158
|
+
"aria-label": "Decrease",
|
|
159
|
+
className: tigercatCore.getInputNumberSideButtonClasses("left", disabled || atMin),
|
|
160
|
+
disabled: disabled || atMin,
|
|
161
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
162
|
+
onClick: () => handleStep("down"),
|
|
163
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
164
|
+
"svg",
|
|
165
|
+
{
|
|
166
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
167
|
+
viewBox: "0 0 24 24",
|
|
168
|
+
fill: "none",
|
|
169
|
+
stroke: "currentColor",
|
|
170
|
+
strokeWidth: "2",
|
|
171
|
+
className: "w-4 h-4",
|
|
172
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: tigercatCore.inputNumberMinusIconPathD })
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
178
|
+
"input",
|
|
179
|
+
{
|
|
180
|
+
ref: inputRef,
|
|
181
|
+
type: "text",
|
|
182
|
+
inputMode: "decimal",
|
|
183
|
+
role: "spinbutton",
|
|
184
|
+
"aria-valuemin": min === -Infinity ? void 0 : min,
|
|
185
|
+
"aria-valuemax": max === Infinity ? void 0 : max,
|
|
186
|
+
"aria-valuenow": currentValue ?? void 0,
|
|
187
|
+
className: inputClasses,
|
|
188
|
+
value: displayValue,
|
|
189
|
+
placeholder,
|
|
190
|
+
disabled,
|
|
191
|
+
readOnly: readonly,
|
|
192
|
+
name,
|
|
193
|
+
id,
|
|
194
|
+
onChange: handleInput,
|
|
195
|
+
onBlur: handleBlur,
|
|
196
|
+
onFocus: handleFocus,
|
|
197
|
+
onKeyDown: handleKeyDown
|
|
198
|
+
}
|
|
199
|
+
),
|
|
200
|
+
controls && controlsPosition === "both" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
201
|
+
"button",
|
|
202
|
+
{
|
|
203
|
+
type: "button",
|
|
204
|
+
tabIndex: -1,
|
|
205
|
+
"aria-label": "Increase",
|
|
206
|
+
className: tigercatCore.getInputNumberSideButtonClasses("right", disabled || atMax),
|
|
207
|
+
disabled: disabled || atMax,
|
|
208
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
209
|
+
onClick: () => handleStep("up"),
|
|
210
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
211
|
+
"svg",
|
|
212
|
+
{
|
|
213
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
214
|
+
viewBox: "0 0 24 24",
|
|
215
|
+
fill: "none",
|
|
216
|
+
stroke: "currentColor",
|
|
217
|
+
strokeWidth: "2",
|
|
218
|
+
className: "w-4 h-4",
|
|
219
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: tigercatCore.inputNumberPlusIconPathD })
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
),
|
|
224
|
+
controls && controlsPosition === "right" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tigercatCore.inputNumberControlsRightClasses, children: [
|
|
225
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
226
|
+
"button",
|
|
227
|
+
{
|
|
228
|
+
type: "button",
|
|
229
|
+
tabIndex: -1,
|
|
230
|
+
"aria-label": "Increase",
|
|
231
|
+
className: tigercatCore.getInputNumberStepButtonClasses("up", disabled || atMax),
|
|
232
|
+
disabled: disabled || atMax,
|
|
233
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
234
|
+
onClick: () => handleStep("up"),
|
|
235
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
"svg",
|
|
237
|
+
{
|
|
238
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
239
|
+
viewBox: "0 0 24 24",
|
|
240
|
+
fill: "currentColor",
|
|
241
|
+
className: "w-3 h-3",
|
|
242
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: tigercatCore.inputNumberUpIconPathD })
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
),
|
|
247
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
248
|
+
"button",
|
|
249
|
+
{
|
|
250
|
+
type: "button",
|
|
251
|
+
tabIndex: -1,
|
|
252
|
+
"aria-label": "Decrease",
|
|
253
|
+
className: tigercatCore.getInputNumberStepButtonClasses("down", disabled || atMin),
|
|
254
|
+
disabled: disabled || atMin,
|
|
255
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
256
|
+
onClick: () => handleStep("down"),
|
|
257
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
258
|
+
"svg",
|
|
259
|
+
{
|
|
260
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
261
|
+
viewBox: "0 0 24 24",
|
|
262
|
+
fill: "currentColor",
|
|
263
|
+
className: "w-3 h-3",
|
|
264
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: tigercatCore.inputNumberDownIconPathD })
|
|
265
|
+
}
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
] })
|
|
270
|
+
] });
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
exports.InputNumber = InputNumber;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo, useCallback } from 'react';
|
|
2
|
-
import { getSpinnerSVG, getFixedColumnOffsets, filterData, sortData, paginateData, getRowKey, calculatePagination, getTableHeaderClasses, getCheckboxCellClasses, classNames, getTableHeaderCellClasses, tableEmptyStateClasses, getTableCellClasses, getTableRowClasses, getSimplePaginationContainerClasses, getSimplePaginationTotalClasses, getSimplePaginationControlsClasses, getSimplePaginationSelectClasses, getSimplePaginationButtonsWrapperClasses, getSimplePaginationButtonClasses, getSimplePaginationPageIndicatorClasses, getTableWrapperClasses, tableBaseClasses, tableLoadingOverlayClasses, icon24ViewBox, lockClosedIcon24PathD, lockOpenIcon24PathD,
|
|
1
|
+
import { useState, useEffect, useMemo, useCallback, Fragment } from 'react';
|
|
2
|
+
import { getSpinnerSVG, getFixedColumnOffsets, filterData, sortData, paginateData, getRowKey, calculatePagination, getTableHeaderClasses, getExpandCellClasses, getCheckboxCellClasses, classNames, getTableHeaderCellClasses, tableEmptyStateClasses, getTableCellClasses, getTableRowClasses, expandedRowContentClasses, getSimplePaginationContainerClasses, getSimplePaginationTotalClasses, getSimplePaginationControlsClasses, getSimplePaginationSelectClasses, getSimplePaginationButtonsWrapperClasses, getSimplePaginationButtonClasses, getSimplePaginationPageIndicatorClasses, getTableWrapperClasses, tableBaseClasses, tableLoadingOverlayClasses, icon16ViewBox, expandIconButtonClasses, getExpandIconRotationClasses, icon24ViewBox, lockClosedIcon24PathD, lockOpenIcon24PathD, getSortIconClasses, sortAscIcon16PathD, sortDescIcon16PathD, sortBothIcon16PathD, getLoadingOverlaySpinnerClasses } from '@expcat/tigercat-core';
|
|
3
3
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
// src/components/Table.tsx
|
|
@@ -64,12 +64,14 @@ function Table({
|
|
|
64
64
|
stickyHeader = false,
|
|
65
65
|
maxHeight,
|
|
66
66
|
tableLayout = "auto",
|
|
67
|
+
expandable,
|
|
67
68
|
onChange,
|
|
68
69
|
onRowClick,
|
|
69
70
|
onSelectionChange,
|
|
70
71
|
onSortChange,
|
|
71
72
|
onFilterChange,
|
|
72
73
|
onPageChange,
|
|
74
|
+
onExpandedRowsChange,
|
|
73
75
|
className,
|
|
74
76
|
...props
|
|
75
77
|
}) {
|
|
@@ -122,6 +124,24 @@ function Table({
|
|
|
122
124
|
setUncontrolledSelectedRowKeys(rowSelection?.selectedRowKeys ?? []);
|
|
123
125
|
}
|
|
124
126
|
}, [isSelectionControlled, rowSelection?.selectedRowKeys]);
|
|
127
|
+
const isExpandControlled = expandable?.expandedRowKeys !== void 0;
|
|
128
|
+
const [uncontrolledExpandedRowKeys, setUncontrolledExpandedRowKeys] = useState(expandable?.defaultExpandedRowKeys ?? expandable?.expandedRowKeys ?? []);
|
|
129
|
+
const expandedRowKeys = isExpandControlled ? expandable.expandedRowKeys : uncontrolledExpandedRowKeys;
|
|
130
|
+
const expandedRowKeySet = useMemo(
|
|
131
|
+
() => new Set(expandedRowKeys),
|
|
132
|
+
[expandedRowKeys]
|
|
133
|
+
);
|
|
134
|
+
const handleToggleExpand = useCallback(
|
|
135
|
+
(key) => {
|
|
136
|
+
const isExp = expandedRowKeySet.has(key);
|
|
137
|
+
const next = isExp ? expandedRowKeys.filter((k) => k !== key) : [...expandedRowKeys, key];
|
|
138
|
+
if (!isExpandControlled) {
|
|
139
|
+
setUncontrolledExpandedRowKeys(next);
|
|
140
|
+
}
|
|
141
|
+
onExpandedRowsChange?.(next);
|
|
142
|
+
},
|
|
143
|
+
[expandedRowKeys, expandedRowKeySet, isExpandControlled, onExpandedRowsChange]
|
|
144
|
+
);
|
|
125
145
|
const [fixedOverrides, setFixedOverrides] = useState({});
|
|
126
146
|
const displayColumns = useMemo(() => {
|
|
127
147
|
return columns.map((column) => {
|
|
@@ -132,6 +152,12 @@ function Table({
|
|
|
132
152
|
};
|
|
133
153
|
});
|
|
134
154
|
}, [columns, fixedOverrides]);
|
|
155
|
+
const totalColumnCount = useMemo(() => {
|
|
156
|
+
let count = displayColumns.length;
|
|
157
|
+
if (rowSelection && rowSelection.showCheckbox !== false) count++;
|
|
158
|
+
if (expandable) count++;
|
|
159
|
+
return count;
|
|
160
|
+
}, [displayColumns.length, rowSelection, expandable]);
|
|
135
161
|
const columnByKey = useMemo(() => {
|
|
136
162
|
const map = {};
|
|
137
163
|
for (const column of displayColumns) {
|
|
@@ -343,6 +369,7 @@ function Table({
|
|
|
343
369
|
}, [selectedRowKeys.length, allSelected]);
|
|
344
370
|
const renderTableHeader = useCallback(() => {
|
|
345
371
|
return /* @__PURE__ */ jsx("thead", { className: getTableHeaderClasses(stickyHeader), children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
372
|
+
expandable && expandable.expandIconPosition !== "end" && /* @__PURE__ */ jsx("th", { className: getExpandCellClasses(size) }),
|
|
346
373
|
rowSelection && rowSelection.showCheckbox !== false && rowSelection.type !== "radio" && /* @__PURE__ */ jsx("th", { className: getCheckboxCellClasses(size), children: /* @__PURE__ */ jsx(
|
|
347
374
|
"input",
|
|
348
375
|
{
|
|
@@ -435,7 +462,8 @@ function Table({
|
|
|
435
462
|
},
|
|
436
463
|
column.key
|
|
437
464
|
);
|
|
438
|
-
})
|
|
465
|
+
}),
|
|
466
|
+
expandable && expandable.expandIconPosition === "end" && /* @__PURE__ */ jsx("th", { className: getExpandCellClasses(size) })
|
|
439
467
|
] }) });
|
|
440
468
|
}, [
|
|
441
469
|
displayColumns,
|
|
@@ -450,86 +478,121 @@ function Table({
|
|
|
450
478
|
handleSelectAll,
|
|
451
479
|
columnLockable,
|
|
452
480
|
toggleColumnLock,
|
|
453
|
-
fixedColumnsInfo
|
|
481
|
+
fixedColumnsInfo,
|
|
482
|
+
expandable
|
|
454
483
|
]);
|
|
455
484
|
const renderTableBody = useCallback(() => {
|
|
456
485
|
if (loading) {
|
|
457
486
|
return null;
|
|
458
487
|
}
|
|
459
488
|
if (paginatedData.length === 0) {
|
|
460
|
-
return /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
|
|
461
|
-
"td",
|
|
462
|
-
{
|
|
463
|
-
colSpan: displayColumns.length + (rowSelection ? 1 : 0),
|
|
464
|
-
className: tableEmptyStateClasses,
|
|
465
|
-
children: /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", children: emptyText })
|
|
466
|
-
}
|
|
467
|
-
) }) });
|
|
489
|
+
return /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: totalColumnCount, className: tableEmptyStateClasses, children: /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", children: emptyText }) }) }) });
|
|
468
490
|
}
|
|
491
|
+
const ExpandToggle = ({ rowKey: rk, expandableRow, expanded }) => expandableRow ? /* @__PURE__ */ jsx(
|
|
492
|
+
"button",
|
|
493
|
+
{
|
|
494
|
+
className: classNames(expandIconButtonClasses, getExpandIconRotationClasses(expanded)),
|
|
495
|
+
"aria-label": expanded ? "Collapse row" : "Expand row",
|
|
496
|
+
onClick: (e) => {
|
|
497
|
+
e.stopPropagation();
|
|
498
|
+
handleToggleExpand(rk);
|
|
499
|
+
},
|
|
500
|
+
children: /* @__PURE__ */ jsx(
|
|
501
|
+
"svg",
|
|
502
|
+
{
|
|
503
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
504
|
+
viewBox: icon16ViewBox,
|
|
505
|
+
fill: "currentColor",
|
|
506
|
+
className: "w-4 h-4",
|
|
507
|
+
children: /* @__PURE__ */ jsx("path", { d: "M6 3l6 5-6 5V3z" })
|
|
508
|
+
}
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
) : null;
|
|
469
512
|
return /* @__PURE__ */ jsx("tbody", { children: paginatedData.map((record, index) => {
|
|
470
513
|
const key = pageRowKeys[index];
|
|
471
514
|
const isSelected = selectedRowKeySet.has(key);
|
|
515
|
+
const isExpanded = expandedRowKeySet.has(key);
|
|
516
|
+
const isExpandableRow = expandable ? expandable.rowExpandable?.(record) ?? true : false;
|
|
472
517
|
const rowClass = typeof rowClassName === "function" ? rowClassName(record, index) : rowClassName;
|
|
473
|
-
return /* @__PURE__ */ jsxs(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
"
|
|
484
|
-
|
|
485
|
-
type: rowSelection?.type === "radio" ? "radio" : "checkbox",
|
|
486
|
-
className: rowSelection?.type === "radio" ? "border-gray-300 text-[var(--tiger-primary,#2563eb)] focus:ring-[var(--tiger-primary,#2563eb)]" : "rounded border-gray-300 text-[var(--tiger-primary,#2563eb)] focus:ring-[var(--tiger-primary,#2563eb)]",
|
|
487
|
-
checked: isSelected,
|
|
488
|
-
disabled: rowSelection?.getCheckboxProps?.(record)?.disabled,
|
|
489
|
-
onChange: (e) => handleSelectRow(key, e.target.checked),
|
|
490
|
-
onClick: (e) => e.stopPropagation()
|
|
491
|
-
}
|
|
492
|
-
) }),
|
|
493
|
-
displayColumns.map((column) => {
|
|
494
|
-
const dataKey = column.dataKey || column.key;
|
|
495
|
-
const cellValue = record[dataKey];
|
|
496
|
-
const isFixedLeft = column.fixed === "left";
|
|
497
|
-
const isFixedRight = column.fixed === "right";
|
|
498
|
-
const fixedStyle = isFixedLeft ? {
|
|
499
|
-
position: "sticky",
|
|
500
|
-
left: `${fixedColumnsInfo.leftOffsets[column.key] || 0}px`,
|
|
501
|
-
zIndex: 10
|
|
502
|
-
} : isFixedRight ? {
|
|
503
|
-
position: "sticky",
|
|
504
|
-
right: `${fixedColumnsInfo.rightOffsets[column.key] || 0}px`,
|
|
505
|
-
zIndex: 10
|
|
506
|
-
} : void 0;
|
|
507
|
-
const widthStyle = column.width ? {
|
|
508
|
-
width: typeof column.width === "number" ? `${column.width}px` : column.width
|
|
509
|
-
} : void 0;
|
|
510
|
-
const style = fixedStyle ? { ...widthStyle, ...fixedStyle } : widthStyle;
|
|
511
|
-
const stickyBgClass = striped && index % 2 === 0 ? "bg-[var(--tiger-surface-muted,#f9fafb)]/50" : "bg-[var(--tiger-surface,#ffffff)]";
|
|
512
|
-
const stickyCellClass = isFixedLeft || isFixedRight ? classNames(
|
|
513
|
-
stickyBgClass,
|
|
514
|
-
hoverable && "group-hover:bg-[var(--tiger-surface-muted,#f9fafb)]"
|
|
515
|
-
) : void 0;
|
|
516
|
-
return /* @__PURE__ */ jsx(
|
|
517
|
-
"td",
|
|
518
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
519
|
+
/* @__PURE__ */ jsxs(
|
|
520
|
+
"tr",
|
|
521
|
+
{
|
|
522
|
+
className: classNames(
|
|
523
|
+
getTableRowClasses(hoverable, striped, index % 2 === 0, rowClass),
|
|
524
|
+
fixedColumnsInfo.hasFixedColumns && "group"
|
|
525
|
+
),
|
|
526
|
+
onClick: () => handleRowClick(record, index),
|
|
527
|
+
children: [
|
|
528
|
+
expandable && expandable.expandIconPosition !== "end" && /* @__PURE__ */ jsx("td", { className: getExpandCellClasses(size), children: /* @__PURE__ */ jsx(
|
|
529
|
+
ExpandToggle,
|
|
518
530
|
{
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
531
|
+
rowKey: key,
|
|
532
|
+
expandableRow: isExpandableRow,
|
|
533
|
+
expanded: isExpanded
|
|
534
|
+
}
|
|
535
|
+
) }),
|
|
536
|
+
rowSelection && rowSelection.showCheckbox !== false && /* @__PURE__ */ jsx("td", { className: getCheckboxCellClasses(size), children: /* @__PURE__ */ jsx(
|
|
537
|
+
"input",
|
|
538
|
+
{
|
|
539
|
+
type: rowSelection?.type === "radio" ? "radio" : "checkbox",
|
|
540
|
+
className: rowSelection?.type === "radio" ? "border-gray-300 text-[var(--tiger-primary,#2563eb)] focus:ring-[var(--tiger-primary,#2563eb)]" : "rounded border-gray-300 text-[var(--tiger-primary,#2563eb)] focus:ring-[var(--tiger-primary,#2563eb)]",
|
|
541
|
+
checked: isSelected,
|
|
542
|
+
disabled: rowSelection?.getCheckboxProps?.(record)?.disabled,
|
|
543
|
+
onChange: (e) => handleSelectRow(key, e.target.checked),
|
|
544
|
+
onClick: (e) => e.stopPropagation()
|
|
545
|
+
}
|
|
546
|
+
) }),
|
|
547
|
+
displayColumns.map((column) => {
|
|
548
|
+
const dataKey = column.dataKey || column.key;
|
|
549
|
+
const cellValue = record[dataKey];
|
|
550
|
+
const isFixedLeft = column.fixed === "left";
|
|
551
|
+
const isFixedRight = column.fixed === "right";
|
|
552
|
+
const fixedStyle = isFixedLeft ? {
|
|
553
|
+
position: "sticky",
|
|
554
|
+
left: `${fixedColumnsInfo.leftOffsets[column.key] || 0}px`,
|
|
555
|
+
zIndex: 10
|
|
556
|
+
} : isFixedRight ? {
|
|
557
|
+
position: "sticky",
|
|
558
|
+
right: `${fixedColumnsInfo.rightOffsets[column.key] || 0}px`,
|
|
559
|
+
zIndex: 10
|
|
560
|
+
} : void 0;
|
|
561
|
+
const widthStyle = column.width ? {
|
|
562
|
+
width: typeof column.width === "number" ? `${column.width}px` : column.width
|
|
563
|
+
} : void 0;
|
|
564
|
+
const style = fixedStyle ? { ...widthStyle, ...fixedStyle } : widthStyle;
|
|
565
|
+
const stickyBgClass = striped && index % 2 === 0 ? "bg-[var(--tiger-surface-muted,#f9fafb)]/50" : "bg-[var(--tiger-surface,#ffffff)]";
|
|
566
|
+
const stickyCellClass = isFixedLeft || isFixedRight ? classNames(
|
|
567
|
+
stickyBgClass,
|
|
568
|
+
hoverable && "group-hover:bg-[var(--tiger-surface-muted,#f9fafb)]"
|
|
569
|
+
) : void 0;
|
|
570
|
+
return /* @__PURE__ */ jsx(
|
|
571
|
+
"td",
|
|
572
|
+
{
|
|
573
|
+
className: classNames(
|
|
574
|
+
getTableCellClasses(size, column.align || "left", column.className),
|
|
575
|
+
stickyCellClass
|
|
576
|
+
),
|
|
577
|
+
style,
|
|
578
|
+
children: column.render ? column.render(record, index) : cellValue
|
|
579
|
+
},
|
|
580
|
+
column.key
|
|
581
|
+
);
|
|
582
|
+
}),
|
|
583
|
+
expandable && expandable.expandIconPosition === "end" && /* @__PURE__ */ jsx("td", { className: getExpandCellClasses(size), children: /* @__PURE__ */ jsx(
|
|
584
|
+
ExpandToggle,
|
|
585
|
+
{
|
|
586
|
+
rowKey: key,
|
|
587
|
+
expandableRow: isExpandableRow,
|
|
588
|
+
expanded: isExpanded
|
|
589
|
+
}
|
|
590
|
+
) })
|
|
591
|
+
]
|
|
592
|
+
}
|
|
593
|
+
),
|
|
594
|
+
expandable && isExpanded && isExpandableRow && /* @__PURE__ */ jsx("tr", { className: expandedRowContentClasses, children: /* @__PURE__ */ jsx("td", { colSpan: totalColumnCount, children: expandable.expandedRowRender(record, index) }) })
|
|
595
|
+
] }, key);
|
|
533
596
|
}) });
|
|
534
597
|
}, [
|
|
535
598
|
loading,
|
|
@@ -545,7 +608,11 @@ function Table({
|
|
|
545
608
|
size,
|
|
546
609
|
handleRowClick,
|
|
547
610
|
handleSelectRow,
|
|
548
|
-
fixedColumnsInfo
|
|
611
|
+
fixedColumnsInfo,
|
|
612
|
+
expandable,
|
|
613
|
+
expandedRowKeySet,
|
|
614
|
+
handleToggleExpand,
|
|
615
|
+
totalColumnCount
|
|
549
616
|
]);
|
|
550
617
|
const renderPagination = useCallback(() => {
|
|
551
618
|
if (pagination === false || !paginationInfo) {
|