@ztwoint/z-ui 0.1.87 → 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.
Files changed (31) hide show
  1. package/dist/components/table/table.js +18 -18
  2. package/dist/components/table-card/table-card.js +43 -42
  3. package/dist/components/table-card/table-card.type.d.ts +1 -1
  4. package/dist/components/table-filter/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -1
  5. package/dist/components/table-filter/close-filter-confirm/filter-confirmation-dialog.js +14 -26
  6. package/dist/components/table-filter/filters/checkbox.js +28 -26
  7. package/dist/components/table-filter/selected-filters-display/index.d.ts +1 -0
  8. package/dist/components/table-filter/selected-filters-display/selected-filters-display.js +17 -16
  9. package/dist/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +3 -2
  10. package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +4 -4
  11. package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.js +18 -25
  12. package/dist/components/table-filter/table-filter-button.js +109 -87
  13. package/dist/components/table-filter/table-filter-column-button.d.ts +1 -1
  14. package/dist/components/table-filter/table-filter-column-button.js +74 -73
  15. package/dist/components/table-filter/table-filter-provider.js +11 -6
  16. package/dist/components/table-filter/table-filter.hook.d.ts +1 -2
  17. package/dist/components/table-filter/table-filter.hook.js +54 -45
  18. package/dist/components/table-filter/table-filter.type.d.ts +2 -1
  19. package/dist/components/table-filter/table-filter.utils.d.ts +2 -0
  20. package/dist/components/table-filter/table-filter.utils.js +12 -0
  21. package/dist/css/styles/tailwind.css +1 -1
  22. package/dist/types/components/table-card/table-card.type.d.ts +1 -1
  23. package/dist/types/components/table-filter/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -1
  24. package/dist/types/components/table-filter/selected-filters-display/index.d.ts +1 -0
  25. package/dist/types/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +3 -2
  26. package/dist/types/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +4 -4
  27. package/dist/types/components/table-filter/table-filter-column-button.d.ts +1 -1
  28. package/dist/types/components/table-filter/table-filter.hook.d.ts +1 -2
  29. package/dist/types/components/table-filter/table-filter.type.d.ts +2 -1
  30. package/dist/types/components/table-filter/table-filter.utils.d.ts +2 -0
  31. package/package.json +1 -1
@@ -1,124 +1,147 @@
1
- import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
- import * as F from "react";
3
- import * as d from "@radix-ui/react-popover";
4
- import { Button as x } from "../button/button.js";
5
- import { useTableFilterContext as H } from "./table-filter.context.js";
6
- import L from "./filters/text.js";
7
- import U from "./filters/boolean.js";
8
- import V from "./filters/number/number.js";
9
- import q from "./filters/checkbox.js";
10
- import E from "../assets/icons/circle-check-filled.js";
11
- import { SelectedFiltersDisplay as G } from "./selected-filters-display/selected-filters-display.js";
12
- import { createFilterDisplayItems as J, calculateTotalCount as M } from "./selected-filters-display/selected-filters-display.utils.js";
13
- import { FilterConfirmationDialog as Q } from "./close-filter-confirm/filter-confirmation-dialog.js";
14
- import { hasUnsavedFilterChanges as N } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
15
- const ne = () => {
16
- const [w, a] = F.useState(!1), [g, n] = F.useState(!1), {
17
- selectedColumn: r,
18
- setSelectedColumn: k,
19
- getFilterForColumn: K,
20
- hasFilterForColumn: S,
21
- updateColumnFilter: j,
22
- clearAllFilters: A,
23
- resetToAppliedFilters: D,
24
- applyFilters: O,
1
+ import { jsxs as s, jsx as t } from "react/jsx-runtime";
2
+ import * as b from "react";
3
+ import * as p from "@radix-ui/react-popover";
4
+ import { Button as y } from "../button/button.js";
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
25
  hasActiveFilters: h,
26
- tempFilters: i,
27
- filterSchema: c,
28
- filter: p,
29
- filterComponents: f = {}
30
- } = H(), P = (e) => {
31
- !e && g ? N(i, p.value) ? a(!0) : n(!1) : n(e);
32
- }, v = () => {
33
- O(), a(!1), n(!1);
34
- }, T = () => {
35
- a(!1), n(!1);
36
- }, $ = () => {
37
- D(), a(!1), n(!1);
38
- }, R = () => {
39
- a(!1);
40
- }, b = N(i, p.value), z = J(i, c), m = M(z), B = () => {
41
- if (!r) return null;
42
- const e = c.find((o) => o.filterKey === r), y = {
43
- boolean: U,
44
- string: L,
45
- number: V,
46
- checkbox: q
47
- }, C = (e == null ? void 0 : e.type) && (f == null ? void 0 : f[e.type]) || y[(e == null ? void 0 : e.type) ?? "string"];
48
- if (!C)
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);
36
+ }, I = () => {
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)
49
47
  return console.warn(
50
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".`
51
49
  ), null;
52
- const s = K(r), I = {
53
- condition: (s == null ? void 0 : s.condition) || "",
54
- value: (s == null ? void 0 : s.value) || ""
50
+ const U = {
51
+ condition: (l == null ? void 0 : l.condition) || "",
52
+ value: (l == null ? void 0 : l.value) || ""
55
53
  };
56
54
  return /* @__PURE__ */ t("div", { className: "flex-1 h-full", children: /* @__PURE__ */ t("div", { className: "mb-4 h-full", children: /* @__PURE__ */ t(
57
- C,
55
+ j,
58
56
  {
59
- value: I,
60
- onChange: ({ condition: o, value: u }) => j(r, o, u),
61
- filterOptions: e != null && e.options ? Object.entries(e.options).map(([o, u]) => ({
62
- label: o,
63
- value: o,
64
- total: u
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
65
63
  })) : void 0
66
64
  },
67
- r
65
+ o
68
66
  ) }) });
69
- };
70
- return /* @__PURE__ */ l(d.Root, { open: g, onOpenChange: P, children: [
71
- /* @__PURE__ */ t(d.Trigger, { asChild: !0, children: /* @__PURE__ */ l(
72
- x,
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
+ (e) => {
71
+ var r;
72
+ return e.filterKey == ((r = c.current) == null ? void 0 : r.field);
73
+ }
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(
82
+ y,
73
83
  {
74
84
  variant: h ? "filled" : "stroke",
75
85
  shade: h ? "brand" : "neutral",
76
86
  size: "small",
77
87
  children: [
78
88
  "Filters ",
79
- h && `(${p.value.length})`
89
+ h && `(${f.value.length})`
80
90
  ]
81
91
  }
82
92
  ) }),
83
- /* @__PURE__ */ t(d.Portal, { children: /* @__PURE__ */ l(
84
- d.Content,
93
+ /* @__PURE__ */ t(p.Portal, { children: /* @__PURE__ */ s(
94
+ p.Content,
85
95
  {
86
96
  className: "w-[512px] bg-surface-neutral-default border border-stroke-solid-light rounded-2xl overflow-hidden shadow-lg",
87
97
  sideOffset: 8,
88
98
  align: "start",
89
99
  children: [
90
- /* @__PURE__ */ l("div", { className: "flex h-[422px]", style: { maxHeight: "calc(100vh - 8rem)" }, children: [
91
- /* @__PURE__ */ l("div", { className: "w-48 border-r border-stroke-solid-light p-2 flex flex-col gap-1.5 overflow-y-auto", children: [
100
+ /* @__PURE__ */ s("div", { className: "flex h-[422px]", style: { maxHeight: "calc(100vh - 8rem)" }, children: [
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: [
92
102
  /* @__PURE__ */ t("div", { className: "p-2 pb-1", children: /* @__PURE__ */ t("h3", { className: "leading-none-medium-sm text-text-neutral-secondary", children: "Filters" }) }),
93
- c.map((e) => /* @__PURE__ */ l(
103
+ m.map((e) => /* @__PURE__ */ s(
94
104
  "button",
95
105
  {
96
- onClick: () => k(e.filterKey),
97
- className: `w-full text-left p-2 text-sm flex items-center justify-between hover:bg-surface-neutral-hovered transition-colors rounded-lg ${r === 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"}`,
98
108
  children: [
99
109
  /* @__PURE__ */ t("span", { className: "truncate", children: e.title }),
100
- S(e.filterKey) && /* @__PURE__ */ t(E, { 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" })
101
111
  ]
102
112
  },
103
113
  e.filterKey
104
114
  ))
105
115
  ] }),
106
- /* @__PURE__ */ t("div", { className: "flex-1 flex flex-col", children: r ? B() : /* @__PURE__ */ t("div", { className: "flex-1 flex items-center justify-center text-text-neutral-muted", children: "Select a column to configure its filter" }) })
116
+ /* @__PURE__ */ s("div", { className: "flex-1 flex flex-col relative", 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: [
119
+ /* @__PURE__ */ t("div", { className: "w-8 h-8 border-2 border-stroke-solid-medium border-t-transparent rounded-full animate-spin" }),
120
+ /* @__PURE__ */ t("span", { className: "text-text-body-primary text-sm", children: "Loading options..." })
121
+ ] }) })
122
+ ] })
107
123
  ] }),
108
- (!!m || b) && /* @__PURE__ */ l("div", { className: "flex justify-between items-end p-4 border-t border-stroke-solid-medium min-h-[73px]", children: [
109
- /* @__PURE__ */ t(G, { selectedFilters: i, schema: c }),
110
- /* @__PURE__ */ l("div", { className: "flex justify-end gap-2", children: [
111
- !!m && /* @__PURE__ */ t(x, { onClick: A, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
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" }),
133
+ /* @__PURE__ */ s("div", { className: "flex justify-end gap-2", children: [
134
+ !!n && /* @__PURE__ */ t(y, { onClick: T, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
112
135
  /* @__PURE__ */ t(
113
- x,
136
+ y,
114
137
  {
115
- onClick: v,
138
+ onClick: N,
116
139
  variant: "filled",
117
140
  shade: "neutral",
118
141
  size: "small",
119
142
  className: "min-w-20",
120
- disabled: !b,
121
- children: `Apply ${m ? m.toLocaleString() : ""}`
143
+ disabled: !F,
144
+ children: `Apply ${n ? n.toLocaleString() : ""}`
122
145
  }
123
146
  )
124
147
  ] })
@@ -126,17 +149,16 @@ const ne = () => {
126
149
  ]
127
150
  }
128
151
  ) }),
129
- w && /* @__PURE__ */ t(
130
- Q,
152
+ K && /* @__PURE__ */ t(
153
+ X,
131
154
  {
132
- onClose: R,
133
- onKeepChanges: T,
134
- onRevertChanges: $,
135
- onApplyChanges: v
155
+ onClose: I,
156
+ onRevertChanges: L,
157
+ onApplyChanges: N
136
158
  }
137
159
  )
138
160
  ] });
139
161
  };
140
162
  export {
141
- ne as TableFilterButton
163
+ ie as TableFilterButton
142
164
  };
@@ -1,3 +1,3 @@
1
+ import { default as React } from 'react';
1
2
  import { TableFilterColumnButtonProps } from './table-filter-column-button.type';
2
- import * as React from 'react';
3
3
  export declare const TableFilterColumnButton: React.FC<TableFilterColumnButtonProps>;
@@ -1,106 +1,107 @@
1
- import { jsxs as a, jsx as l } from "react/jsx-runtime";
2
- import * as x from "react";
3
- import * as p from "@radix-ui/react-popover";
4
- import { Button as d } from "../button/button.js";
5
- import { useTableFilterContext as U } from "./table-filter.context.js";
6
- import q from "./filters/text.js";
7
- import E from "./filters/boolean.js";
8
- import G from "./filters/number/number.js";
9
- import H from "./filters/checkbox.js";
10
- import J from "../assets/icons/circle-check-filled.js";
11
- import { getFilterCount as L } from "./selected-filters-display/selected-filters-display.utils.js";
12
- import { FilterConfirmationDialog as M } from "./close-filter-confirm/filter-confirmation-dialog.js";
13
- import { hasUnsavedFilterChangesForColumn as w } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
14
- const ne = ({ filterName: t }) => {
15
- const [k, s] = x.useState(!1), [f, r] = x.useState(!1), {
16
- getFilterForColumn: A,
17
- hasAppliedFilterForColumn: O,
18
- updateColumnFilter: u,
1
+ import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
+ import k, { useMemo as K } from "react";
3
+ import * as d from "@radix-ui/react-popover";
4
+ import { Button as f } from "../button/button.js";
5
+ import { useTableFilterContext as L } from "./table-filter.context.js";
6
+ import _ from "./filters/text.js";
7
+ import M from "./filters/boolean.js";
8
+ import U from "./filters/number/number.js";
9
+ import q from "./filters/checkbox.js";
10
+ import E from "../assets/icons/circle-check-filled.js";
11
+ import { getFilterCount as G } from "./selected-filters-display/selected-filters-display.utils.js";
12
+ import { FilterConfirmationDialog as H } from "./close-filter-confirm/filter-confirmation-dialog.js";
13
+ import { hasUnsavedFilterChangesForColumn as A } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
14
+ const re = ({ filterName: t }) => {
15
+ const [O, i] = k.useState(!1), [u, r] = k.useState(!1), {
16
+ getFilterForColumn: C,
17
+ hasAppliedFilterForColumn: P,
18
+ updateColumnFilter: g,
19
19
  applyFilters: c,
20
- resetToAppliedFilters: P,
21
- filterSchema: T,
20
+ resetToAppliedFilters: T,
21
+ filterSchema: j,
22
22
  filterComponents: m = {},
23
- tempFilters: C,
24
- filter: g
25
- } = U(), $ = (e) => {
26
- !e && f ? w(t, C, g.value) ? s(!0) : r(!1) : r(e);
27
- }, j = () => {
28
- c(), s(!1), r(!1);
23
+ tempFilters: v,
24
+ filter: p
25
+ } = L(), $ = (o) => {
26
+ !o && u ? A(t, v, p.value) ? i(!0) : r(!1) : r(o);
29
27
  }, D = () => {
30
- s(!1), r(!1);
31
- }, K = () => {
32
- P(), s(!1), r(!1);
28
+ c(), i(!1), r(!1);
33
29
  }, R = () => {
34
- s(!1);
35
- }, F = w(t, C, g.value), o = T.find((e) => e.filterKey === t);
36
- if (!o)
30
+ T(), i(!1), r(!1);
31
+ }, S = () => {
32
+ i(!1);
33
+ }, b = A(t, v, p.value), n = j.find((o) => o.filterKey === t), l = K(
34
+ () => C(t),
35
+ [t, C]
36
+ );
37
+ if (!n)
37
38
  return console.warn(`Column "${t}" not found in schema`), null;
38
- const S = {
39
- boolean: E,
40
- string: q,
41
- number: G,
42
- checkbox: H
43
- }, v = o.type && (m == null ? void 0 : m[o.type]) || S[o.type ?? "string"];
44
- if (!v)
45
- return console.warn(
46
- `No filter component found for column "${o.filterKey}" with type "${o.type}". Provide a custom filter component or use supported types: "string", "number", "boolean", "checkbox".`
47
- ), null;
48
- const n = A(t), h = O(t), b = o.options ? Object.entries(o.options).map(([e, i]) => ({
49
- label: e,
50
- value: e,
51
- total: i
52
- })) : void 0, y = n ? L(n, b) : void 0, z = n != null && n.value ? Array.isArray(n.value) ? n.value.length : 1 : 0, B = () => {
53
- const e = u(t, "", "");
54
- c(e), r(!1);
39
+ const z = {
40
+ boolean: M,
41
+ string: _,
42
+ number: U,
43
+ checkbox: q
44
+ }, F = n.type && (m == null ? void 0 : m[n.type]) || z[n.type ?? "string"], h = P(t), x = p.loading || !1, y = n.options ? Object.entries(n.options).map(([o, a]) => ({
45
+ label: o,
46
+ value: o,
47
+ total: a
48
+ })) : void 0, w = l ? G(l, y) : void 0, B = l != null && l.value ? Array.isArray(l.value) ? l.value.length : 1 : 0, N = () => {
49
+ const o = g(t, "", "");
50
+ c(o), r(!1);
55
51
  }, I = () => {
56
52
  c(), r(!1);
57
53
  };
58
- return /* @__PURE__ */ a(p.Root, { open: f, onOpenChange: $, children: [
59
- /* @__PURE__ */ l(p.Trigger, { asChild: !0, children: /* @__PURE__ */ l(
60
- d,
54
+ return F ? /* @__PURE__ */ s(d.Root, { open: u, onOpenChange: $, children: [
55
+ /* @__PURE__ */ e(d.Trigger, { asChild: !0, children: /* @__PURE__ */ e(
56
+ f,
61
57
  {
62
58
  variant: h ? "filled" : "stroke",
63
59
  shade: h ? "brand" : "neutral",
64
60
  size: "small",
65
- children: /* @__PURE__ */ a("span", { className: "flex items-center gap-2", children: [
66
- o.title,
67
- h && /* @__PURE__ */ l(J, { className: "w-4 h-4 text-white flex-shrink-0" })
61
+ children: /* @__PURE__ */ s("span", { className: "flex items-center gap-2", children: [
62
+ n.title,
63
+ h && /* @__PURE__ */ e(E, { className: "w-4 h-4 text-white flex-shrink-0" }),
64
+ x && /* @__PURE__ */ e("div", { className: "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin flex-shrink-0" })
68
65
  ] })
69
66
  }
70
67
  ) }),
71
- /* @__PURE__ */ l(p.Portal, { children: /* @__PURE__ */ a(
72
- p.Content,
68
+ /* @__PURE__ */ e(d.Portal, { children: /* @__PURE__ */ s(
69
+ d.Content,
73
70
  {
74
71
  className: "w-80 bg-surface-neutral-default border border-stroke-solid-light rounded-2xl overflow-hidden shadow-lg",
75
72
  sideOffset: 8,
76
73
  align: "start",
77
74
  children: [
78
- /* @__PURE__ */ l(
79
- v,
75
+ x ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ s("div", { className: "flex flex-col items-center gap-3", children: [
76
+ /* @__PURE__ */ e("div", { className: "w-8 h-8 border-2 border-stroke-solid-medium border-t-stroke-solid-strong rounded-full animate-spin" }),
77
+ /* @__PURE__ */ e("span", { className: "text-text-neutral-muted text-sm", children: "Loading options..." })
78
+ ] }) }) : /* @__PURE__ */ e(
79
+ F,
80
80
  {
81
- value: n,
82
- onChange: ({ condition: e, value: i }) => u(t, e, i),
83
- filterOptions: b
81
+ value: l,
82
+ onChange: ({ condition: o, value: a }) => g(t, o, a),
83
+ filterOptions: y
84
84
  }
85
85
  ),
86
- (F || !!z) && /* @__PURE__ */ a("div", { className: "flex justify-between gap-2 p-3 border-t border-stroke-solid-medium", children: [
87
- /* @__PURE__ */ l(d, { onClick: B, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
88
- F && /* @__PURE__ */ l(d, { onClick: I, variant: "filled", shade: "neutral", size: "small", children: `Apply${y !== void 0 ? ` ${y}` : ""}` })
86
+ (b || !!B) && /* @__PURE__ */ s("div", { className: "flex justify-between gap-2 p-3 border-t border-stroke-solid-medium", children: [
87
+ /* @__PURE__ */ e(f, { onClick: N, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
88
+ b && /* @__PURE__ */ e(f, { onClick: I, variant: "filled", shade: "neutral", size: "small", children: `Apply${w !== void 0 ? ` ${w}` : ""}` })
89
89
  ] })
90
90
  ]
91
91
  }
92
92
  ) }),
93
- k && /* @__PURE__ */ l(
94
- M,
93
+ O && /* @__PURE__ */ e(
94
+ H,
95
95
  {
96
- onClose: R,
97
- onKeepChanges: D,
98
- onRevertChanges: K,
99
- onApplyChanges: j
96
+ onClose: S,
97
+ onRevertChanges: R,
98
+ onApplyChanges: D
100
99
  }
101
100
  )
102
- ] });
101
+ ] }) : (console.warn(
102
+ `No filter component found for column "${n.filterKey}" with type "${n.type}". Provide a custom filter component or use supported types: "string", "number", "boolean", "checkbox".`
103
+ ), null);
103
104
  };
104
105
  export {
105
- ne as TableFilterColumnButton
106
+ re as TableFilterColumnButton
106
107
  };
@@ -7,20 +7,25 @@ const c = ({
7
7
  filterSchema: e,
8
8
  filter: o
9
9
  }) => {
10
- const n = a({
10
+ const l = a({
11
11
  filterSchema: e,
12
- filter: o || { value: [], onChange: () => {
13
- }, onDynamicChange: void 0 }
12
+ filter: o || {
13
+ value: [],
14
+ onChange: () => {
15
+ },
16
+ onFilterClick: void 0,
17
+ loading: !1
18
+ }
14
19
  });
15
20
  if (!o)
16
21
  return null;
17
- const l = {
18
- ...n,
22
+ const n = {
23
+ ...l,
19
24
  filterSchema: e,
20
25
  filter: o,
21
26
  filterComponents: t
22
27
  };
23
- return /* @__PURE__ */ i(u.Provider, { value: l, children: r });
28
+ return /* @__PURE__ */ i(u.Provider, { value: n, children: r });
24
29
  };
25
30
  export {
26
31
  c as TableFilterProvider
@@ -1,8 +1,7 @@
1
- import { default as React } from 'react';
2
1
  import { TableFilterProps, FilterRule } from './table-filter.type';
3
2
  declare const useTableFilter: ({ filter, filterSchema }: TableFilterProps) => {
4
3
  selectedColumn: string | null;
5
- setSelectedColumn: React.Dispatch<React.SetStateAction<string | null>>;
4
+ setSelectedColumn: (column: string | null) => void;
6
5
  getFilterForColumn: (columnKey: string) => FilterRule | undefined;
7
6
  hasFilterForColumn: (columnKey: string) => boolean;
8
7
  hasAppliedFilterForColumn: (columnKey: string) => boolean;
@@ -1,61 +1,70 @@
1
- import o from "react";
2
- const w = ({ filter: n, filterSchema: c }) => {
3
- const [v, d] = o.useState(null), [l, i] = o.useState(n.value);
4
- o.useEffect(() => {
5
- !v && c.length > 0 && d(c[0].filterKey);
6
- }, [v, c]);
7
- const F = (t) => l.find((e) => e.field === t), p = (t) => {
8
- const e = F(t);
1
+ import i, { useEffect as k } from "react";
2
+ import { removeInvalidFilterOptions as E } from "./table-filter.utils.js";
3
+ const w = ({ filter: r, filterSchema: a }) => {
4
+ const [v, F] = i.useState(null), [n, u] = i.useState(r.value);
5
+ k(() => {
6
+ u((t) => E(t, a));
7
+ }, [a]);
8
+ const f = i.useCallback(
9
+ (t) => {
10
+ if (F(t), t && r.onFilterClick) {
11
+ const e = n.filter((l) => Array.isArray(l.value) ? l.value.length > 0 : l.value !== "");
12
+ r.onFilterClick(e, t);
13
+ }
14
+ },
15
+ [r, n]
16
+ );
17
+ i.useEffect(() => {
18
+ !v && a.length > 0 && F(a[0].filterKey);
19
+ }, [v, a]);
20
+ const c = (t) => n.find((e) => e.field === t), p = (t) => {
21
+ const e = c(t);
9
22
  return e ? Array.isArray(e.value) ? e.value.length > 0 : e.value !== "" : !1;
10
- }, g = (t) => n.value.find((e) => e.field === t), m = (t) => {
11
- const e = g(t);
23
+ }, A = (t) => r.value.find((e) => e.field === t), C = (t) => {
24
+ const e = A(t);
12
25
  return e ? Array.isArray(e.value) ? e.value.length > 0 : e.value !== "" : !1;
13
- }, y = (t, e, a) => {
14
- const f = l.findIndex((r) => r.field === t);
15
- let u = [];
16
- if (f >= 0)
17
- u = l.map(
18
- (s, x) => x === f ? {
26
+ }, g = (t, e, l) => {
27
+ const d = n.findIndex((s) => s.field === t);
28
+ let o = [];
29
+ if (d >= 0)
30
+ o = n.map(
31
+ (s, T) => T === d ? {
19
32
  ...s,
20
33
  ...e !== void 0 ? { condition: e } : {},
21
- ...a !== void 0 ? { value: a } : {}
34
+ ...l !== void 0 ? { value: l } : {}
22
35
  } : s
23
36
  );
24
37
  else {
25
- const r = {
38
+ const s = {
26
39
  field: t,
27
40
  ...e ? { condition: e } : {},
28
- value: a || ""
41
+ value: l || ""
29
42
  };
30
- u = [...l, r];
43
+ o = [...n, s];
31
44
  }
32
- if (i(u), n.onDynamicChange) {
33
- const r = u.filter((s) => Array.isArray(s.value) ? s.value.length > 0 : s.value !== "");
34
- n.onDynamicChange(r);
35
- }
36
- return u;
37
- }, h = () => {
38
- i([]), n.onDynamicChange && n.onDynamicChange([]);
39
- }, C = () => {
40
- i(n.value), n.onDynamicChange && n.onDynamicChange(n.value);
41
- }, A = (t) => {
42
- const e = (t || l).filter((a) => Array.isArray(a.value) ? a.value.length > 0 : a.value !== "");
43
- n.onChange(e);
44
- }, D = n.value.length > 0;
45
- return o.useEffect(() => {
46
- i(n.value);
47
- }, [n.value]), {
45
+ return u(o), o;
46
+ }, m = () => {
47
+ u([]);
48
+ }, y = () => {
49
+ u(r.value);
50
+ }, h = (t) => {
51
+ const e = (t || n).filter((l) => Array.isArray(l.value) ? l.value.length > 0 : l.value !== "");
52
+ r.onChange(e);
53
+ }, x = r.value.length > 0;
54
+ return i.useEffect(() => {
55
+ u(r.value);
56
+ }, [r.value]), {
48
57
  selectedColumn: v,
49
- setSelectedColumn: d,
50
- getFilterForColumn: F,
58
+ setSelectedColumn: f,
59
+ getFilterForColumn: c,
51
60
  hasFilterForColumn: p,
52
- hasAppliedFilterForColumn: m,
53
- updateColumnFilter: y,
54
- clearAllFilters: h,
55
- resetToAppliedFilters: C,
56
- applyFilters: A,
57
- hasActiveFilters: D,
58
- tempFilters: l
61
+ hasAppliedFilterForColumn: C,
62
+ updateColumnFilter: g,
63
+ clearAllFilters: m,
64
+ resetToAppliedFilters: y,
65
+ applyFilters: h,
66
+ hasActiveFilters: x,
67
+ tempFilters: n
59
68
  };
60
69
  };
61
70
  export {
@@ -21,7 +21,8 @@ export type FilterSchema = FilterSchemaField[];
21
21
  export type TableFilter = {
22
22
  value: FilterRule[];
23
23
  onChange: (filters: FilterRule[]) => void;
24
- onDynamicChange?: (filters: FilterRule[]) => void;
24
+ onFilterClick?: (filters: FilterRule[], selectedColumn: string) => void;
25
+ loading?: boolean;
25
26
  };
26
27
  export interface TableFilterProps {
27
28
  filterSchema: FilterSchema;
@@ -0,0 +1,2 @@
1
+ import { FilterRule, FilterSchema } from './table-filter.type';
2
+ export declare const removeInvalidFilterOptions: (filters: FilterRule[], filterSchema: FilterSchema) => FilterRule[];
@@ -0,0 +1,12 @@
1
+ const l = (t, i) => {
2
+ const s = i.map((e) => e.filterKey);
3
+ return t.filter((e) => {
4
+ const n = i.find((r) => r.filterKey === e.field);
5
+ return n ? (Array.isArray(e.value) && (e.value = e.value.filter(
6
+ (r) => Object.entries(n.options || {}).some(([a]) => a === r)
7
+ )), s.includes(e.field)) : !1;
8
+ });
9
+ };
10
+ export {
11
+ l as removeInvalidFilterOptions
12
+ };