@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.
@@ -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
  };
@@ -10,6 +10,11 @@ export declare const RESIZE_HANDLE_CONFIG: {
10
10
  readonly lineHeight: "h-5";
11
11
  readonly lineWidth: "w-[1px]";
12
12
  };
13
+ export declare const CHECKBOX_COLUMN_CONFIG: {
14
+ readonly size: 50;
15
+ readonly minSize: 50;
16
+ readonly maxSize: 50;
17
+ };
13
18
  export declare const ACTIONS_COLUMN_CONFIG: {
14
19
  readonly size: 50;
15
20
  readonly minSize: 50;
@@ -20,4 +25,5 @@ export declare const CELL_BACKGROUND_COLORS: {
20
25
  readonly body: "hsl(var(--background))";
21
26
  };
22
27
  export declare const ROW_HEIGHT_DEFAULT = 66;
28
+ export declare const COLUMN_MIN_SIZE_DEFAULT = 50;
23
29
  export declare const PINNED_SHADOW_CLASS = "shadow-[-4px_0_4px_-2px_rgba(0,0,0,0.1)]";
@@ -1,26 +1,32 @@
1
- const e = {
1
+ const _ = {
2
2
  height: "h-8",
3
3
  gap: "gap-1.5",
4
4
  roundedClass: "rounded-md",
5
5
  fontSize: "text-sm",
6
6
  fontWeight: "font-medium"
7
- }, t = {
7
+ }, e = {
8
8
  width: "w-2",
9
9
  lineHeight: "h-5",
10
10
  lineWidth: "w-[1px]"
11
- }, _ = {
11
+ }, t = {
12
+ size: 50,
13
+ minSize: 50,
14
+ maxSize: 50
15
+ }, i = {
12
16
  size: 50,
13
17
  minSize: 50,
14
18
  maxSize: 50
15
19
  }, n = {
16
20
  header: "hsl(var(--sidebar))",
17
21
  body: "hsl(var(--background))"
18
- }, o = 66, i = "shadow-[-4px_0_4px_-2px_rgba(0,0,0,0.1)]";
22
+ }, o = 66, s = 50, C = "shadow-[-4px_0_4px_-2px_rgba(0,0,0,0.1)]";
19
23
  export {
20
- _ as ACTIONS_COLUMN_CONFIG,
24
+ i as ACTIONS_COLUMN_CONFIG,
21
25
  n as CELL_BACKGROUND_COLORS,
22
- e as COLUMN_HEADER_CONFIG,
23
- i as PINNED_SHADOW_CLASS,
24
- t as RESIZE_HANDLE_CONFIG,
26
+ t as CHECKBOX_COLUMN_CONFIG,
27
+ _ as COLUMN_HEADER_CONFIG,
28
+ s as COLUMN_MIN_SIZE_DEFAULT,
29
+ C as PINNED_SHADOW_CLASS,
30
+ e as RESIZE_HANDLE_CONFIG,
25
31
  o as ROW_HEIGHT_DEFAULT
26
32
  };