@deepnoid/ui 0.1.78 → 0.1.80

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,535 @@
1
+ "use client";
2
+ import {
3
+ scrollArea_default
4
+ } from "./chunk-M37VBNB3.mjs";
5
+ import {
6
+ skeleton_default
7
+ } from "./chunk-6PN3DGOE.mjs";
8
+ import {
9
+ pagination_default
10
+ } from "./chunk-CC2F5HQX.mjs";
11
+ import {
12
+ checkbox_default
13
+ } from "./chunk-SKOCUCE5.mjs";
14
+ import {
15
+ clsx
16
+ } from "./chunk-27Y6K5NK.mjs";
17
+ import {
18
+ mapPropsVariants
19
+ } from "./chunk-E3G5QXSH.mjs";
20
+
21
+ // src/components/table/table.tsx
22
+ import {
23
+ forwardRef,
24
+ useEffect,
25
+ useImperativeHandle,
26
+ useMemo,
27
+ useState
28
+ } from "react";
29
+ import { tv } from "tailwind-variants";
30
+
31
+ // src/components/table/table-body.tsx
32
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
33
+ var TableBody = ({
34
+ slots,
35
+ rows,
36
+ columns,
37
+ size,
38
+ color,
39
+ rowCheckbox = false,
40
+ checkedRows,
41
+ onCheckRow,
42
+ isLoading = false,
43
+ emptyContent,
44
+ skeletonRow,
45
+ classNames,
46
+ className
47
+ }) => {
48
+ const renderTdSkeleton = (key, column) => {
49
+ const isCheckbox = key.includes("checkbox");
50
+ return /* @__PURE__ */ jsx(
51
+ "td",
52
+ {
53
+ className: slots.td({ class: classNames == null ? void 0 : classNames.td }),
54
+ style: isCheckbox ? {
55
+ width: "40px",
56
+ minWidth: "40px",
57
+ maxWidth: "40px",
58
+ flexShrink: 0,
59
+ flexGrow: 0,
60
+ boxSizing: "border-box"
61
+ } : column ? getCellStyle(column) : void 0,
62
+ children: /* @__PURE__ */ jsx(skeleton_default, { color, className: "h-full w-full", rounded: "lg", speed: "fast" })
63
+ },
64
+ key
65
+ );
66
+ };
67
+ const renderCheckboxCell = (rowId) => /* @__PURE__ */ jsx(
68
+ "td",
69
+ {
70
+ className: clsx(slots.td({ class: classNames == null ? void 0 : classNames.td }), "text-center"),
71
+ style: {
72
+ width: "40px",
73
+ minWidth: "40px",
74
+ maxWidth: "40px",
75
+ flexShrink: 0,
76
+ flexGrow: 0,
77
+ boxSizing: "border-box"
78
+ },
79
+ children: /* @__PURE__ */ jsx(checkbox_default, { size, checked: checkedRows.has(rowId), onChange: (e) => onCheckRow(rowId, e.target.checked) })
80
+ }
81
+ );
82
+ const renderSkeletonRow = (rowIndex) => /* @__PURE__ */ jsxs("tr", { className: slots.tr({ class: classNames == null ? void 0 : classNames.tr }), children: [
83
+ columns.map((column, colIdx) => renderTdSkeleton(`skeleton-${rowIndex}-${colIdx}`, column)),
84
+ rowCheckbox && renderTdSkeleton(`skeleton-checkbox-${rowIndex}`)
85
+ ] }, `skeleton-${rowIndex}`);
86
+ const renderEmptyRow = () => /* @__PURE__ */ jsx("tr", { className: slots.tr({ class: classNames == null ? void 0 : classNames.tr }), children: /* @__PURE__ */ jsx("td", { colSpan: columns.length + (rowCheckbox ? 1 : 0), className: slots.empty({ class: classNames == null ? void 0 : classNames.empty }), children: emptyContent }) });
87
+ const renderDataRow = (row, rowIndex) => /* @__PURE__ */ jsxs("tr", { className: slots.tr({ class: classNames == null ? void 0 : classNames.tr }), children: [
88
+ columns.map((column, colIdx) => {
89
+ var _a;
90
+ const value = row[column.field];
91
+ const formattedValue = ((_a = column.valueFormatter) == null ? void 0 : _a.call(column, { value, field: column.field })) || value;
92
+ const content = column.renderCell ? column.renderCell({ id: row.id, field: column.field, value, formattedValue, row }) : formattedValue;
93
+ return /* @__PURE__ */ jsx(
94
+ "td",
95
+ {
96
+ className: clsx(slots.td({ class: classNames == null ? void 0 : classNames.td }), column.className),
97
+ style: getCellStyle(column),
98
+ children: content
99
+ },
100
+ `${rowIndex}-${colIdx}`
101
+ );
102
+ }),
103
+ rowCheckbox && renderCheckboxCell(row.id)
104
+ ] }, rowIndex);
105
+ const renderRows = () => {
106
+ if (isLoading) return skeletonRow ? Array.from({ length: skeletonRow }, (_, idx) => renderSkeletonRow(idx)) : /* @__PURE__ */ jsx(Fragment, {});
107
+ if (!rows.length && emptyContent) return renderEmptyRow();
108
+ return rows.map((row, index) => renderDataRow(row, index));
109
+ };
110
+ return /* @__PURE__ */ jsx("tbody", { className: `${slots.tbody({ class: classNames == null ? void 0 : classNames.tbody })} ${className || ""}`, children: renderRows() });
111
+ };
112
+ var table_body_default = TableBody;
113
+
114
+ // src/components/table/table.tsx
115
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
116
+ var Table = forwardRef((originalProps, ref) => {
117
+ const [props, variantProps] = mapPropsVariants(originalProps, tableStyle.variantKeys);
118
+ const {
119
+ rows,
120
+ columns,
121
+ rowCheckbox = false,
122
+ totalData = 0,
123
+ pagination,
124
+ onPageChange,
125
+ emptyContent,
126
+ isLoading = false,
127
+ classNames,
128
+ color,
129
+ size,
130
+ skeletonRow,
131
+ onCheckedRowsChange
132
+ } = { ...props, ...variantProps };
133
+ const { page = 1, perPage = 15 } = pagination || {};
134
+ const showPagination = pagination && totalData > 0 && !isLoading;
135
+ const [checkedRows, setCheckedRows] = useState(/* @__PURE__ */ new Set());
136
+ const tableMinWidth = useMemo(() => {
137
+ const columnsWidth = columns.reduce((total, column) => {
138
+ if (column.width) return total + column.width;
139
+ if (column.minWidth) return total + column.minWidth;
140
+ return total + 100;
141
+ }, 0);
142
+ const checkboxWidth = rowCheckbox ? 40 : 0;
143
+ return columnsWidth + checkboxWidth;
144
+ }, [columns, rowCheckbox]);
145
+ useEffect(() => {
146
+ onCheckedRowsChange == null ? void 0 : onCheckedRowsChange(getCheckedRowData(checkedRows));
147
+ }, [checkedRows]);
148
+ useEffect(() => {
149
+ const currentRowIds = new Set(rows.map((row) => row.id));
150
+ const checkedRowIds = Array.from(checkedRows);
151
+ const hasValidCheckedRows = checkedRowIds.every((id) => currentRowIds.has(id));
152
+ if (!hasValidCheckedRows) {
153
+ setCheckedRows(/* @__PURE__ */ new Set());
154
+ }
155
+ }, [rows.map((row) => row.id).join(",")]);
156
+ useImperativeHandle(
157
+ ref,
158
+ () => ({
159
+ checkedRows,
160
+ setCheckedRows
161
+ }),
162
+ [checkedRows]
163
+ );
164
+ const handleAllRowCheck = (checked) => {
165
+ const updated = checked ? new Set(rows.map((row) => row.id)) : /* @__PURE__ */ new Set();
166
+ setCheckedRows(updated);
167
+ };
168
+ const handleRowCheck = (id, checked) => {
169
+ setCheckedRows((prev) => {
170
+ const updated = new Set(prev);
171
+ checked ? updated.add(id) : updated.delete(id);
172
+ return updated;
173
+ });
174
+ };
175
+ const getCheckedRowData = (checked) => rows.filter((row) => checked.has(row.id));
176
+ const slots = useMemo(() => tableStyle(variantProps), [variantProps]);
177
+ return /* @__PURE__ */ jsxs2("div", { "data-table": "base", className: slots.base({ class: classNames == null ? void 0 : classNames.base }), children: [
178
+ /* @__PURE__ */ jsx2(scrollArea_default, { direction: "x", size: size === "xl" ? "lg" : size, children: /* @__PURE__ */ jsxs2(
179
+ "table",
180
+ {
181
+ className: slots.table({ class: classNames == null ? void 0 : classNames.table }),
182
+ style: {
183
+ tableLayout: "fixed",
184
+ width: "100%",
185
+ minWidth: `${tableMinWidth}px`
186
+ },
187
+ children: [
188
+ /* @__PURE__ */ jsx2(
189
+ table_head_default,
190
+ {
191
+ columns,
192
+ size,
193
+ color,
194
+ rowCheckbox,
195
+ isCheckedAll: checkedRows.size === rows.length && rows.length > 0,
196
+ onCheckAll: handleAllRowCheck,
197
+ isLoading,
198
+ classNames,
199
+ slots
200
+ }
201
+ ),
202
+ /* @__PURE__ */ jsx2(
203
+ table_body_default,
204
+ {
205
+ slots,
206
+ rows,
207
+ columns,
208
+ size,
209
+ color,
210
+ rowCheckbox,
211
+ checkedRows,
212
+ onCheckRow: handleRowCheck,
213
+ emptyContent,
214
+ isLoading,
215
+ skeletonRow,
216
+ className: clsx(
217
+ "transition-all duration-150 ease-out",
218
+ isLoading ? "-translate-y-2 opacity-0" : "translate-y-0 opacity-100",
219
+ classNames
220
+ )
221
+ }
222
+ )
223
+ ]
224
+ }
225
+ ) }),
226
+ showPagination && /* @__PURE__ */ jsx2("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx2(
227
+ pagination_default,
228
+ {
229
+ color,
230
+ currentPage: page,
231
+ totalPage: Math.ceil(totalData / perPage),
232
+ groupSize: 10,
233
+ handleChangePage: (newPage) => onPageChange == null ? void 0 : onPageChange({ page: newPage, perPage })
234
+ }
235
+ ) })
236
+ ] });
237
+ });
238
+ Table.displayName = "Table";
239
+ var table_default = Table;
240
+ var tableStyle = tv({
241
+ slots: {
242
+ base: ["flex", "flex-col", "relative", "select-none", "gap-[20px]"],
243
+ table: ["w-full", "h-auto"],
244
+ thead: ["w-full"],
245
+ tbody: ["w-full"],
246
+ tr: ["group/tr", "outline-none", "w-full", "h-full"],
247
+ th: [
248
+ "text-body-foreground",
249
+ "font-bold",
250
+ "whitespace-nowrap",
251
+ "outline-none",
252
+ "align-middle",
253
+ "px-[10px]",
254
+ "[&>div]:flex",
255
+ "[&>div]:gap-[10px]"
256
+ ],
257
+ td: [
258
+ "relative",
259
+ "text-foreground",
260
+ "whitespace-normal",
261
+ "outline-none",
262
+ "[&>*]:z-1",
263
+ "[&>*]:relative",
264
+ "px-[10px]",
265
+ "gap-[10px]",
266
+ "transition duration-200",
267
+ "align-middle"
268
+ ],
269
+ empty: [
270
+ "relative",
271
+ "text-foreground",
272
+ "whitespace-normal",
273
+ "outline-none",
274
+ "[&>*]:z-1",
275
+ "[&>*]:relative",
276
+ "align-middle"
277
+ ]
278
+ },
279
+ variants: {
280
+ variant: {
281
+ solid: {
282
+ tbody: ["[&>tr]:border-b"]
283
+ },
284
+ outline: {
285
+ tbody: ["[&>td]:border"],
286
+ th: ["border"],
287
+ td: ["border"]
288
+ },
289
+ underline: {
290
+ tbody: ["[&>tr]:border-b"],
291
+ th: ["border-t-[2px]", "border-b"]
292
+ }
293
+ },
294
+ size: {
295
+ sm: {
296
+ tr: ["text-sm"]
297
+ },
298
+ md: {
299
+ tr: ["text-md"]
300
+ },
301
+ lg: {
302
+ tr: ["text-lg"]
303
+ },
304
+ xl: {
305
+ tr: ["text-xl"]
306
+ }
307
+ },
308
+ color: {
309
+ primary: {
310
+ tbody: ["[&>tr]:border-primary-light"]
311
+ },
312
+ secondary: {
313
+ tbody: ["[&>tr]:border-secondary-light"]
314
+ },
315
+ neutral: {
316
+ tbody: ["[&>tr]:border-neutral-light"]
317
+ }
318
+ },
319
+ height: {
320
+ narrow: {},
321
+ wide: {}
322
+ }
323
+ },
324
+ compoundVariants: [
325
+ {
326
+ variant: "solid",
327
+ color: "primary",
328
+ class: {
329
+ th: ["bg-primary-soft"]
330
+ }
331
+ },
332
+ {
333
+ variant: "solid",
334
+ color: "secondary",
335
+ class: {
336
+ th: ["bg-secondary-soft"]
337
+ }
338
+ },
339
+ {
340
+ variant: "solid",
341
+ color: "neutral",
342
+ class: {
343
+ th: ["bg-neutral-soft"]
344
+ }
345
+ },
346
+ {
347
+ variant: "outline",
348
+ color: "primary",
349
+ class: {
350
+ th: ["bg-primary-soft", "border-primary-light"],
351
+ td: ["border-primary-light"]
352
+ }
353
+ },
354
+ {
355
+ variant: "outline",
356
+ color: "secondary",
357
+ class: {
358
+ th: ["bg-secondary-soft", "border-secondary-light"],
359
+ td: ["border-secondary-light"]
360
+ }
361
+ },
362
+ {
363
+ variant: "outline",
364
+ color: "neutral",
365
+ class: {
366
+ th: ["bg-neutral-soft", "border-neutral-light"],
367
+ td: ["border-neutral-light"]
368
+ }
369
+ },
370
+ {
371
+ variant: "underline",
372
+ color: "primary",
373
+ class: {
374
+ th: ["bg-body-background", "border-t-[2px]", "border-b", "border-primary-main"]
375
+ }
376
+ },
377
+ {
378
+ variant: "underline",
379
+ color: "secondary",
380
+ class: {
381
+ th: ["bg-body-background", "border-t-[2px]", "border-b", "border-secondary-main"]
382
+ }
383
+ },
384
+ {
385
+ variant: "underline",
386
+ color: "neutral",
387
+ class: {
388
+ th: ["bg-body-background", "border-t-[2px]", "border-b", "border-neutral-main"]
389
+ }
390
+ },
391
+ {
392
+ height: "narrow",
393
+ size: "sm",
394
+ class: {
395
+ tr: ["h-[30px]"]
396
+ }
397
+ },
398
+ {
399
+ height: "narrow",
400
+ size: "md",
401
+ class: {
402
+ tr: ["h-[40px]"]
403
+ }
404
+ },
405
+ {
406
+ height: "narrow",
407
+ size: "lg",
408
+ class: {
409
+ tr: ["h-[50px]"]
410
+ }
411
+ },
412
+ {
413
+ height: "narrow",
414
+ size: "xl",
415
+ class: {
416
+ tr: ["h-[60px]"]
417
+ }
418
+ },
419
+ {
420
+ height: "wide",
421
+ size: "sm",
422
+ class: {
423
+ tr: ["h-[40px]"]
424
+ }
425
+ },
426
+ {
427
+ height: "wide",
428
+ size: "md",
429
+ class: {
430
+ tr: ["h-[50px]"]
431
+ }
432
+ },
433
+ {
434
+ height: "wide",
435
+ size: "lg",
436
+ class: {
437
+ tr: ["h-[60px]"]
438
+ }
439
+ },
440
+ {
441
+ height: "wide",
442
+ size: "xl",
443
+ class: {
444
+ tr: ["h-[70px]"]
445
+ }
446
+ }
447
+ ],
448
+ defaultVariants: {
449
+ variant: "solid",
450
+ size: "md",
451
+ color: "primary",
452
+ height: "narrow"
453
+ }
454
+ });
455
+ var getCellStyle = (column) => {
456
+ const hasFixedWidth = column.width;
457
+ const hasMinWidth = column.minWidth;
458
+ return {
459
+ width: hasFixedWidth ? `${column.width}px` : "auto",
460
+ minWidth: hasMinWidth ? `${column.minWidth}px` : hasFixedWidth ? `${column.width}px` : void 0,
461
+ maxWidth: column.maxWidth ? `${column.maxWidth}px` : void 0,
462
+ height: column.height ? `${column.height}px` : void 0,
463
+ textAlign: column.align || "center",
464
+ boxSizing: "border-box",
465
+ overflow: "hidden",
466
+ textOverflow: "ellipsis",
467
+ whiteSpace: "nowrap"
468
+ };
469
+ };
470
+
471
+ // src/components/table/table-head.tsx
472
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
473
+ var TableHead = ({
474
+ slots,
475
+ columns,
476
+ color,
477
+ size,
478
+ rowCheckbox = false,
479
+ isCheckedAll,
480
+ isLoading = false,
481
+ classNames,
482
+ onCheckAll
483
+ }) => {
484
+ const handleClickCheckAll = (e) => {
485
+ e.preventDefault();
486
+ onCheckAll(!isCheckedAll);
487
+ };
488
+ const renderTh = (content, key, column, isCheckbox) => /* @__PURE__ */ jsx3(
489
+ "th",
490
+ {
491
+ className: clsx(slots.th({ class: classNames == null ? void 0 : classNames.th }), column == null ? void 0 : column.className),
492
+ style: isCheckbox ? {
493
+ width: "40px",
494
+ minWidth: "40px",
495
+ maxWidth: "40px",
496
+ flexShrink: 0,
497
+ flexGrow: 0,
498
+ boxSizing: "border-box"
499
+ } : column ? getCellStyle(column) : void 0,
500
+ children: content
501
+ },
502
+ key
503
+ );
504
+ const renderSkeletonRow = () => /* @__PURE__ */ jsx3("thead", { className: slots.thead({ class: classNames == null ? void 0 : classNames.thead }), children: /* @__PURE__ */ jsxs3("tr", { className: clsx(slots.tr({ class: classNames == null ? void 0 : classNames.tr }), "[&>th]:border-0"), children: [
505
+ columns.map(
506
+ (column, idx) => renderTh(/* @__PURE__ */ jsx3(skeleton_default, { color, rounded: "lg", speed: "fast" }), `skeleton-${idx}`, column)
507
+ ),
508
+ rowCheckbox && renderTh(/* @__PURE__ */ jsx3(skeleton_default, { color, rounded: "lg", speed: "fast" }), "checkbox-skeleton", void 0, true)
509
+ ] }) });
510
+ const renderContentRow = () => /* @__PURE__ */ jsx3("thead", { className: slots.thead({ class: classNames == null ? void 0 : classNames.thead }), children: /* @__PURE__ */ jsxs3("tr", { className: slots.tr({ class: classNames == null ? void 0 : classNames.tr }), children: [
511
+ columns.map((column, idx) => renderTh(column.headerName, `${column.field}-${idx}`, column)),
512
+ rowCheckbox && renderTh(
513
+ /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-center", onClick: handleClickCheckAll, children: /* @__PURE__ */ jsx3(
514
+ checkbox_default,
515
+ {
516
+ size,
517
+ checked: isCheckedAll,
518
+ onChange: (e) => onCheckAll(e.target.checked)
519
+ }
520
+ ) }),
521
+ "checkbox",
522
+ void 0,
523
+ true
524
+ )
525
+ ] }) });
526
+ return isLoading ? renderSkeletonRow() : renderContentRow();
527
+ };
528
+ var table_head_default = TableHead;
529
+
530
+ export {
531
+ table_head_default,
532
+ table_body_default,
533
+ table_default,
534
+ getCellStyle
535
+ };
@@ -2,11 +2,11 @@
2
2
  import {
3
3
  dateTimePickerStyle,
4
4
  dateTimePicker_default
5
- } from "../../chunk-YF2N2OBY.mjs";
6
- import "../../chunk-WYHCK7XL.mjs";
5
+ } from "../../chunk-L65ETSUY.mjs";
6
+ import "../../chunk-ZYS4NSXT.mjs";
7
7
  import "../../chunk-7MVEAQ7Z.mjs";
8
- import "../../chunk-B6XJNGQL.mjs";
9
8
  import "../../chunk-QFIS6N5R.mjs";
9
+ import "../../chunk-B6XJNGQL.mjs";
10
10
  import "../../chunk-FWJ2ZKH6.mjs";
11
11
  import "../../chunk-TUXYVNTY.mjs";
12
12
  import "../../chunk-P732YGHO.mjs";
@@ -2,11 +2,11 @@
2
2
  import "../../chunk-75HLCORR.mjs";
3
3
  import {
4
4
  dateTimePicker_default
5
- } from "../../chunk-YF2N2OBY.mjs";
6
- import "../../chunk-WYHCK7XL.mjs";
5
+ } from "../../chunk-L65ETSUY.mjs";
6
+ import "../../chunk-ZYS4NSXT.mjs";
7
7
  import "../../chunk-7MVEAQ7Z.mjs";
8
- import "../../chunk-B6XJNGQL.mjs";
9
8
  import "../../chunk-QFIS6N5R.mjs";
9
+ import "../../chunk-B6XJNGQL.mjs";
10
10
  import "../../chunk-FWJ2ZKH6.mjs";
11
11
  import "../../chunk-TUXYVNTY.mjs";
12
12
  import "../../chunk-P732YGHO.mjs";
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  timePicker_default
4
- } from "../../chunk-WYHCK7XL.mjs";
4
+ } from "../../chunk-ZYS4NSXT.mjs";
5
5
  import "../../chunk-7MVEAQ7Z.mjs";
6
- import "../../chunk-B6XJNGQL.mjs";
7
6
  import "../../chunk-QFIS6N5R.mjs";
7
+ import "../../chunk-B6XJNGQL.mjs";
8
8
  import "../../chunk-FUPY7MXT.mjs";
9
9
  import "../../chunk-ZYIIXWVY.mjs";
10
10
  import "../../chunk-JP4TEWP7.mjs";
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import "../../chunk-7MVEAQ7Z.mjs";
3
- import {
4
- list_default
5
- } from "../../chunk-B6XJNGQL.mjs";
6
3
  import {
7
4
  listItem_default
8
5
  } from "../../chunk-QFIS6N5R.mjs";
6
+ import {
7
+ list_default
8
+ } from "../../chunk-B6XJNGQL.mjs";
9
9
  import "../../chunk-FUPY7MXT.mjs";
10
10
  import "../../chunk-ZYIIXWVY.mjs";
11
11
  import "../../chunk-JP4TEWP7.mjs";