@yuno-payments/dashboard-design-system 0.0.128 → 0.0.130
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/components/organisms/data-table/data-table.d.ts +19 -1
- package/dist/components/organisms/data-table/data-table.js +98 -88
- package/dist/components/organisms/data-table/data-table.types.d.ts +19 -0
- package/dist/components/organisms/data-table/hooks/use-data-table-state.d.ts +7 -2
- package/dist/components/organisms/data-table/hooks/use-data-table-state.js +80 -46
- package/package.json +1 -1
|
@@ -41,6 +41,15 @@ export interface DataTableProps<TData, TValue> {
|
|
|
41
41
|
* @default false
|
|
42
42
|
*/
|
|
43
43
|
manualSorting?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Controlled sorting state (optional)
|
|
46
|
+
* If provided, component operates in controlled mode
|
|
47
|
+
*/
|
|
48
|
+
sorting?: import('@tanstack/react-table').SortingState;
|
|
49
|
+
/**
|
|
50
|
+
* Callback when sorting changes (required for controlled mode)
|
|
51
|
+
*/
|
|
52
|
+
onSortingChange?: (sorting: import('@tanstack/react-table').SortingState) => void;
|
|
44
53
|
/**
|
|
45
54
|
* Whether to enable column filtering
|
|
46
55
|
* @default false
|
|
@@ -81,6 +90,15 @@ export interface DataTableProps<TData, TValue> {
|
|
|
81
90
|
* Unique key for persisting table state in localStorage
|
|
82
91
|
*/
|
|
83
92
|
persistKey?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Initial settings to load (from backend/profile)
|
|
95
|
+
* Takes precedence over localStorage
|
|
96
|
+
*/
|
|
97
|
+
initialSettings?: import('./data-table.types').DataTableSettings;
|
|
98
|
+
/**
|
|
99
|
+
* Callback when table settings change (for syncing to backend)
|
|
100
|
+
*/
|
|
101
|
+
onUpdate?: (settings: import('./data-table.types').DataTableSettings) => void;
|
|
84
102
|
}
|
|
85
103
|
/**
|
|
86
104
|
* Advanced data table component built on TanStack Table.
|
|
@@ -103,4 +121,4 @@ export interface DataTableProps<TData, TValue> {
|
|
|
103
121
|
* />
|
|
104
122
|
* ```
|
|
105
123
|
*/
|
|
106
|
-
export declare function DataTable<TData, TValue>({ columns, data, isLoading, empty, checkboxSelection, onRowSelectionChange, enableSorting, manualSorting, enableColumnFilters, enableColumnResizing, columnResizeMode, onRowClick, actions, height, rowHeight, className, persistKey, }: DataTableProps<TData, TValue>): import("react/jsx-runtime").JSX.Element;
|
|
124
|
+
export declare function DataTable<TData, TValue>({ columns, data, isLoading, empty, checkboxSelection, onRowSelectionChange, enableSorting, manualSorting, sorting: externalSorting, onSortingChange: externalOnSortingChange, enableColumnFilters, enableColumnResizing, columnResizeMode, onRowClick, actions, height, rowHeight, className, persistKey, initialSettings, onUpdate, }: DataTableProps<TData, TValue>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,140 +1,150 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import * as
|
|
3
|
-
import { useReactTable as
|
|
4
|
-
import { Table as
|
|
1
|
+
import { j as o } from "../../../_virtual/jsx-runtime.js";
|
|
2
|
+
import * as I from "react";
|
|
3
|
+
import { useReactTable as U } from "../../../node_modules/@tanstack/react-table/build/lib/index.js";
|
|
4
|
+
import { Table as V } from "../../../vendor/shadcn/table.js";
|
|
5
5
|
import { cn as u } from "../../../lib/utils.js";
|
|
6
|
-
import { DataTableLoading as
|
|
7
|
-
import { DataTableHeader as
|
|
8
|
-
import { DataTableBody as
|
|
9
|
-
import { useDataTableColumns as
|
|
10
|
-
import { useDataTableState as
|
|
11
|
-
import { ROW_HEIGHT_DEFAULT as
|
|
12
|
-
import { getFilteredRowModel as
|
|
13
|
-
import { Empty as
|
|
14
|
-
function
|
|
6
|
+
import { DataTableLoading as q } from "./components/states/data-table-loading.js";
|
|
7
|
+
import { DataTableHeader as J } from "./components/data-table-header.js";
|
|
8
|
+
import { DataTableBody as K } from "./components/data-table-body.js";
|
|
9
|
+
import { useDataTableColumns as Q } from "./hooks/use-data-table-columns.js";
|
|
10
|
+
import { useDataTableState as X } from "./hooks/use-data-table-state.js";
|
|
11
|
+
import { ROW_HEIGHT_DEFAULT as Y } from "./utils/data-table-constants.js";
|
|
12
|
+
import { getFilteredRowModel as Z, getSortedRowModel as $, getCoreRowModel as k } from "../../../node_modules/@tanstack/table-core/build/lib/index.js";
|
|
13
|
+
import { Empty as z } from "../../molecules/empty/empty.js";
|
|
14
|
+
function fe({
|
|
15
15
|
columns: a,
|
|
16
16
|
data: s,
|
|
17
|
-
isLoading:
|
|
18
|
-
empty:
|
|
17
|
+
isLoading: p = !1,
|
|
18
|
+
empty: C,
|
|
19
19
|
checkboxSelection: m = !1,
|
|
20
|
-
onRowSelectionChange:
|
|
21
|
-
enableSorting:
|
|
22
|
-
manualSorting:
|
|
23
|
-
|
|
20
|
+
onRowSelectionChange: n,
|
|
21
|
+
enableSorting: b = !0,
|
|
22
|
+
manualSorting: h = !1,
|
|
23
|
+
sorting: x,
|
|
24
|
+
onSortingChange: w,
|
|
25
|
+
enableColumnFilters: y = !1,
|
|
24
26
|
enableColumnResizing: i = !0,
|
|
25
|
-
columnResizeMode:
|
|
26
|
-
onRowClick:
|
|
27
|
-
actions:
|
|
28
|
-
height:
|
|
29
|
-
rowHeight: d =
|
|
30
|
-
className:
|
|
31
|
-
persistKey:
|
|
27
|
+
columnResizeMode: S = "onChange",
|
|
28
|
+
onRowClick: T,
|
|
29
|
+
actions: r,
|
|
30
|
+
height: j,
|
|
31
|
+
rowHeight: d = Y,
|
|
32
|
+
className: R,
|
|
33
|
+
persistKey: D,
|
|
34
|
+
initialSettings: F,
|
|
35
|
+
onUpdate: M
|
|
32
36
|
}) {
|
|
33
|
-
const
|
|
37
|
+
const E = Q({
|
|
34
38
|
columns: a,
|
|
35
39
|
checkboxSelection: m,
|
|
36
|
-
actions:
|
|
40
|
+
actions: r
|
|
37
41
|
}), {
|
|
38
|
-
sorting:
|
|
39
|
-
setSorting:
|
|
40
|
-
columnFilters:
|
|
41
|
-
setColumnFilters:
|
|
42
|
-
columnVisibility:
|
|
43
|
-
setColumnVisibility:
|
|
44
|
-
rowSelection:
|
|
45
|
-
setRowSelection:
|
|
46
|
-
columnPinning:
|
|
47
|
-
handleColumnPinningChange:
|
|
48
|
-
} =
|
|
49
|
-
persistKey:
|
|
50
|
-
hasActions: !!
|
|
51
|
-
|
|
42
|
+
sorting: f,
|
|
43
|
+
setSorting: g,
|
|
44
|
+
columnFilters: N,
|
|
45
|
+
setColumnFilters: v,
|
|
46
|
+
columnVisibility: P,
|
|
47
|
+
setColumnVisibility: A,
|
|
48
|
+
rowSelection: c,
|
|
49
|
+
setRowSelection: H,
|
|
50
|
+
columnPinning: L,
|
|
51
|
+
handleColumnPinningChange: W
|
|
52
|
+
} = X({
|
|
53
|
+
persistKey: D,
|
|
54
|
+
hasActions: !!r,
|
|
55
|
+
externalSorting: x,
|
|
56
|
+
onExternalSortingChange: w,
|
|
57
|
+
initialSettings: F,
|
|
58
|
+
onUpdate: M
|
|
59
|
+
}), t = U({
|
|
52
60
|
data: s,
|
|
53
|
-
columns:
|
|
54
|
-
getCoreRowModel:
|
|
61
|
+
columns: E,
|
|
62
|
+
getCoreRowModel: k(),
|
|
55
63
|
enableColumnResizing: i,
|
|
56
|
-
columnResizeMode:
|
|
64
|
+
columnResizeMode: S,
|
|
57
65
|
enableColumnPinning: !0,
|
|
58
66
|
defaultColumn: {
|
|
59
67
|
enableSorting: !1,
|
|
60
68
|
minSize: 50
|
|
61
69
|
},
|
|
62
|
-
...p && {
|
|
63
|
-
onSortingChange: S,
|
|
64
|
-
getSortedRowModel: K(),
|
|
65
|
-
manualSorting: C
|
|
66
|
-
},
|
|
67
70
|
...b && {
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
onSortingChange: (e) => {
|
|
72
|
+
g(typeof e == "function" ? e(f) : e);
|
|
73
|
+
},
|
|
74
|
+
getSortedRowModel: $(),
|
|
75
|
+
manualSorting: h
|
|
76
|
+
},
|
|
77
|
+
...y && {
|
|
78
|
+
onColumnFiltersChange: v,
|
|
79
|
+
getFilteredRowModel: Z()
|
|
70
80
|
},
|
|
71
|
-
onColumnVisibilityChange:
|
|
72
|
-
onRowSelectionChange:
|
|
73
|
-
onColumnPinningChange:
|
|
81
|
+
onColumnVisibilityChange: A,
|
|
82
|
+
onRowSelectionChange: H,
|
|
83
|
+
onColumnPinningChange: W,
|
|
74
84
|
state: {
|
|
75
|
-
sorting:
|
|
76
|
-
columnFilters:
|
|
77
|
-
columnVisibility:
|
|
78
|
-
rowSelection:
|
|
79
|
-
columnPinning:
|
|
85
|
+
sorting: f,
|
|
86
|
+
columnFilters: N,
|
|
87
|
+
columnVisibility: P,
|
|
88
|
+
rowSelection: c,
|
|
89
|
+
columnPinning: L
|
|
80
90
|
}
|
|
81
91
|
});
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
|
|
92
|
+
if (I.useEffect(() => {
|
|
93
|
+
if (n) {
|
|
94
|
+
const e = t.getFilteredSelectedRowModel().rows.map((l) => l.original);
|
|
95
|
+
n(e);
|
|
86
96
|
}
|
|
87
|
-
}, [
|
|
88
|
-
return /* @__PURE__ */
|
|
89
|
-
|
|
97
|
+
}, [c, n, t]), p)
|
|
98
|
+
return /* @__PURE__ */ o.jsx(
|
|
99
|
+
q,
|
|
90
100
|
{
|
|
91
101
|
columns: a,
|
|
92
102
|
checkboxSelection: m,
|
|
93
|
-
actions:
|
|
103
|
+
actions: r,
|
|
94
104
|
rowHeight: d
|
|
95
105
|
}
|
|
96
106
|
);
|
|
97
107
|
if (s.length === 0) {
|
|
98
|
-
const
|
|
108
|
+
const e = C || {}, {
|
|
99
109
|
title: l = "No results",
|
|
100
|
-
description:
|
|
101
|
-
media:
|
|
102
|
-
actions:
|
|
103
|
-
} =
|
|
104
|
-
return /* @__PURE__ */
|
|
105
|
-
|
|
110
|
+
description: _ = "No data available",
|
|
111
|
+
media: B,
|
|
112
|
+
actions: G
|
|
113
|
+
} = e;
|
|
114
|
+
return /* @__PURE__ */ o.jsx(
|
|
115
|
+
z,
|
|
106
116
|
{
|
|
107
|
-
media:
|
|
117
|
+
media: B,
|
|
108
118
|
title: l,
|
|
109
|
-
description:
|
|
110
|
-
actions:
|
|
119
|
+
description: _,
|
|
120
|
+
actions: G
|
|
111
121
|
}
|
|
112
122
|
);
|
|
113
123
|
}
|
|
114
|
-
return /* @__PURE__ */
|
|
124
|
+
return /* @__PURE__ */ o.jsx("div", { className: u("space-y-4", R), children: /* @__PURE__ */ o.jsx(
|
|
115
125
|
"div",
|
|
116
126
|
{
|
|
117
127
|
className: "rounded-md border overflow-x-auto",
|
|
118
|
-
style: { height:
|
|
119
|
-
children: /* @__PURE__ */
|
|
120
|
-
|
|
128
|
+
style: { height: j || "auto" },
|
|
129
|
+
children: /* @__PURE__ */ o.jsxs(
|
|
130
|
+
V,
|
|
121
131
|
{
|
|
122
132
|
className: u("table-fixed"),
|
|
123
133
|
style: { width: "max-content", minWidth: "100%" },
|
|
124
134
|
children: [
|
|
125
|
-
/* @__PURE__ */
|
|
126
|
-
|
|
135
|
+
/* @__PURE__ */ o.jsx(
|
|
136
|
+
J,
|
|
127
137
|
{
|
|
128
138
|
table: t,
|
|
129
139
|
enableColumnResizing: i
|
|
130
140
|
}
|
|
131
141
|
),
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
-
|
|
142
|
+
/* @__PURE__ */ o.jsx(
|
|
143
|
+
K,
|
|
134
144
|
{
|
|
135
145
|
table: t,
|
|
136
146
|
enableColumnResizing: i,
|
|
137
|
-
onRowClick:
|
|
147
|
+
onRowClick: T,
|
|
138
148
|
rowHeight: d
|
|
139
149
|
}
|
|
140
150
|
)
|
|
@@ -145,5 +155,5 @@ function ae({
|
|
|
145
155
|
) });
|
|
146
156
|
}
|
|
147
157
|
export {
|
|
148
|
-
|
|
158
|
+
fe as DataTable
|
|
149
159
|
};
|
|
@@ -77,6 +77,23 @@ export type DataTableColumn<TData> = ColumnDef<TData> & {
|
|
|
77
77
|
enableSorting?: boolean;
|
|
78
78
|
enableHiding?: boolean;
|
|
79
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Settings structure compatible with TableV2 format
|
|
82
|
+
* Used for initialSettings and onUpdate callback
|
|
83
|
+
*/
|
|
84
|
+
export interface DataTableSettings {
|
|
85
|
+
hide?: string[];
|
|
86
|
+
show?: string[];
|
|
87
|
+
width?: {
|
|
88
|
+
[key: string]: number;
|
|
89
|
+
};
|
|
90
|
+
pinnedColumns?: {
|
|
91
|
+
right: string[];
|
|
92
|
+
left: string[];
|
|
93
|
+
};
|
|
94
|
+
order?: string[];
|
|
95
|
+
sorting?: SortingState;
|
|
96
|
+
}
|
|
80
97
|
export interface DataTableProps<TData> {
|
|
81
98
|
columns: DataTableColumn<TData>[];
|
|
82
99
|
data: TData[];
|
|
@@ -103,6 +120,8 @@ export interface DataTableProps<TData> {
|
|
|
103
120
|
height?: string | number;
|
|
104
121
|
rowHeight?: number;
|
|
105
122
|
persistKey?: string;
|
|
123
|
+
initialSettings?: DataTableSettings;
|
|
124
|
+
onUpdate?: (settings: DataTableSettings) => void;
|
|
106
125
|
renderToolbar?: () => React.ReactNode;
|
|
107
126
|
renderActions?: () => React.ReactNode;
|
|
108
127
|
className?: string;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { ColumnFiltersState, SortingState, VisibilityState, RowSelectionState, ColumnPinningState } from '@tanstack/react-table';
|
|
2
|
+
import { DataTableSettings } from '../data-table.types';
|
|
2
3
|
import * as React from "react";
|
|
3
4
|
interface UseDataTableStateProps {
|
|
4
5
|
persistKey?: string;
|
|
5
6
|
hasActions?: boolean;
|
|
7
|
+
externalSorting?: SortingState;
|
|
8
|
+
onExternalSortingChange?: (sorting: SortingState) => void;
|
|
9
|
+
initialSettings?: DataTableSettings;
|
|
10
|
+
onUpdate?: (settings: DataTableSettings) => void;
|
|
6
11
|
}
|
|
7
|
-
export declare function useDataTableState({ persistKey, hasActions, }: UseDataTableStateProps): {
|
|
12
|
+
export declare function useDataTableState({ persistKey, hasActions, externalSorting, onExternalSortingChange, initialSettings, onUpdate, }: UseDataTableStateProps): {
|
|
8
13
|
sorting: SortingState;
|
|
9
|
-
setSorting:
|
|
14
|
+
setSorting: (sorting: SortingState) => void;
|
|
10
15
|
columnFilters: ColumnFiltersState;
|
|
11
16
|
setColumnFilters: React.Dispatch<React.SetStateAction<ColumnFiltersState>>;
|
|
12
17
|
columnVisibility: VisibilityState;
|
|
@@ -1,74 +1,108 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
function
|
|
3
|
-
persistKey:
|
|
4
|
-
hasActions:
|
|
1
|
+
import * as i from "react";
|
|
2
|
+
function N({
|
|
3
|
+
persistKey: l,
|
|
4
|
+
hasActions: s = !1,
|
|
5
|
+
externalSorting: P,
|
|
6
|
+
onExternalSortingChange: r,
|
|
7
|
+
initialSettings: n,
|
|
8
|
+
onUpdate: m
|
|
5
9
|
}) {
|
|
6
|
-
const [
|
|
10
|
+
const [c, a] = i.useState([]), [y, w] = i.useState(
|
|
7
11
|
[]
|
|
8
|
-
), [
|
|
12
|
+
), [u, d] = i.useState({}), [V, C] = i.useState({}), [f, g] = i.useState({
|
|
9
13
|
left: [],
|
|
10
|
-
right:
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
right: s ? ["actions"] : []
|
|
15
|
+
}), F = P ?? c, I = r ?? a;
|
|
16
|
+
i.useEffect(() => {
|
|
17
|
+
if (n) {
|
|
18
|
+
if (n.hide || n.show) {
|
|
19
|
+
const e = {};
|
|
20
|
+
n.hide?.forEach((t) => {
|
|
21
|
+
e[t] = !1;
|
|
22
|
+
}), d(e);
|
|
23
|
+
}
|
|
24
|
+
n.pinnedColumns && g({
|
|
25
|
+
left: n.pinnedColumns.left || [],
|
|
26
|
+
right: [
|
|
27
|
+
...(n.pinnedColumns.right || []).filter(
|
|
28
|
+
(e) => e !== "actions"
|
|
29
|
+
),
|
|
30
|
+
...s ? ["actions"] : []
|
|
31
|
+
]
|
|
32
|
+
}), !r && n.sorting && a(n.sorting);
|
|
33
|
+
}
|
|
34
|
+
}, [n, s, r]), i.useEffect(() => {
|
|
35
|
+
if (!l) return;
|
|
36
|
+
const e = localStorage.getItem(`datatable-${l}`);
|
|
37
|
+
if (e)
|
|
16
38
|
try {
|
|
17
|
-
const t = JSON.parse(
|
|
18
|
-
t.columnVisibility &&
|
|
39
|
+
const t = JSON.parse(e);
|
|
40
|
+
t.columnVisibility && d(t.columnVisibility), t.columnPinning && g({
|
|
19
41
|
left: t.columnPinning.left || [],
|
|
20
42
|
right: [
|
|
21
43
|
...(t.columnPinning.right || []).filter(
|
|
22
44
|
(o) => o !== "actions"
|
|
23
45
|
),
|
|
24
|
-
...
|
|
46
|
+
...s ? ["actions"] : []
|
|
25
47
|
]
|
|
26
|
-
});
|
|
48
|
+
}), !r && t.sorting && a(t.sorting);
|
|
27
49
|
} catch (t) {
|
|
28
50
|
console.error("Failed to load table state", t);
|
|
29
51
|
}
|
|
30
|
-
}, [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
}, [l, s, r]), i.useEffect(() => {
|
|
53
|
+
const e = Object.entries(u).filter(([, o]) => !o).map(([o]) => o), t = {
|
|
54
|
+
hide: e.length > 0 ? e : void 0,
|
|
55
|
+
pinnedColumns: {
|
|
56
|
+
left: f.left || [],
|
|
57
|
+
right: f.right || []
|
|
58
|
+
},
|
|
59
|
+
// Only include sorting if not controlled externally
|
|
60
|
+
...!r && c.length > 0 && { sorting: c }
|
|
35
61
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
if (l) {
|
|
63
|
+
const o = {
|
|
64
|
+
columnVisibility: u,
|
|
65
|
+
columnPinning: f,
|
|
66
|
+
...!r && { sorting: c }
|
|
67
|
+
};
|
|
68
|
+
localStorage.setItem(`datatable-${l}`, JSON.stringify(o));
|
|
69
|
+
}
|
|
70
|
+
m && m(t);
|
|
71
|
+
}, [u, f, c, l, r, m]);
|
|
72
|
+
const O = i.useCallback(
|
|
73
|
+
(e) => {
|
|
74
|
+
g((t) => {
|
|
75
|
+
const o = typeof e == "function" ? e(t) : e, h = Array.isArray(o.left) ? o.left : [], b = Array.isArray(o.right) ? o.right : [];
|
|
76
|
+
if (s) {
|
|
77
|
+
const v = b.filter(
|
|
78
|
+
(J) => J !== "actions"
|
|
45
79
|
);
|
|
46
80
|
return {
|
|
47
|
-
left:
|
|
48
|
-
right: [...
|
|
81
|
+
left: h,
|
|
82
|
+
right: [...v, "actions"]
|
|
49
83
|
};
|
|
50
84
|
}
|
|
51
85
|
return {
|
|
52
|
-
left:
|
|
53
|
-
right:
|
|
86
|
+
left: h,
|
|
87
|
+
right: b
|
|
54
88
|
};
|
|
55
89
|
});
|
|
56
90
|
},
|
|
57
|
-
[
|
|
91
|
+
[s]
|
|
58
92
|
);
|
|
59
93
|
return {
|
|
60
|
-
sorting:
|
|
61
|
-
setSorting:
|
|
62
|
-
columnFilters:
|
|
63
|
-
setColumnFilters:
|
|
64
|
-
columnVisibility:
|
|
65
|
-
setColumnVisibility:
|
|
66
|
-
rowSelection:
|
|
67
|
-
setRowSelection:
|
|
68
|
-
columnPinning:
|
|
69
|
-
handleColumnPinningChange:
|
|
94
|
+
sorting: F,
|
|
95
|
+
setSorting: I,
|
|
96
|
+
columnFilters: y,
|
|
97
|
+
setColumnFilters: w,
|
|
98
|
+
columnVisibility: u,
|
|
99
|
+
setColumnVisibility: d,
|
|
100
|
+
rowSelection: V,
|
|
101
|
+
setRowSelection: C,
|
|
102
|
+
columnPinning: f,
|
|
103
|
+
handleColumnPinningChange: O
|
|
70
104
|
};
|
|
71
105
|
}
|
|
72
106
|
export {
|
|
73
|
-
|
|
107
|
+
N as useDataTableState
|
|
74
108
|
};
|