@yuno-payments/dashboard-design-system 0.0.138-beta.2 → 0.0.139

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
@@ -56,6 +65,11 @@ export interface DataTableProps<TData, TValue> {
56
65
  * @default 'onChange'
57
66
  */
58
67
  columnResizeMode?: ColumnResizeMode;
68
+ /**
69
+ * Whether to enable column pinning
70
+ * @default true
71
+ */
72
+ enableColumnPinning?: boolean;
59
73
  /**
60
74
  * Callback fired when a row is clicked
61
75
  */
@@ -81,6 +95,15 @@ export interface DataTableProps<TData, TValue> {
81
95
  * Unique key for persisting table state in localStorage
82
96
  */
83
97
  persistKey?: string;
98
+ /**
99
+ * Initial settings to load (from backend/profile)
100
+ * Takes precedence over localStorage
101
+ */
102
+ initialSettings?: import('./data-table.types').DataTableSettings;
103
+ /**
104
+ * Callback when table settings change (for syncing to backend)
105
+ */
106
+ onUpdate?: (settings: import('./data-table.types').DataTableSettings) => void;
84
107
  }
85
108
  /**
86
109
  * Advanced data table component built on TanStack Table.
@@ -103,4 +126,4 @@ export interface DataTableProps<TData, TValue> {
103
126
  * />
104
127
  * ```
105
128
  */
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;
129
+ export declare function DataTable<TData, TValue>({ columns, data, isLoading, empty, checkboxSelection, onRowSelectionChange, enableSorting, manualSorting, sorting: externalSorting, onSortingChange: externalOnSortingChange, enableColumnFilters, enableColumnResizing, columnResizeMode, enableColumnPinning, onRowClick, actions, height, rowHeight, className, persistKey, initialSettings, onUpdate, }: DataTableProps<TData, TValue>): import("react/jsx-runtime").JSX.Element;
@@ -1,141 +1,165 @@
1
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";
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({
15
- columns: a,
16
- data: s,
17
- isLoading: c = !1,
18
- empty: g,
19
- checkboxSelection: m = !1,
20
- onRowSelectionChange: o,
21
- enableSorting: p = !0,
22
- manualSorting: C = !1,
23
- enableColumnFilters: b = !1,
24
- 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
2
+ import * as B from "react";
3
+ import { useReactTable as I } from "../../../node_modules/@tanstack/react-table/build/lib/index.js";
4
+ import { Table as U } from "../../../vendor/shadcn/table.js";
5
+ import { cn as x } from "../../../lib/utils.js";
6
+ import { DataTableLoading as V } from "./components/states/data-table-loading.js";
7
+ import { DataTableHeader as q } from "./components/data-table-header.js";
8
+ import { DataTableBody as J } from "./components/data-table-body.js";
9
+ import { useDataTableColumns as K } from "./hooks/use-data-table-columns.js";
10
+ import { useDataTableState as Q } from "./hooks/use-data-table-state.js";
11
+ import { ROW_HEIGHT_DEFAULT as X } from "./utils/data-table-constants.js";
12
+ import { getFilteredRowModel as Y, getSortedRowModel as Z, getCoreRowModel as k } from "../../../node_modules/@tanstack/table-core/build/lib/index.js";
13
+ import { Empty as O } from "../../molecules/empty/empty.js";
14
+ function fo({
15
+ columns: m,
16
+ data: c,
17
+ isLoading: C = !1,
18
+ empty: b,
19
+ checkboxSelection: d = !1,
20
+ onRowSelectionChange: l,
21
+ enableSorting: h = !0,
22
+ manualSorting: S = !1,
23
+ sorting: j,
24
+ onSortingChange: w,
25
+ enableColumnFilters: y = !1,
26
+ enableColumnResizing: s = !0,
27
+ columnResizeMode: R = "onChange",
28
+ enableColumnPinning: T = !0,
29
+ onRowClick: D,
30
+ actions: r,
31
+ height: F,
32
+ rowHeight: u = X,
33
+ className: M,
34
+ persistKey: v,
35
+ initialSettings: E,
36
+ onUpdate: N
32
37
  }) {
33
- const y = O({
34
- columns: a,
35
- checkboxSelection: m,
36
- actions: n
38
+ const H = K({
39
+ columns: m,
40
+ checkboxSelection: d,
41
+ actions: r
37
42
  }), {
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({
52
- data: s,
53
- columns: y,
54
- getCoreRowModel: Q(),
55
- enableColumnResizing: i,
56
- columnResizeMode: h,
57
- enableColumnPinning: !0,
43
+ sorting: f,
44
+ setSorting: g,
45
+ columnFilters: P,
46
+ setColumnFilters: W,
47
+ columnVisibility: _,
48
+ setColumnVisibility: $,
49
+ rowSelection: p,
50
+ setRowSelection: z,
51
+ columnPinning: A,
52
+ handleColumnPinningChange: G
53
+ } = Q({
54
+ persistKey: v,
55
+ hasActions: !!r,
56
+ externalSorting: j,
57
+ onExternalSortingChange: w,
58
+ initialSettings: E,
59
+ onUpdate: N
60
+ }), i = I({
61
+ data: c,
62
+ columns: H,
63
+ getCoreRowModel: k(),
64
+ enableColumnResizing: s,
65
+ columnResizeMode: R,
66
+ enableColumnPinning: T,
58
67
  defaultColumn: {
59
68
  enableSorting: !1,
60
69
  minSize: 50
61
70
  },
62
- ...p && {
63
- onSortingChange: S,
64
- getSortedRowModel: K(),
65
- manualSorting: C
71
+ ...h && {
72
+ onSortingChange: (o) => {
73
+ g(typeof o == "function" ? o(f) : o);
74
+ },
75
+ getSortedRowModel: Z(),
76
+ manualSorting: S
66
77
  },
67
- ...b && {
68
- onColumnFiltersChange: F,
69
- getFilteredRowModel: J()
78
+ ...y && {
79
+ onColumnFiltersChange: W,
80
+ getFilteredRowModel: Y()
70
81
  },
71
- onColumnVisibilityChange: E,
72
- onRowSelectionChange: N,
73
- onColumnPinningChange: P,
82
+ onColumnVisibilityChange: $,
83
+ onRowSelectionChange: z,
84
+ onColumnPinningChange: G,
74
85
  state: {
75
- sorting: R,
76
- columnFilters: D,
77
- columnVisibility: M,
78
- rowSelection: f,
79
- columnPinning: v
86
+ sorting: f,
87
+ columnFilters: P,
88
+ columnVisibility: _,
89
+ rowSelection: p,
90
+ columnPinning: A
80
91
  }
81
92
  });
82
- if (L.useEffect(() => {
83
- if (o) {
84
- const r = t.getFilteredSelectedRowModel().rows.map((l) => l.original);
85
- o(r);
93
+ if (B.useEffect(() => {
94
+ if (l) {
95
+ const o = i.getFilteredSelectedRowModel().rows.map((t) => t.original);
96
+ l(o);
86
97
  }
87
- }, [f, o, t]), c)
98
+ }, [p, l, i]), C)
88
99
  return /* @__PURE__ */ e.jsx(
89
- B,
100
+ V,
90
101
  {
91
- columns: a,
92
- checkboxSelection: m,
93
- actions: n,
94
- rowHeight: d
102
+ columns: m,
103
+ checkboxSelection: d,
104
+ actions: r,
105
+ rowHeight: u
95
106
  }
96
107
  );
97
- if (s.length === 0) {
98
- const r = g || {}, {
99
- title: l = "No results",
100
- description: V = "No data available",
101
- media: A,
102
- actions: H
103
- } = r;
108
+ if (c.length === 0) {
109
+ const o = b || {}, {
110
+ title: t = "No results",
111
+ description: a = "No data available",
112
+ media: n,
113
+ actions: L
114
+ } = o;
104
115
  return /* @__PURE__ */ e.jsx(
105
- X,
116
+ O,
106
117
  {
107
- media: A,
108
- title: l,
109
- description: V,
110
- actions: H
118
+ media: n,
119
+ title: t,
120
+ description: a,
121
+ actions: L
111
122
  }
112
123
  );
113
124
  }
114
- return /* @__PURE__ */ e.jsx("div", { className: u("space-y-4", T), children: /* @__PURE__ */ e.jsx(
125
+ return /* @__PURE__ */ e.jsx("div", { className: x("space-y-4", M), children: /* @__PURE__ */ e.jsx(
115
126
  "div",
116
127
  {
117
128
  className: "rounded-md border overflow-x-auto",
118
- style: { height: w || "auto" },
129
+ style: { height: F || "auto" },
119
130
  children: /* @__PURE__ */ e.jsxs(
120
- _,
131
+ U,
121
132
  {
122
- className: u("table-fixed"),
123
- style: { width: "max-content", minWidth: "100%" },
133
+ className: x("table-fixed"),
124
134
  children: [
135
+ /* @__PURE__ */ e.jsx("colgroup", { children: i.getHeaderGroups()[0]?.headers.map((o) => {
136
+ const t = o.column.columnDef.enableResizing === !1, a = o.column.id === "_spacer", n = o.column.getSize();
137
+ return a ? /* @__PURE__ */ e.jsx("col", { style: { width: "auto" } }, o.id) : /* @__PURE__ */ e.jsx(
138
+ "col",
139
+ {
140
+ style: {
141
+ width: t ? `${n}px` : "auto",
142
+ minWidth: t ? `${n}px` : void 0,
143
+ maxWidth: t ? `${n}px` : void 0
144
+ }
145
+ },
146
+ o.id
147
+ );
148
+ }) }),
125
149
  /* @__PURE__ */ e.jsx(
126
- G,
150
+ q,
127
151
  {
128
- table: t,
129
- enableColumnResizing: i
152
+ table: i,
153
+ enableColumnResizing: s
130
154
  }
131
155
  ),
132
156
  /* @__PURE__ */ e.jsx(
133
- I,
157
+ J,
134
158
  {
135
- table: t,
136
- enableColumnResizing: i,
137
- onRowClick: x,
138
- rowHeight: d
159
+ table: i,
160
+ enableColumnResizing: s,
161
+ onRowClick: D,
162
+ rowHeight: u
139
163
  }
140
164
  )
141
165
  ]
@@ -145,5 +169,5 @@ function ae({
145
169
  ) });
146
170
  }
147
171
  export {
148
- ae as DataTable
172
+ fo as DataTable
149
173
  };
@@ -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[];
@@ -97,12 +114,15 @@ export interface DataTableProps<TData> {
97
114
  enableColumnFilters?: boolean;
98
115
  columnFilters?: ColumnFiltersState;
99
116
  onColumnFiltersChange?: (filters: ColumnFiltersState) => void;
117
+ enableColumnPinning?: boolean;
100
118
  columnVisibility?: VisibilityState;
101
119
  onColumnVisibilityChange?: (visibility: VisibilityState) => void;
102
120
  onRowClick?: (row: TData) => void;
103
121
  height?: string | number;
104
122
  rowHeight?: number;
105
123
  persistKey?: string;
124
+ initialSettings?: DataTableSettings;
125
+ onUpdate?: (settings: DataTableSettings) => void;
106
126
  renderToolbar?: () => React.ReactNode;
107
127
  renderActions?: () => React.ReactNode;
108
128
  className?: string;
@@ -1,78 +1,82 @@
1
- import { j as n } from "../../../../_virtual/jsx-runtime.js";
1
+ import { j as a } from "../../../../_virtual/jsx-runtime.js";
2
2
  import * as C from "react";
3
- import { Button as S } from "../../../atoms/button/button.js";
4
- import { DataTableColumnHeader as f } from "../components/column-header/data-table-column-header.js";
3
+ import { Button as b } from "../../../atoms/button/button.js";
4
+ import { DataTableColumnHeader as S } from "../components/column-header/data-table-column-header.js";
5
5
  import { isHeaderConfig as h } from "../utils/data-table-utils.js";
6
- import { ACTIONS_COLUMN_CONFIG as c } from "../utils/data-table-constants.js";
7
- import { Checkbox as u } from "../../../atoms/checkbox/checkbox.js";
8
- function P({
9
- columns: g,
6
+ import { COLUMN_MIN_SIZE_DEFAULT as p, CHECKBOX_COLUMN_CONFIG as c, ACTIONS_COLUMN_CONFIG as g } from "../utils/data-table-constants.js";
7
+ import { Checkbox as z } from "../../../atoms/checkbox/checkbox.js";
8
+ function _({
9
+ columns: f,
10
10
  checkboxSelection: d = !1,
11
- actions: a
11
+ actions: l
12
12
  }) {
13
13
  return C.useMemo(() => {
14
- let l = g.map((r) => {
15
- const { header: e, enablePinning: i = !0, ...t } = r, o = t.size !== void 0 ? { ...t, minSize: t.minSize ?? t.size } : t;
14
+ let n = f.map((t) => {
15
+ const { header: e, enablePinning: i = !0, ...r } = t, s = r.size !== void 0 ? { ...r, minSize: r.minSize ?? p } : r;
16
16
  return typeof e == "string" ? {
17
- ...o,
17
+ ...s,
18
18
  enablePinning: i,
19
- header: ({ column: s, table: m }) => /* @__PURE__ */ n.jsx(
20
- f,
19
+ header: ({ column: o, table: m }) => /* @__PURE__ */ a.jsx(
20
+ S,
21
21
  {
22
- column: s,
22
+ column: o,
23
23
  table: m,
24
24
  title: e
25
25
  }
26
26
  )
27
27
  } : h(e) ? {
28
- ...o,
28
+ ...s,
29
29
  enablePinning: i,
30
- header: ({ column: s, table: m }) => /* @__PURE__ */ n.jsx(
31
- f,
30
+ header: ({ column: o, table: m }) => /* @__PURE__ */ a.jsx(
31
+ S,
32
32
  {
33
- column: s,
33
+ column: o,
34
34
  table: m,
35
35
  title: e.title,
36
36
  info: e.info,
37
37
  className: e.className
38
38
  }
39
39
  )
40
- } : { ...o, header: e, enablePinning: i };
40
+ } : { ...s, header: e, enablePinning: i };
41
41
  });
42
- if (d && (l = [{
42
+ if (d && (n = [{
43
43
  id: "select",
44
- header: ({ table: e }) => /* @__PURE__ */ n.jsx(
45
- u,
44
+ header: ({ table: e }) => /* @__PURE__ */ a.jsx(
45
+ z,
46
46
  {
47
47
  checked: e.getIsAllPageRowsSelected() || (e.getIsSomePageRowsSelected() ? "indeterminate" : !1),
48
- onCheckedChange: (i) => e.toggleAllPageRowsSelected(!!i),
48
+ onChange: (i) => e.toggleAllPageRowsSelected(i.target.checked),
49
49
  "aria-label": "Select all"
50
50
  }
51
51
  ),
52
- cell: ({ row: e }) => /* @__PURE__ */ n.jsx(
53
- u,
52
+ cell: ({ row: e }) => /* @__PURE__ */ a.jsx(
53
+ z,
54
54
  {
55
55
  checked: e.getIsSelected(),
56
- onCheckedChange: (i) => e.toggleSelected(!!i),
56
+ onChange: (i) => e.toggleSelected(i.target.checked),
57
57
  "aria-label": "Select row"
58
58
  }
59
59
  ),
60
60
  enableSorting: !1,
61
61
  enableHiding: !1,
62
- enablePinning: !1
63
- }, ...l]), a) {
64
- const r = {
62
+ enablePinning: !1,
63
+ enableResizing: !1,
64
+ size: c.size,
65
+ minSize: c.minSize,
66
+ maxSize: c.maxSize
67
+ }, ...n]), l) {
68
+ const t = {
65
69
  id: "actions",
66
70
  header: "",
67
- cell: ({ row: e }) => a.render ? /* @__PURE__ */ n.jsx(n.Fragment, { children: a.render(e.original) }) : /* @__PURE__ */ n.jsx(
68
- S,
71
+ cell: ({ row: e }) => l.render ? /* @__PURE__ */ a.jsx(a.Fragment, { children: l.render(e.original) }) : /* @__PURE__ */ a.jsx(
72
+ b,
69
73
  {
70
74
  variant: "ghost",
71
75
  size: "icon",
72
76
  startIcon: "Eye",
73
77
  "aria-label": "Actions",
74
78
  onClick: (i) => {
75
- i.stopPropagation(), a.onClick?.(e.original);
79
+ i.stopPropagation(), l.onClick?.(e.original);
76
80
  }
77
81
  }
78
82
  ),
@@ -80,15 +84,27 @@ function P({
80
84
  enableHiding: !1,
81
85
  enablePinning: !1,
82
86
  enableResizing: !1,
83
- size: c.size,
84
- minSize: c.minSize,
85
- maxSize: c.maxSize
87
+ size: g.size,
88
+ minSize: g.minSize,
89
+ maxSize: g.maxSize
86
90
  };
87
- l = [...l, r];
91
+ n = [...n, t];
88
92
  }
89
- return l;
90
- }, [d, a, g]);
93
+ const u = {
94
+ id: "_spacer",
95
+ header: "",
96
+ cell: () => null,
97
+ enableSorting: !1,
98
+ enableHiding: !1,
99
+ enablePinning: !1,
100
+ enableResizing: !1,
101
+ size: 100,
102
+ // Arbitrary value, colgroup will override with auto
103
+ minSize: 0
104
+ };
105
+ return n = [...n, u], n;
106
+ }, [d, l, f]);
91
107
  }
92
108
  export {
93
- P as useDataTableColumns
109
+ _ as useDataTableColumns
94
110
  };
@@ -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;