@ztwoint/z-ui 0.1.87 → 0.1.88
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.
- package/dist/components/table-card/table-card.js +43 -42
- package/dist/components/table-card/table-card.type.d.ts +1 -1
- package/dist/components/table-filter/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -1
- package/dist/components/table-filter/close-filter-confirm/filter-confirmation-dialog.js +14 -26
- package/dist/components/table-filter/filters/checkbox.js +28 -26
- package/dist/components/table-filter/selected-filters-display/selected-filters-display.js +23 -27
- package/dist/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +5 -3
- package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +1 -4
- package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.js +11 -26
- package/dist/components/table-filter/table-filter-button.js +104 -88
- package/dist/components/table-filter/table-filter-column-button.d.ts +1 -1
- package/dist/components/table-filter/table-filter-column-button.js +74 -73
- package/dist/components/table-filter/table-filter-provider.js +11 -6
- package/dist/components/table-filter/table-filter.hook.d.ts +1 -2
- package/dist/components/table-filter/table-filter.hook.js +54 -45
- package/dist/components/table-filter/table-filter.type.d.ts +2 -1
- package/dist/components/table-filter/table-filter.utils.d.ts +2 -0
- package/dist/components/table-filter/table-filter.utils.js +12 -0
- package/dist/css/styles/tailwind.css +1 -1
- package/dist/types/components/table-card/table-card.type.d.ts +1 -1
- package/dist/types/components/table-filter/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -1
- package/dist/types/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +5 -3
- package/dist/types/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +1 -4
- package/dist/types/components/table-filter/table-filter-column-button.d.ts +1 -1
- package/dist/types/components/table-filter/table-filter.hook.d.ts +1 -2
- package/dist/types/components/table-filter/table-filter.type.d.ts +2 -1
- package/dist/types/components/table-filter/table-filter.utils.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,124 +1,141 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { useTableFilterContext as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { SelectedFiltersDisplay as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const [
|
|
17
|
-
selectedColumn:
|
|
18
|
-
setSelectedColumn:
|
|
19
|
-
getFilterForColumn:
|
|
20
|
-
hasFilterForColumn:
|
|
21
|
-
updateColumnFilter:
|
|
22
|
-
clearAllFilters:
|
|
23
|
-
resetToAppliedFilters:
|
|
24
|
-
applyFilters:
|
|
25
|
-
hasActiveFilters:
|
|
26
|
-
tempFilters:
|
|
27
|
-
filterSchema:
|
|
28
|
-
filter:
|
|
29
|
-
filterComponents:
|
|
30
|
-
} =
|
|
31
|
-
!e &&
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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)
|
|
1
|
+
import { jsxs as s, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import * as b from "react";
|
|
3
|
+
import * as f from "@radix-ui/react-popover";
|
|
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);
|
|
34
|
+
}, 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)
|
|
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
|
|
53
|
-
condition: (
|
|
54
|
-
value: (
|
|
50
|
+
const q = {
|
|
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
|
-
|
|
55
|
+
S,
|
|
58
56
|
{
|
|
59
|
-
value:
|
|
60
|
-
onChange: ({ condition: o, value:
|
|
61
|
-
filterOptions: e != null && e.options ? Object.entries(e.options).map(([o,
|
|
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]) => ({
|
|
62
60
|
label: o,
|
|
63
61
|
value: o,
|
|
64
|
-
total:
|
|
62
|
+
total: x
|
|
65
63
|
})) : void 0
|
|
66
64
|
},
|
|
67
|
-
|
|
65
|
+
a
|
|
68
66
|
) }) });
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
70
|
+
(e) => {
|
|
71
|
+
var r;
|
|
72
|
+
return e.filterKey == ((r = n.current) == null ? void 0 : r.field);
|
|
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(
|
|
83
|
+
y,
|
|
73
84
|
{
|
|
74
|
-
variant:
|
|
75
|
-
shade:
|
|
85
|
+
variant: p ? "filled" : "stroke",
|
|
86
|
+
shade: p ? "brand" : "neutral",
|
|
76
87
|
size: "small",
|
|
77
88
|
children: [
|
|
78
89
|
"Filters ",
|
|
79
|
-
|
|
90
|
+
p && `(${m.value.length})`
|
|
80
91
|
]
|
|
81
92
|
}
|
|
82
93
|
) }),
|
|
83
|
-
/* @__PURE__ */ t(
|
|
84
|
-
|
|
94
|
+
/* @__PURE__ */ t(f.Portal, { children: /* @__PURE__ */ s(
|
|
95
|
+
f.Content,
|
|
85
96
|
{
|
|
86
97
|
className: "w-[512px] bg-surface-neutral-default border border-stroke-solid-light rounded-2xl overflow-hidden shadow-lg",
|
|
87
98
|
sideOffset: 8,
|
|
88
99
|
align: "start",
|
|
89
100
|
children: [
|
|
90
|
-
/* @__PURE__ */
|
|
91
|
-
/* @__PURE__ */
|
|
101
|
+
/* @__PURE__ */ s("div", { className: "flex h-[422px]", style: { maxHeight: "calc(100vh - 8rem)" }, children: [
|
|
102
|
+
/* @__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
103
|
/* @__PURE__ */ t("div", { className: "p-2 pb-1", children: /* @__PURE__ */ t("h3", { className: "leading-none-medium-sm text-text-neutral-secondary", children: "Filters" }) }),
|
|
93
|
-
|
|
104
|
+
u.map((e) => /* @__PURE__ */ s(
|
|
94
105
|
"button",
|
|
95
106
|
{
|
|
96
|
-
onClick: () =>
|
|
97
|
-
className: `w-full text-left p-2 text-sm flex items-center justify-between hover:bg-surface-neutral-hovered transition-colors rounded-lg ${
|
|
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"}`,
|
|
98
109
|
children: [
|
|
99
110
|
/* @__PURE__ */ t("span", { className: "truncate", children: e.title }),
|
|
100
|
-
|
|
111
|
+
R(e.filterKey) && /* @__PURE__ */ t(W, { className: "w-4 h-4 text-text-brand-secondary flex-shrink-0 ml-2" })
|
|
101
112
|
]
|
|
102
113
|
},
|
|
103
114
|
e.filterKey
|
|
104
115
|
))
|
|
105
116
|
] }),
|
|
106
|
-
/* @__PURE__ */
|
|
117
|
+
/* @__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: [
|
|
120
|
+
/* @__PURE__ */ t("div", { className: "w-8 h-8 border-2 border-stroke-solid-medium border-t-transparent rounded-full animate-spin" }),
|
|
121
|
+
/* @__PURE__ */ t("span", { className: "text-text-body-primary text-sm", children: "Loading options..." })
|
|
122
|
+
] }) })
|
|
123
|
+
] })
|
|
107
124
|
] }),
|
|
108
|
-
(!!
|
|
109
|
-
/* @__PURE__ */ t(
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
!!
|
|
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" }),
|
|
127
|
+
/* @__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" }),
|
|
112
129
|
/* @__PURE__ */ t(
|
|
113
|
-
|
|
130
|
+
y,
|
|
114
131
|
{
|
|
115
|
-
onClick:
|
|
132
|
+
onClick: F,
|
|
116
133
|
variant: "filled",
|
|
117
134
|
shade: "neutral",
|
|
118
135
|
size: "small",
|
|
119
136
|
className: "min-w-20",
|
|
120
|
-
disabled: !
|
|
121
|
-
children: `Apply ${
|
|
137
|
+
disabled: !w,
|
|
138
|
+
children: `Apply ${i ? i.toLocaleString() : ""}`
|
|
122
139
|
}
|
|
123
140
|
)
|
|
124
141
|
] })
|
|
@@ -126,17 +143,16 @@ const ne = () => {
|
|
|
126
143
|
]
|
|
127
144
|
}
|
|
128
145
|
) }),
|
|
129
|
-
|
|
130
|
-
|
|
146
|
+
O && /* @__PURE__ */ t(
|
|
147
|
+
Y,
|
|
131
148
|
{
|
|
132
|
-
onClose:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
onApplyChanges: v
|
|
149
|
+
onClose: V,
|
|
150
|
+
onRevertChanges: I,
|
|
151
|
+
onApplyChanges: F
|
|
136
152
|
}
|
|
137
153
|
)
|
|
138
154
|
] });
|
|
139
155
|
};
|
|
140
156
|
export {
|
|
141
|
-
|
|
157
|
+
ce as TableFilterButton
|
|
142
158
|
};
|
|
@@ -1,106 +1,107 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import * as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { useTableFilterContext as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { getFilterCount as
|
|
12
|
-
import { FilterConfirmationDialog as
|
|
13
|
-
import { hasUnsavedFilterChangesForColumn as
|
|
14
|
-
const
|
|
15
|
-
const [
|
|
16
|
-
getFilterForColumn:
|
|
17
|
-
hasAppliedFilterForColumn:
|
|
18
|
-
updateColumnFilter:
|
|
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:
|
|
21
|
-
filterSchema:
|
|
20
|
+
resetToAppliedFilters: T,
|
|
21
|
+
filterSchema: j,
|
|
22
22
|
filterComponents: m = {},
|
|
23
|
-
tempFilters:
|
|
24
|
-
filter:
|
|
25
|
-
} =
|
|
26
|
-
!
|
|
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
|
-
|
|
31
|
-
}, K = () => {
|
|
32
|
-
P(), s(!1), r(!1);
|
|
28
|
+
c(), i(!1), r(!1);
|
|
33
29
|
}, R = () => {
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
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
|
|
39
|
-
boolean:
|
|
40
|
-
string:
|
|
41
|
-
number:
|
|
42
|
-
checkbox:
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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__ */
|
|
59
|
-
/* @__PURE__ */
|
|
60
|
-
|
|
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__ */
|
|
66
|
-
|
|
67
|
-
h && /* @__PURE__ */
|
|
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__ */
|
|
72
|
-
|
|
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__ */
|
|
79
|
-
|
|
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:
|
|
82
|
-
onChange: ({ condition:
|
|
83
|
-
filterOptions:
|
|
81
|
+
value: l,
|
|
82
|
+
onChange: ({ condition: o, value: a }) => g(t, o, a),
|
|
83
|
+
filterOptions: y
|
|
84
84
|
}
|
|
85
85
|
),
|
|
86
|
-
(
|
|
87
|
-
/* @__PURE__ */
|
|
88
|
-
|
|
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
|
-
|
|
94
|
-
|
|
93
|
+
O && /* @__PURE__ */ e(
|
|
94
|
+
H,
|
|
95
95
|
{
|
|
96
|
-
onClose:
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
106
|
+
re as TableFilterColumnButton
|
|
106
107
|
};
|
|
@@ -7,20 +7,25 @@ const c = ({
|
|
|
7
7
|
filterSchema: e,
|
|
8
8
|
filter: o
|
|
9
9
|
}) => {
|
|
10
|
-
const
|
|
10
|
+
const l = a({
|
|
11
11
|
filterSchema: e,
|
|
12
|
-
filter: o || {
|
|
13
|
-
|
|
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
|
|
18
|
-
...
|
|
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:
|
|
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:
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
},
|
|
11
|
-
const e =
|
|
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
|
-
},
|
|
14
|
-
const
|
|
15
|
-
let
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
(s,
|
|
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
|
-
...
|
|
34
|
+
...l !== void 0 ? { value: l } : {}
|
|
22
35
|
} : s
|
|
23
36
|
);
|
|
24
37
|
else {
|
|
25
|
-
const
|
|
38
|
+
const s = {
|
|
26
39
|
field: t,
|
|
27
40
|
...e ? { condition: e } : {},
|
|
28
|
-
value:
|
|
41
|
+
value: l || ""
|
|
29
42
|
};
|
|
30
|
-
|
|
43
|
+
o = [...n, s];
|
|
31
44
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, h = () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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:
|
|
50
|
-
getFilterForColumn:
|
|
58
|
+
setSelectedColumn: f,
|
|
59
|
+
getFilterForColumn: c,
|
|
51
60
|
hasFilterForColumn: p,
|
|
52
|
-
hasAppliedFilterForColumn:
|
|
53
|
-
updateColumnFilter:
|
|
54
|
-
clearAllFilters:
|
|
55
|
-
resetToAppliedFilters:
|
|
56
|
-
applyFilters:
|
|
57
|
-
hasActiveFilters:
|
|
58
|
-
tempFilters:
|
|
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
|
-
|
|
24
|
+
onFilterClick?: (filters: FilterRule[], selectedColumn: string) => void;
|
|
25
|
+
loading?: boolean;
|
|
25
26
|
};
|
|
26
27
|
export interface TableFilterProps {
|
|
27
28
|
filterSchema: FilterSchema;
|
|
@@ -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
|
+
};
|