@ztwoint/z-ui 0.1.88 → 0.1.89

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,47 +1,47 @@
1
1
  import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
2
  import * as S from "react";
3
- import { DEFAULT_EMPTY_MESSAGE as T, TABLE_CSS_CLASSES as o } from "./table.const.js";
4
- import { TableHeader as N } from "./components/table-header/table-header.js";
5
- import { TableRow as v } from "./components/table-row.js";
3
+ import { DEFAULT_EMPTY_MESSAGE as T, TABLE_CSS_CLASSES as l } from "./table.const.js";
4
+ import { TableHeader as w } from "./components/table-header/table-header.js";
5
+ import { TableRow as N } from "./components/table-row.js";
6
6
  import { TableMessageState as i } from "./components/table-message-state.js";
7
- import { TableContext as w } from "./table.context.js";
7
+ import { TableContext as v } from "./table.context.js";
8
8
  import { cn as d } from "../../lib/utils.js";
9
9
  const j = ({
10
- cell: s = { hasBorder: !0 },
10
+ cell: o = { hasBorder: !0 },
11
11
  sort: c,
12
12
  className: f,
13
13
  stickyHeader: p = !1,
14
- dataSourceError: l,
15
- ...u
14
+ dataSourceError: s,
15
+ ...h
16
16
  }) => {
17
- const h = S.useContext(w), {
17
+ const u = S.useContext(v), {
18
18
  dataSource: t = [],
19
19
  schema: a = [],
20
20
  loading: r = !1,
21
21
  emptyMessage: b = T,
22
22
  customCells: g
23
- } = h || u, x = () => l ? /* @__PURE__ */ e(
23
+ } = u || h, x = () => s ? /* @__PURE__ */ e(
24
24
  i,
25
25
  {
26
26
  colSpan: a.length,
27
- message: typeof l == "string" ? l : "Error loading data",
28
- className: o.dataErrorState
27
+ message: typeof s == "string" ? s : "Error loading data",
28
+ className: l.dataErrorState
29
29
  }
30
30
  ) : !t || t.length === 0 && !r ? /* @__PURE__ */ e(
31
31
  i,
32
32
  {
33
33
  colSpan: a.length,
34
34
  message: b,
35
- className: o.emptyState
35
+ className: l.emptyState
36
36
  }
37
37
  ) : /* @__PURE__ */ e("tbody", { children: t.map((y, m) => /* @__PURE__ */ e(
38
- v,
38
+ N,
39
39
  {
40
40
  record: y,
41
41
  index: m,
42
42
  schema: a,
43
43
  customCells: g,
44
- cell: s
44
+ cell: o
45
45
  },
46
46
  m
47
47
  )) });
@@ -49,14 +49,14 @@ const j = ({
49
49
  "div",
50
50
  {
51
51
  className: d(
52
- r ? "overflow-y-hidden relative" : "overflow-y-auto",
53
- o.bordered[s.hasBorder && !r && t.length > 0 ? "true" : "false"],
52
+ r ? "overflow-y-hidden relative" : "overflow-y-auto will-change-transform",
53
+ l.bordered[o.hasBorder && !r && t.length > 0 ? "true" : "false"],
54
54
  f
55
55
  ),
56
56
  children: [
57
- /* @__PURE__ */ n("table", { className: d(o.table, "w-full"), children: [
57
+ /* @__PURE__ */ n("table", { className: d(l.table, "w-full"), children: [
58
58
  x(),
59
- /* @__PURE__ */ e(N, { schema: a, sort: c, cell: s, stickyHeader: p })
59
+ /* @__PURE__ */ e(w, { schema: a, sort: c, cell: o, stickyHeader: p })
60
60
  ] }),
61
61
  r && /* @__PURE__ */ e("div", { className: "absolute top-0 inset-0 w-full h-full bg-white/80 flex items-center justify-center", children: /* @__PURE__ */ n("div", { className: "flex flex-col items-center gap-3", children: [
62
62
  /* @__PURE__ */ e("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-text-brand-secondary" }),
@@ -1,2 +1,3 @@
1
1
  export { SelectedFiltersDisplay } from './selected-filters-display';
2
+ export { getAppliedOptions } from './selected-filters-display.utils';
2
3
  export type { SelectedFilterDisplayProps, FilterDisplayItem, } from './selected-filters-display.type';
@@ -1,26 +1,31 @@
1
- import { jsxs as e, jsx as t, Fragment as s } from "react/jsx-runtime";
2
- import * as m from "react";
3
- const d = ({
4
- selectedItems: n,
5
- totalCount: l
6
- }) => /* @__PURE__ */ e("div", { className: "flex flex-col gap-2.5 max-w-md", children: [
7
- l > 0 && /* @__PURE__ */ e("span", { className: "text-text-neutral-primary leading-none-medium-sm", children: [
8
- l.toLocaleString(),
9
- " total"
10
- ] }),
11
- /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center gap-2.5 max-w-md", children: n.map((a, r) => /* @__PURE__ */ e(m.Fragment, { children: [
12
- /* @__PURE__ */ t("div", { className: "inline-flex items-center text-text-neutral-secondary rounded-md leading-none-regular-sm", children: /* @__PURE__ */ e("span", { className: "text-text-neutral-muted", children: [
13
- a.name,
14
- " ",
15
- a.total !== void 0 && /* @__PURE__ */ e(s, { children: [
16
- "[",
17
- /* @__PURE__ */ t("span", { className: "text-text-neutral-secondary", children: a.total.toLocaleString() }),
18
- "]"
19
- ] })
20
- ] }) }),
21
- r < n.length - 1 && /* @__PURE__ */ t("span", { className: "text-text-neutral-muted", children: "•" })
22
- ] }, a.name)) })
23
- ] });
1
+ import { jsxs as e, jsx as a, Fragment as c } from "react/jsx-runtime";
2
+ import * as d from "react";
3
+ import { getAppliedOptions as i } from "./selected-filters-display.utils.js";
4
+ const p = ({
5
+ totalCount: l,
6
+ tempFilters: r,
7
+ filterSchema: s
8
+ }) => {
9
+ const n = i(r, s);
10
+ return /* @__PURE__ */ e("div", { className: "flex flex-col gap-2.5 max-w-md", children: [
11
+ l > 0 && /* @__PURE__ */ e("span", { className: "text-text-neutral-primary leading-none-medium-sm", children: [
12
+ l.toLocaleString(),
13
+ " total"
14
+ ] }),
15
+ /* @__PURE__ */ a("div", { className: "flex flex-wrap items-center gap-2.5 max-w-md", children: n.map((t, m) => /* @__PURE__ */ e(d.Fragment, { children: [
16
+ /* @__PURE__ */ a("div", { className: "inline-flex items-center text-text-neutral-secondary rounded-md leading-none-regular-sm", children: /* @__PURE__ */ e("span", { className: "text-text-neutral-muted", children: [
17
+ t.name,
18
+ " ",
19
+ t.total !== void 0 && /* @__PURE__ */ e(c, { children: [
20
+ "[",
21
+ /* @__PURE__ */ a("span", { className: "text-text-neutral-secondary", children: t.total.toLocaleString() }),
22
+ "]"
23
+ ] })
24
+ ] }) }),
25
+ m < n.length - 1 && /* @__PURE__ */ a("span", { className: "text-text-neutral-muted", children: "•" })
26
+ ] }, t.name)) })
27
+ ] });
28
+ };
24
29
  export {
25
- d as SelectedFiltersDisplay
30
+ p as SelectedFiltersDisplay
26
31
  };
@@ -1,9 +1,8 @@
1
+ import { FilterRule, FilterSchema } from '../table-filter.type';
1
2
  export interface SelectedFilterDisplayProps {
2
- selectedItems: {
3
- name: string;
4
- total: number;
5
- }[];
6
3
  totalCount: number;
4
+ tempFilters: FilterRule[];
5
+ filterSchema: FilterSchema;
7
6
  }
8
7
  export interface FilterDisplayItem {
9
8
  field: string;
@@ -1,3 +1,6 @@
1
- import { FilterRule, FilterOption } from '../table-filter.type';
2
- export declare const formatFilterValue: (value: string | string[]) => string;
1
+ import { FilterRule, FilterSchema, FilterOption } from '../table-filter.type';
2
+ export declare const getAppliedOptions: (tempFilters: FilterRule[], filterSchema: FilterSchema) => {
3
+ name: string;
4
+ total: number;
5
+ }[];
3
6
  export declare const getFilterCount: (filterRule: FilterRule, filterOptions?: FilterOption[]) => number | undefined;
@@ -1,15 +1,23 @@
1
- const r = (e, t) => {
2
- if (!t || t.length === 0) return e.value !== "" ? 1 : 0;
1
+ const u = (e, n) => e.map(({ field: r, value: t }) => {
2
+ var o;
3
+ const a = (o = n.find(({ filterKey: s }) => s === r)) == null ? void 0 : o.options;
4
+ return !a || !Array.isArray(t) ? [] : t.map((s) => ({
5
+ name: s,
6
+ total: a[s]
7
+ }));
8
+ }).flat(), l = (e, n) => {
9
+ if (!n || n.length === 0) return e.value !== "" ? 1 : 0;
3
10
  if (Array.isArray(e.value)) {
4
- const u = t.filter(
5
- (n) => e.value.includes(n.value)
6
- ).reduce((n, o) => n + (o.total || 0), 0);
7
- return u > 0 ? u : void 0;
11
+ const t = n.filter(
12
+ (a) => e.value.includes(a.value)
13
+ ).reduce((a, o) => a + (o.total || 0), 0);
14
+ return t > 0 ? t : void 0;
8
15
  } else {
9
- const a = t.find((u) => u.value === e.value);
10
- return a == null ? void 0 : a.total;
16
+ const r = n.find((t) => t.value === e.value);
17
+ return r == null ? void 0 : r.total;
11
18
  }
12
19
  };
13
20
  export {
14
- r as getFilterCount
21
+ u as getAppliedOptions,
22
+ l as getFilterCount
15
23
  };
@@ -1,98 +1,97 @@
1
1
  import { jsxs as s, jsx as t } from "react/jsx-runtime";
2
2
  import * as b from "react";
3
- import * as f from "@radix-ui/react-popover";
3
+ import * as p from "@radix-ui/react-popover";
4
4
  import { Button as y } from "../button/button.js";
5
- import { useTableFilterContext as E } from "./table-filter.context.js";
6
- import G from "./filters/text.js";
7
- import J from "./filters/boolean.js";
8
- import M from "./filters/number/number.js";
9
- import Q from "./filters/checkbox.js";
10
- import W from "../assets/icons/circle-check-filled.js";
11
- import { SelectedFiltersDisplay as X } from "./selected-filters-display/selected-filters-display.js";
12
- import { FilterConfirmationDialog as Y } from "./close-filter-confirm/filter-confirmation-dialog.js";
13
- import { hasUnsavedFilterChanges as K } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
14
- const ce = () => {
15
- var k, A, j;
16
- const [O, c] = b.useState(!1), n = b.useRef(null), [C, d] = b.useState(!1), {
17
- selectedColumn: a,
18
- setSelectedColumn: P,
19
- getFilterForColumn: D,
20
- hasFilterForColumn: R,
21
- updateColumnFilter: T,
22
- clearAllFilters: $,
23
- resetToAppliedFilters: z,
24
- applyFilters: B,
25
- hasActiveFilters: p,
26
- tempFilters: N,
27
- filterSchema: u,
28
- filter: m,
29
- filterComponents: h = {}
30
- } = E(), L = (e) => {
31
- !e && C ? K(N, m.value) ? c(!0) : d(!1) : d(e);
32
- }, F = () => {
33
- B(), c(!1), d(!1);
5
+ import { useTableFilterContext as q } from "./table-filter.context.js";
6
+ import E from "./filters/text.js";
7
+ import G from "./filters/boolean.js";
8
+ import J from "./filters/number/number.js";
9
+ import M from "./filters/checkbox.js";
10
+ import Q from "../assets/icons/circle-check-filled.js";
11
+ import { SelectedFiltersDisplay as W } from "./selected-filters-display/selected-filters-display.js";
12
+ import { FilterConfirmationDialog as X } from "./close-filter-confirm/filter-confirmation-dialog.js";
13
+ import { hasUnsavedFilterChanges as S } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
14
+ const ie = () => {
15
+ var k, A;
16
+ const [K, i] = b.useState(!1), c = b.useRef(null), [C, d] = b.useState(!1), {
17
+ selectedColumn: o,
18
+ setSelectedColumn: O,
19
+ getFilterForColumn: P,
20
+ hasFilterForColumn: D,
21
+ updateColumnFilter: R,
22
+ clearAllFilters: T,
23
+ resetToAppliedFilters: $,
24
+ applyFilters: z,
25
+ hasActiveFilters: h,
26
+ tempFilters: u,
27
+ filterSchema: m,
28
+ filter: f,
29
+ filterComponents: g = {}
30
+ } = q(), B = (e) => {
31
+ !e && C ? S(u, f.value) ? i(!0) : d(!1) : d(e);
32
+ }, N = () => {
33
+ z(), i(!1), d(!1);
34
+ }, L = () => {
35
+ $(), i(!1), d(!1);
34
36
  }, I = () => {
35
- z(), c(!1), d(!1);
36
- }, V = () => {
37
- c(!1);
38
- }, w = K(N, m.value), l = D(a || ""), H = () => {
39
- if (!a) return null;
40
- const e = u.find((o) => o.filterKey === a), r = {
41
- boolean: J,
42
- string: G,
43
- number: M,
44
- checkbox: Q
45
- }, S = (e == null ? void 0 : e.type) && (h == null ? void 0 : h[e.type]) || r[(e == null ? void 0 : e.type) ?? "string"];
46
- if (!S)
37
+ i(!1);
38
+ }, F = S(u, f.value), l = P(o || ""), V = () => {
39
+ if (!o) return null;
40
+ const e = m.find((a) => a.filterKey === o), r = {
41
+ boolean: G,
42
+ string: E,
43
+ number: J,
44
+ checkbox: M
45
+ }, j = (e == null ? void 0 : e.type) && (g == null ? void 0 : g[e.type]) || r[(e == null ? void 0 : e.type) ?? "string"];
46
+ if (!j)
47
47
  return console.warn(
48
48
  `No filter component found for column "${e == null ? void 0 : e.filterKey}" with type "${e == null ? void 0 : e.type}". Provide a custom filter component or use supported types: "string", "number", "boolean", "checkbox".`
49
49
  ), null;
50
- const q = {
50
+ const U = {
51
51
  condition: (l == null ? void 0 : l.condition) || "",
52
52
  value: (l == null ? void 0 : l.value) || ""
53
53
  };
54
54
  return /* @__PURE__ */ t("div", { className: "flex-1 h-full", children: /* @__PURE__ */ t("div", { className: "mb-4 h-full", children: /* @__PURE__ */ t(
55
- S,
55
+ j,
56
56
  {
57
- value: q,
58
- onChange: ({ condition: o, value: x }) => T(a, o, x),
59
- filterOptions: e != null && e.options ? Object.entries(e.options).map(([o, x]) => ({
60
- label: o,
61
- value: o,
62
- total: x
57
+ value: U,
58
+ onChange: ({ condition: a, value: v }) => R(o, a, v),
59
+ filterOptions: e != null && e.options ? Object.entries(e.options).map(([a, v]) => ({
60
+ label: a,
61
+ value: a,
62
+ total: v
63
63
  })) : void 0
64
64
  },
65
- a
65
+ o
66
66
  ) }) });
67
- }, U = m.loading || !1;
68
- l && (Array.isArray(l.value) && l.value.length > 0 || (l == null ? void 0 : l.value) !== "") && (n.current = l);
69
- const g = u.find(
67
+ }, H = f.loading || !1;
68
+ l && (Array.isArray(l.value) && l.value.length > 0 || (l == null ? void 0 : l.value) !== "") && (c.current = l);
69
+ const x = m.find(
70
70
  (e) => {
71
71
  var r;
72
- return e.filterKey == ((r = n.current) == null ? void 0 : r.field);
72
+ return e.filterKey == ((r = c.current) == null ? void 0 : r.field);
73
73
  }
74
- ), v = Array.isArray((k = n.current) == null ? void 0 : k.value) ? (A = n.current) == null ? void 0 : A.value.map((e) => {
75
- var r;
76
- return {
77
- name: e,
78
- total: ((r = g == null ? void 0 : g.options) == null ? void 0 : r[e]) || 0
79
- };
80
- }) : [{ name: ((j = n.current) == null ? void 0 : j.value) || "", total: 1 }], i = v.reduce((e, r) => e + r.total, 0);
81
- return /* @__PURE__ */ s(f.Root, { open: C, onOpenChange: L, children: [
82
- /* @__PURE__ */ t(f.Trigger, { asChild: !0, children: /* @__PURE__ */ s(
74
+ ), w = Array.isArray((k = c.current) == null ? void 0 : k.value) ? (A = c.current) == null ? void 0 : A.value.map(
75
+ (e) => {
76
+ var r;
77
+ return ((r = x == null ? void 0 : x.options) == null ? void 0 : r[e]) || 0;
78
+ }
79
+ ) : [1], n = w.reduce((e, r) => e + r, 0);
80
+ return /* @__PURE__ */ s(p.Root, { open: C, onOpenChange: B, children: [
81
+ /* @__PURE__ */ t(p.Trigger, { asChild: !0, children: /* @__PURE__ */ s(
83
82
  y,
84
83
  {
85
- variant: p ? "filled" : "stroke",
86
- shade: p ? "brand" : "neutral",
84
+ variant: h ? "filled" : "stroke",
85
+ shade: h ? "brand" : "neutral",
87
86
  size: "small",
88
87
  children: [
89
88
  "Filters ",
90
- p && `(${m.value.length})`
89
+ h && `(${f.value.length})`
91
90
  ]
92
91
  }
93
92
  ) }),
94
- /* @__PURE__ */ t(f.Portal, { children: /* @__PURE__ */ s(
95
- f.Content,
93
+ /* @__PURE__ */ t(p.Portal, { children: /* @__PURE__ */ s(
94
+ p.Content,
96
95
  {
97
96
  className: "w-[512px] bg-surface-neutral-default border border-stroke-solid-light rounded-2xl overflow-hidden shadow-lg",
98
97
  sideOffset: 8,
@@ -101,41 +100,48 @@ const ce = () => {
101
100
  /* @__PURE__ */ s("div", { className: "flex h-[422px]", style: { maxHeight: "calc(100vh - 8rem)" }, children: [
102
101
  /* @__PURE__ */ s("div", { className: "w-48 border-r border-stroke-solid-light p-2 flex flex-col gap-1.5 overflow-y-auto", children: [
103
102
  /* @__PURE__ */ t("div", { className: "p-2 pb-1", children: /* @__PURE__ */ t("h3", { className: "leading-none-medium-sm text-text-neutral-secondary", children: "Filters" }) }),
104
- u.map((e) => /* @__PURE__ */ s(
103
+ m.map((e) => /* @__PURE__ */ s(
105
104
  "button",
106
105
  {
107
- onClick: () => P(e.filterKey),
108
- className: `w-full text-left p-2 text-sm flex items-center justify-between hover:bg-surface-neutral-hovered transition-colors rounded-lg ${a === e.filterKey ? "bg-surface-neutral-focused text-text-brand-primary" : "text-text-neutral-primary"}`,
106
+ onClick: () => O(e.filterKey),
107
+ className: `w-full text-left p-2 text-sm flex items-center justify-between hover:bg-surface-neutral-hover transition-colors rounded-lg ${o === e.filterKey ? "bg-surface-neutral-focused text-text-brand-primary" : "text-text-neutral-primary"}`,
109
108
  children: [
110
109
  /* @__PURE__ */ t("span", { className: "truncate", children: e.title }),
111
- R(e.filterKey) && /* @__PURE__ */ t(W, { className: "w-4 h-4 text-text-brand-secondary flex-shrink-0 ml-2" })
110
+ D(e.filterKey) && /* @__PURE__ */ t(Q, { className: "w-4 h-4 text-text-brand-secondary flex-shrink-0 ml-2" })
112
111
  ]
113
112
  },
114
113
  e.filterKey
115
114
  ))
116
115
  ] }),
117
116
  /* @__PURE__ */ s("div", { className: "flex-1 flex flex-col relative", children: [
118
- a ? H() : /* @__PURE__ */ t("div", { className: "flex-1 flex items-center justify-center text-text-neutral-muted", children: "Select a column to configure its filter" }),
119
- U && /* @__PURE__ */ t("div", { className: "flex items-center justify-center p-8 absolute top-0 left-0 right-0 bottom-0 bg-background-neutral-default/80", children: /* @__PURE__ */ s("div", { className: "flex flex-col items-center gap-3", children: [
117
+ o ? V() : /* @__PURE__ */ t("div", { className: "flex-1 flex items-center justify-center text-text-neutral-muted", children: "Select a column to configure its filter" }),
118
+ H && /* @__PURE__ */ t("div", { className: "flex items-center justify-center p-8 absolute top-0 left-0 right-0 bottom-0 bg-background-neutral-default/80", children: /* @__PURE__ */ s("div", { className: "flex flex-col items-center gap-3", children: [
120
119
  /* @__PURE__ */ t("div", { className: "w-8 h-8 border-2 border-stroke-solid-medium border-t-transparent rounded-full animate-spin" }),
121
120
  /* @__PURE__ */ t("span", { className: "text-text-body-primary text-sm", children: "Loading options..." })
122
121
  ] }) })
123
122
  ] })
124
123
  ] }),
125
- (!!i || w) && /* @__PURE__ */ s("div", { className: "flex justify-between items-end p-4 border-t border-stroke-solid-medium min-h-[73px]", children: [
126
- v.length > 0 ? /* @__PURE__ */ t(X, { selectedItems: v, totalCount: i }) : /* @__PURE__ */ t("div", { className: "w-full" }),
124
+ (!!n || F) && /* @__PURE__ */ s("div", { className: "flex justify-between items-end p-4 border-t border-stroke-solid-medium min-h-[73px]", children: [
125
+ w.length > 0 ? /* @__PURE__ */ t(
126
+ W,
127
+ {
128
+ tempFilters: u,
129
+ filterSchema: m,
130
+ totalCount: n
131
+ }
132
+ ) : /* @__PURE__ */ t("div", { className: "w-full" }),
127
133
  /* @__PURE__ */ s("div", { className: "flex justify-end gap-2", children: [
128
- !!i && /* @__PURE__ */ t(y, { onClick: $, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
134
+ !!n && /* @__PURE__ */ t(y, { onClick: T, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
129
135
  /* @__PURE__ */ t(
130
136
  y,
131
137
  {
132
- onClick: F,
138
+ onClick: N,
133
139
  variant: "filled",
134
140
  shade: "neutral",
135
141
  size: "small",
136
142
  className: "min-w-20",
137
- disabled: !w,
138
- children: `Apply ${i ? i.toLocaleString() : ""}`
143
+ disabled: !F,
144
+ children: `Apply ${n ? n.toLocaleString() : ""}`
139
145
  }
140
146
  )
141
147
  ] })
@@ -143,16 +149,16 @@ const ce = () => {
143
149
  ]
144
150
  }
145
151
  ) }),
146
- O && /* @__PURE__ */ t(
147
- Y,
152
+ K && /* @__PURE__ */ t(
153
+ X,
148
154
  {
149
- onClose: V,
150
- onRevertChanges: I,
151
- onApplyChanges: F
155
+ onClose: I,
156
+ onRevertChanges: L,
157
+ onApplyChanges: N
152
158
  }
153
159
  )
154
160
  ] });
155
161
  };
156
162
  export {
157
- ce as TableFilterButton
163
+ ie as TableFilterButton
158
164
  };