@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.
@@ -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 e } from "../../../_virtual/jsx-runtime.js";
2
- import * as L from "react";
3
- import { useReactTable as W } from "../../../node_modules/@tanstack/react-table/build/lib/index.js";
4
- import { Table as _ } from "../../../vendor/shadcn/table.js";
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 B } from "./components/states/data-table-loading.js";
7
- import { DataTableHeader as G } from "./components/data-table-header.js";
8
- import { DataTableBody as I } from "./components/data-table-body.js";
9
- import { useDataTableColumns as O } from "./hooks/use-data-table-columns.js";
10
- import { useDataTableState as U } from "./hooks/use-data-table-state.js";
11
- import { ROW_HEIGHT_DEFAULT as q } from "./utils/data-table-constants.js";
12
- import { getFilteredRowModel as J, getSortedRowModel as K, getCoreRowModel as Q } from "../../../node_modules/@tanstack/table-core/build/lib/index.js";
13
- import { Empty as X } from "../../molecules/empty/empty.js";
14
- function ae({
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: c = !1,
18
- empty: g,
17
+ isLoading: p = !1,
18
+ empty: C,
19
19
  checkboxSelection: m = !1,
20
- onRowSelectionChange: o,
21
- enableSorting: p = !0,
22
- manualSorting: C = !1,
23
- enableColumnFilters: b = !1,
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: h = "onChange",
26
- onRowClick: x,
27
- actions: n,
28
- height: w,
29
- rowHeight: d = q,
30
- className: T,
31
- persistKey: j
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 y = O({
37
+ const E = Q({
34
38
  columns: a,
35
39
  checkboxSelection: m,
36
- actions: n
40
+ actions: r
37
41
  }), {
38
- sorting: R,
39
- setSorting: S,
40
- columnFilters: D,
41
- setColumnFilters: F,
42
- columnVisibility: M,
43
- setColumnVisibility: E,
44
- rowSelection: f,
45
- setRowSelection: N,
46
- columnPinning: v,
47
- handleColumnPinningChange: P
48
- } = U({
49
- persistKey: j,
50
- hasActions: !!n
51
- }), t = W({
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: y,
54
- getCoreRowModel: Q(),
61
+ columns: E,
62
+ getCoreRowModel: k(),
55
63
  enableColumnResizing: i,
56
- columnResizeMode: h,
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
- onColumnFiltersChange: F,
69
- getFilteredRowModel: J()
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: E,
72
- onRowSelectionChange: N,
73
- onColumnPinningChange: P,
81
+ onColumnVisibilityChange: A,
82
+ onRowSelectionChange: H,
83
+ onColumnPinningChange: W,
74
84
  state: {
75
- sorting: R,
76
- columnFilters: D,
77
- columnVisibility: M,
78
- rowSelection: f,
79
- columnPinning: v
85
+ sorting: f,
86
+ columnFilters: N,
87
+ columnVisibility: P,
88
+ rowSelection: c,
89
+ columnPinning: L
80
90
  }
81
91
  });
82
- if (L.useEffect(() => {
83
- if (o) {
84
- const r = t.getFilteredSelectedRowModel().rows.map((l) => l.original);
85
- o(r);
92
+ if (I.useEffect(() => {
93
+ if (n) {
94
+ const e = t.getFilteredSelectedRowModel().rows.map((l) => l.original);
95
+ n(e);
86
96
  }
87
- }, [f, o, t]), c)
88
- return /* @__PURE__ */ e.jsx(
89
- B,
97
+ }, [c, n, t]), p)
98
+ return /* @__PURE__ */ o.jsx(
99
+ q,
90
100
  {
91
101
  columns: a,
92
102
  checkboxSelection: m,
93
- actions: n,
103
+ actions: r,
94
104
  rowHeight: d
95
105
  }
96
106
  );
97
107
  if (s.length === 0) {
98
- const r = g || {}, {
108
+ const e = C || {}, {
99
109
  title: l = "No results",
100
- description: V = "No data available",
101
- media: A,
102
- actions: H
103
- } = r;
104
- return /* @__PURE__ */ e.jsx(
105
- X,
110
+ description: _ = "No data available",
111
+ media: B,
112
+ actions: G
113
+ } = e;
114
+ return /* @__PURE__ */ o.jsx(
115
+ z,
106
116
  {
107
- media: A,
117
+ media: B,
108
118
  title: l,
109
- description: V,
110
- actions: H
119
+ description: _,
120
+ actions: G
111
121
  }
112
122
  );
113
123
  }
114
- return /* @__PURE__ */ e.jsx("div", { className: u("space-y-4", T), children: /* @__PURE__ */ e.jsx(
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: w || "auto" },
119
- children: /* @__PURE__ */ e.jsxs(
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__ */ e.jsx(
126
- G,
135
+ /* @__PURE__ */ o.jsx(
136
+ J,
127
137
  {
128
138
  table: t,
129
139
  enableColumnResizing: i
130
140
  }
131
141
  ),
132
- /* @__PURE__ */ e.jsx(
133
- I,
142
+ /* @__PURE__ */ o.jsx(
143
+ K,
134
144
  {
135
145
  table: t,
136
146
  enableColumnResizing: i,
137
- onRowClick: x,
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
- ae as DataTable
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: React.Dispatch<React.SetStateAction<SortingState>>;
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 e from "react";
2
- function V({
3
- persistKey: i,
4
- hasActions: l = !1
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 [g, m] = e.useState([]), [S, b] = e.useState(
10
+ const [c, a] = i.useState([]), [y, w] = i.useState(
7
11
  []
8
- ), [r, c] = e.useState({}), [h, P] = e.useState({}), [a, s] = e.useState({
12
+ ), [u, d] = i.useState({}), [V, C] = i.useState({}), [f, g] = i.useState({
9
13
  left: [],
10
- right: l ? ["actions"] : []
11
- });
12
- e.useEffect(() => {
13
- if (!i) return;
14
- const n = localStorage.getItem(`datatable-${i}`);
15
- if (n)
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(n);
18
- t.columnVisibility && c(t.columnVisibility), t.columnPinning && s({
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
- ...l ? ["actions"] : []
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
- }, [i, l]), e.useEffect(() => {
31
- if (!i) return;
32
- const n = {
33
- columnVisibility: r,
34
- columnPinning: a
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
- localStorage.setItem(`datatable-${i}`, JSON.stringify(n));
37
- }, [r, a, i]);
38
- const d = e.useCallback(
39
- (n) => {
40
- s((t) => {
41
- const o = typeof n == "function" ? n(t) : n, u = Array.isArray(o.left) ? o.left : [], f = Array.isArray(o.right) ? o.right : [];
42
- if (l) {
43
- const y = f.filter(
44
- (C) => C !== "actions"
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: u,
48
- right: [...y, "actions"]
81
+ left: h,
82
+ right: [...v, "actions"]
49
83
  };
50
84
  }
51
85
  return {
52
- left: u,
53
- right: f
86
+ left: h,
87
+ right: b
54
88
  };
55
89
  });
56
90
  },
57
- [l]
91
+ [s]
58
92
  );
59
93
  return {
60
- sorting: g,
61
- setSorting: m,
62
- columnFilters: S,
63
- setColumnFilters: b,
64
- columnVisibility: r,
65
- setColumnVisibility: c,
66
- rowSelection: h,
67
- setRowSelection: P,
68
- columnPinning: a,
69
- handleColumnPinningChange: d
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
- V as useDataTableState
107
+ N as useDataTableState
74
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuno-payments/dashboard-design-system",
3
- "version": "0.0.128",
3
+ "version": "0.0.130",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",