@deepnoid/ui 0.1.79 → 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.
@@ -1,16 +1,16 @@
1
1
  "use client";
2
- import {
3
- table_body_default
4
- } from "./chunk-SIVCIIB6.mjs";
5
- import {
6
- table_head_default
7
- } from "./chunk-D5N7OBSO.mjs";
8
2
  import {
9
3
  scrollArea_default
10
4
  } from "./chunk-M37VBNB3.mjs";
5
+ import {
6
+ skeleton_default
7
+ } from "./chunk-6PN3DGOE.mjs";
11
8
  import {
12
9
  pagination_default
13
10
  } from "./chunk-CC2F5HQX.mjs";
11
+ import {
12
+ checkbox_default
13
+ } from "./chunk-SKOCUCE5.mjs";
14
14
  import {
15
15
  clsx
16
16
  } from "./chunk-27Y6K5NK.mjs";
@@ -27,7 +27,92 @@ import {
27
27
  useState
28
28
  } from "react";
29
29
  import { tv } from "tailwind-variants";
30
- import { jsx, jsxs } from "react/jsx-runtime";
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";
31
116
  var Table = forwardRef((originalProps, ref) => {
32
117
  const [props, variantProps] = mapPropsVariants(originalProps, tableStyle.variantKeys);
33
118
  const {
@@ -48,6 +133,15 @@ var Table = forwardRef((originalProps, ref) => {
48
133
  const { page = 1, perPage = 15 } = pagination || {};
49
134
  const showPagination = pagination && totalData > 0 && !isLoading;
50
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]);
51
145
  useEffect(() => {
52
146
  onCheckedRowsChange == null ? void 0 : onCheckedRowsChange(getCheckedRowData(checkedRows));
53
147
  }, [checkedRows]);
@@ -80,17 +174,18 @@ var Table = forwardRef((originalProps, ref) => {
80
174
  };
81
175
  const getCheckedRowData = (checked) => rows.filter((row) => checked.has(row.id));
82
176
  const slots = useMemo(() => tableStyle(variantProps), [variantProps]);
83
- return /* @__PURE__ */ jsxs("div", { "data-table": "base", className: slots.base({ class: classNames == null ? void 0 : classNames.base }), children: [
84
- /* @__PURE__ */ jsx(scrollArea_default, { direction: "x", size: size === "xl" ? "lg" : size, children: /* @__PURE__ */ jsxs(
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(
85
179
  "table",
86
180
  {
87
181
  className: slots.table({ class: classNames == null ? void 0 : classNames.table }),
88
182
  style: {
89
183
  tableLayout: "fixed",
90
- width: "100%"
184
+ width: "100%",
185
+ minWidth: `${tableMinWidth}px`
91
186
  },
92
187
  children: [
93
- /* @__PURE__ */ jsx(
188
+ /* @__PURE__ */ jsx2(
94
189
  table_head_default,
95
190
  {
96
191
  columns,
@@ -104,7 +199,7 @@ var Table = forwardRef((originalProps, ref) => {
104
199
  slots
105
200
  }
106
201
  ),
107
- /* @__PURE__ */ jsx(
202
+ /* @__PURE__ */ jsx2(
108
203
  table_body_default,
109
204
  {
110
205
  slots,
@@ -128,7 +223,7 @@ var Table = forwardRef((originalProps, ref) => {
128
223
  ]
129
224
  }
130
225
  ) }),
131
- showPagination && /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
226
+ showPagination && /* @__PURE__ */ jsx2("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx2(
132
227
  pagination_default,
133
228
  {
134
229
  color,
@@ -357,7 +452,84 @@ var tableStyle = tv({
357
452
  height: "narrow"
358
453
  }
359
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;
360
529
 
361
530
  export {
362
- table_default
531
+ table_head_default,
532
+ table_body_default,
533
+ table_default,
534
+ getCellStyle
363
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";
@@ -695,17 +695,14 @@ var TableHead = ({
695
695
  "th",
696
696
  {
697
697
  className: clsx(slots.th({ class: classNames == null ? void 0 : classNames.th }), column == null ? void 0 : column.className),
698
- style: {
699
- width: isCheckbox ? "40px" : (column == null ? void 0 : column.width) ? `${column.width}px` : "auto",
700
- minWidth: isCheckbox ? "40px" : (column == null ? void 0 : column.minWidth) ? `${column.minWidth}px` : void 0,
701
- maxWidth: isCheckbox ? "40px" : (column == null ? void 0 : column.maxWidth) ? `${column.maxWidth}px` : void 0,
702
- height: (column == null ? void 0 : column.height) ? `${column.height}px` : void 0,
703
- ...isCheckbox || (column == null ? void 0 : column.width) ? {
704
- flexShrink: 0,
705
- flexGrow: 0,
706
- boxSizing: "border-box"
707
- } : {}
708
- },
698
+ style: isCheckbox ? {
699
+ width: "40px",
700
+ minWidth: "40px",
701
+ maxWidth: "40px",
702
+ flexShrink: 0,
703
+ flexGrow: 0,
704
+ boxSizing: "border-box"
705
+ } : column ? getCellStyle(column) : void 0,
709
706
  children: content
710
707
  },
711
708
  key
@@ -753,21 +750,6 @@ var TableBody = ({
753
750
  classNames,
754
751
  className
755
752
  }) => {
756
- const getCellStyle = (column) => ({
757
- width: column.width ? `${column.width}px` : "auto",
758
- minWidth: column.minWidth ? `${column.minWidth}px` : void 0,
759
- maxWidth: column.maxWidth ? `${column.maxWidth}px` : void 0,
760
- height: column.height ? `${column.height}px` : void 0,
761
- textAlign: column.align || "center",
762
- ...column.width && {
763
- flexShrink: 0,
764
- flexGrow: 0,
765
- boxSizing: "border-box",
766
- overflow: "hidden",
767
- textOverflow: "ellipsis",
768
- whiteSpace: "nowrap"
769
- }
770
- });
771
753
  const renderTdSkeleton = (key, column) => {
772
754
  const isCheckbox = key.includes("checkbox");
773
755
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -6181,6 +6163,15 @@ var Table = (0, import_react5.forwardRef)((originalProps, ref) => {
6181
6163
  const { page = 1, perPage = 15 } = pagination || {};
6182
6164
  const showPagination = pagination && totalData > 0 && !isLoading;
6183
6165
  const [checkedRows, setCheckedRows] = (0, import_react5.useState)(/* @__PURE__ */ new Set());
6166
+ const tableMinWidth = (0, import_react5.useMemo)(() => {
6167
+ const columnsWidth = columns.reduce((total, column) => {
6168
+ if (column.width) return total + column.width;
6169
+ if (column.minWidth) return total + column.minWidth;
6170
+ return total + 100;
6171
+ }, 0);
6172
+ const checkboxWidth = rowCheckbox ? 40 : 0;
6173
+ return columnsWidth + checkboxWidth;
6174
+ }, [columns, rowCheckbox]);
6184
6175
  (0, import_react5.useEffect)(() => {
6185
6176
  onCheckedRowsChange == null ? void 0 : onCheckedRowsChange(getCheckedRowData(checkedRows));
6186
6177
  }, [checkedRows]);
@@ -6220,7 +6211,8 @@ var Table = (0, import_react5.forwardRef)((originalProps, ref) => {
6220
6211
  className: slots.table({ class: classNames == null ? void 0 : classNames.table }),
6221
6212
  style: {
6222
6213
  tableLayout: "fixed",
6223
- width: "100%"
6214
+ width: "100%",
6215
+ minWidth: `${tableMinWidth}px`
6224
6216
  },
6225
6217
  children: [
6226
6218
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
@@ -6490,6 +6482,21 @@ var tableStyle = (0, import_tailwind_variants7.tv)({
6490
6482
  height: "narrow"
6491
6483
  }
6492
6484
  });
6485
+ var getCellStyle = (column) => {
6486
+ const hasFixedWidth = column.width;
6487
+ const hasMinWidth = column.minWidth;
6488
+ return {
6489
+ width: hasFixedWidth ? `${column.width}px` : "auto",
6490
+ minWidth: hasMinWidth ? `${column.minWidth}px` : hasFixedWidth ? `${column.width}px` : void 0,
6491
+ maxWidth: column.maxWidth ? `${column.maxWidth}px` : void 0,
6492
+ height: column.height ? `${column.height}px` : void 0,
6493
+ textAlign: column.align || "center",
6494
+ boxSizing: "border-box",
6495
+ overflow: "hidden",
6496
+ textOverflow: "ellipsis",
6497
+ whiteSpace: "nowrap"
6498
+ };
6499
+ };
6493
6500
 
6494
6501
  // src/components/table/definition-table.tsx
6495
6502
  var import_react6 = require("react");
@@ -5,9 +5,7 @@ import {
5
5
  } from "../../chunk-KCAGZUYM.mjs";
6
6
  import {
7
7
  table_default
8
- } from "../../chunk-AX3D6VFT.mjs";
9
- import "../../chunk-SIVCIIB6.mjs";
10
- import "../../chunk-D5N7OBSO.mjs";
8
+ } from "../../chunk-UWXCAR5C.mjs";
11
9
  import "../../chunk-DQRAFUDA.mjs";
12
10
  import "../../chunk-M37VBNB3.mjs";
13
11
  import "../../chunk-MZ76AA76.mjs";