@ztwoint/z-ui 0.1.64 → 0.1.66
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/column-reorder/column-reorder.js +20 -10
- package/dist/components/column-reorder/column-reorder.type.d.ts +1 -0
- package/dist/components/column-reorder/components/column-item/column-item.js +42 -37
- package/dist/components/column-reorder/components/column-item/column-item.type.d.ts +1 -0
- package/dist/components/table/components/cell/avatar-cell.js +3 -2
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/table-provider.d.ts +0 -2
- package/dist/components/table/table-provider.js +20 -23
- package/dist/components/table/table.type.d.ts +0 -20
- package/dist/components/table-card/table-card.js +50 -49
- package/dist/components/table-card/table-card.type.d.ts +3 -1
- package/dist/components/{table/components/table-filter → table-filter}/close-filter-confirm/filter-confirmation-dialog.js +2 -2
- package/dist/{types/components/table/components → components}/table-filter/close-filter-confirm/filter-confirmation-dialog.utils.d.ts +1 -1
- package/dist/components/{table/components/table-filter → table-filter}/filters/checkbox.js +2 -2
- package/dist/components/{table/components/table-filter → table-filter}/filters/number/filter-input-field.js +1 -1
- package/dist/components/{table/components/table-filter → table-filter}/filters/text.js +3 -3
- package/dist/components/table-filter/index.d.ts +9 -0
- package/dist/components/table-filter/index.js +11 -0
- package/dist/{types/components/table/components → components}/table-filter/selected-filters-display/selected-filters-display.type.d.ts +2 -2
- package/dist/components/{table/components/table-filter → table-filter}/selected-filters-display/selected-filters-display.utils.d.ts +2 -2
- package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.js +30 -0
- package/dist/components/{table/components/table-filter → table-filter}/table-filter-button.js +71 -67
- package/dist/components/table-filter/table-filter-column-button.js +110 -0
- package/dist/components/table-filter/table-filter-provider.d.ts +3 -0
- package/dist/components/table-filter/table-filter-provider.js +27 -0
- package/dist/components/{table/components/table-filter → table-filter}/table-filter.context.d.ts +2 -4
- package/dist/components/{table/components/table-filter → table-filter}/table-filter.hook.d.ts +2 -4
- package/dist/components/{table/components/table-filter → table-filter}/table-filter.hook.js +23 -24
- package/dist/components/table-filter/table-filter.type.d.ts +44 -0
- package/dist/routes/table.d.ts +3 -0
- package/dist/types/components/column-reorder/column-reorder.type.d.ts +1 -0
- package/dist/types/components/column-reorder/components/column-item/column-item.type.d.ts +1 -0
- package/dist/types/components/table/index.d.ts +1 -1
- package/dist/types/components/table/table-provider.d.ts +0 -2
- package/dist/types/components/table/table.type.d.ts +0 -20
- package/dist/types/components/table-card/table-card.type.d.ts +4 -1
- package/dist/{components/table → types}/components/table-filter/close-filter-confirm/filter-confirmation-dialog.utils.d.ts +1 -1
- package/dist/types/components/table-filter/index.d.ts +9 -0
- package/dist/{components/table → types}/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +2 -2
- package/dist/types/components/{table/components/table-filter → table-filter}/selected-filters-display/selected-filters-display.utils.d.ts +2 -2
- package/dist/types/components/table-filter/table-filter-provider.d.ts +3 -0
- package/dist/types/components/{table/components/table-filter → table-filter}/table-filter.context.d.ts +3 -3
- package/dist/types/components/{table/components/table-filter → table-filter}/table-filter.hook.d.ts +2 -3
- package/dist/types/components/table-filter/table-filter.type.d.ts +44 -0
- package/dist/types/routes/table.d.ts +3 -0
- package/package.json +1 -1
- package/dist/components/table/components/table-filter/index.d.ts +0 -4
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.utils.js +0 -26
- package/dist/components/table/components/table-filter/table-filter-column-button.js +0 -108
- package/dist/components/table/components/table-filter/table-filter-provider.d.ts +0 -14
- package/dist/components/table/components/table-filter/table-filter-provider.js +0 -32
- package/dist/components/table/components/table-filter/table-filter.type.d.ts +0 -19
- package/dist/types/components/table/components/table-filter/index.d.ts +0 -4
- package/dist/types/components/table/components/table-filter/table-filter-provider.d.ts +0 -14
- package/dist/types/components/table/components/table-filter/table-filter.type.d.ts +0 -19
- /package/dist/components/{table/components/table-filter → table-filter}/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/close-filter-confirm/filter-confirmation-dialog.utils.js +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/boolean.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/boolean.js +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/checkbox.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/index.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/filter-input-field.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/index.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/number.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/number.hook.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/number.hook.js +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/number/number.js +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/filters/text.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/selected-filters-display/index.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/selected-filters-display/selected-filters-display.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/selected-filters-display/selected-filters-display.js +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/table-filter-button.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/table-filter-column-button.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/table-filter-column-button.type.d.ts +0 -0
- /package/dist/components/{table/components/table-filter → table-filter}/table-filter.context.js +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/close-filter-confirm/filter-confirmation-dialog.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/boolean.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/checkbox.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/index.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/number/filter-input-field.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/number/index.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/number/number.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/number/number.hook.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/filters/text.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/selected-filters-display/index.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/selected-filters-display/selected-filters-display.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/table-filter-button.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/table-filter-column-button.d.ts +0 -0
- /package/dist/types/components/{table/components/table-filter → table-filter}/table-filter-column-button.type.d.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TableFilterProvider as o } from "./table-filter-provider.js";
|
|
2
|
+
import { TableFilterButton as r } from "./table-filter-button.js";
|
|
3
|
+
import { TableFilterColumnButton as e } from "./table-filter-column-button.js";
|
|
4
|
+
import { useTableFilterContext as F } from "./table-filter.context.js";
|
|
5
|
+
const t = o;
|
|
6
|
+
t.FilterButton = r;
|
|
7
|
+
t.FilterColumnButton = e;
|
|
8
|
+
export {
|
|
9
|
+
t as Filter,
|
|
10
|
+
F as useTableFilterContext
|
|
11
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FilterRule,
|
|
1
|
+
import { FilterRule, FilterSchema } from '../table-filter.type';
|
|
2
2
|
export interface SelectedFilterDisplayProps {
|
|
3
3
|
selectedFilters: FilterRule[];
|
|
4
|
-
schema:
|
|
4
|
+
schema: FilterSchema;
|
|
5
5
|
}
|
|
6
6
|
export interface FilterDisplayItem {
|
|
7
7
|
field: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FilterRule,
|
|
1
|
+
import { FilterRule, FilterSchema, FilterOption } from '../table-filter.type';
|
|
2
2
|
import { FilterDisplayItem } from './selected-filters-display.type';
|
|
3
3
|
export declare const formatFilterValue: (value: string | string[]) => string;
|
|
4
4
|
export declare const getFilterCount: (filterRule: FilterRule, filterOptions?: FilterOption[]) => number | undefined;
|
|
5
|
-
export declare const createFilterDisplayItems: (selectedFilters: FilterRule[], schema:
|
|
5
|
+
export declare const createFilterDisplayItems: (selectedFilters: FilterRule[], schema: FilterSchema) => FilterDisplayItem[];
|
|
6
6
|
export declare const calculateTotalCount: (filterDisplayItems: FilterDisplayItem[]) => number;
|
package/dist/components/table-filter/selected-filters-display/selected-filters-display.utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const c = (n, o) => {
|
|
2
|
+
if (!o || o.length === 0) return n.value !== "" ? 1 : 0;
|
|
3
|
+
if (Array.isArray(n.value)) {
|
|
4
|
+
const t = o.filter(
|
|
5
|
+
(r) => n.value.includes(r.value)
|
|
6
|
+
).reduce((r, a) => r + (a.total || 0), 0);
|
|
7
|
+
return t > 0 ? t : void 0;
|
|
8
|
+
} else {
|
|
9
|
+
const e = o.find((t) => t.value === n.value);
|
|
10
|
+
return e == null ? void 0 : e.total;
|
|
11
|
+
}
|
|
12
|
+
}, s = (n, o) => n.filter((e) => Array.isArray(e.value) ? e.value.length > 0 : e.value !== "").map((e) => {
|
|
13
|
+
const t = o.find((u) => u.filterKey === e.field), r = t != null && t.options ? Object.entries(t.options).map(([u, l]) => ({
|
|
14
|
+
label: u,
|
|
15
|
+
value: u,
|
|
16
|
+
total: l
|
|
17
|
+
})) : void 0, a = c(e, r);
|
|
18
|
+
return {
|
|
19
|
+
field: e.field,
|
|
20
|
+
fieldTitle: (t == null ? void 0 : t.title) || e.field,
|
|
21
|
+
value: e.value,
|
|
22
|
+
condition: e.condition,
|
|
23
|
+
count: a
|
|
24
|
+
};
|
|
25
|
+
}), d = (n) => n.reduce((o, e) => o + (e.count || 1), 0);
|
|
26
|
+
export {
|
|
27
|
+
d as calculateTotalCount,
|
|
28
|
+
s as createFilterDisplayItems,
|
|
29
|
+
c as getFilterCount
|
|
30
|
+
};
|
package/dist/components/{table/components/table-filter → table-filter}/table-filter-button.js
RENAMED
|
@@ -1,111 +1,115 @@
|
|
|
1
1
|
import { jsxs as l, jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import * as
|
|
3
|
-
import { Button as
|
|
4
|
-
import { useTableFilterContext as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { SelectedFiltersDisplay as
|
|
11
|
-
import { useClickOutside as
|
|
12
|
-
import { createFilterDisplayItems as
|
|
13
|
-
import { FilterConfirmationDialog as
|
|
14
|
-
import { hasUnsavedFilterChanges as
|
|
15
|
-
const
|
|
16
|
-
const [
|
|
2
|
+
import * as u from "react";
|
|
3
|
+
import { Button as x } from "../button/button.js";
|
|
4
|
+
import { useTableFilterContext as I } from "./table-filter.context.js";
|
|
5
|
+
import P from "./filters/text.js";
|
|
6
|
+
import U from "./filters/boolean.js";
|
|
7
|
+
import V from "./filters/number/number.js";
|
|
8
|
+
import q from "./filters/checkbox.js";
|
|
9
|
+
import E from "../assets/icons/circle-check-filled.js";
|
|
10
|
+
import { SelectedFiltersDisplay as G } from "./selected-filters-display/selected-filters-display.js";
|
|
11
|
+
import { useClickOutside as H } from "../../hooks/useClickOutside.js";
|
|
12
|
+
import { createFilterDisplayItems as J, calculateTotalCount as L } from "./selected-filters-display/selected-filters-display.utils.js";
|
|
13
|
+
import { FilterConfirmationDialog as M } from "./close-filter-confirm/filter-confirmation-dialog.js";
|
|
14
|
+
import { hasUnsavedFilterChanges as C } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
|
|
15
|
+
const ne = () => {
|
|
16
|
+
const [m, a] = u.useState(!1), [F, n] = u.useState(!1), g = u.useRef(null), {
|
|
17
17
|
selectedColumn: r,
|
|
18
|
-
setSelectedColumn:
|
|
18
|
+
setSelectedColumn: N,
|
|
19
19
|
getFilterForColumn: k,
|
|
20
|
-
hasFilterForColumn:
|
|
21
|
-
updateColumnFilter:
|
|
22
|
-
clearAllFilters:
|
|
20
|
+
hasFilterForColumn: w,
|
|
21
|
+
updateColumnFilter: K,
|
|
22
|
+
clearAllFilters: j,
|
|
23
23
|
resetToAppliedFilters: A,
|
|
24
24
|
applyFilters: D,
|
|
25
|
-
hasActiveFilters:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
y(n, d.value) && i ? a(!0) : o(!1);
|
|
25
|
+
hasActiveFilters: d,
|
|
26
|
+
tempFilters: i,
|
|
27
|
+
filterSchema: c,
|
|
28
|
+
filter: p,
|
|
29
|
+
filterComponents: f = {}
|
|
30
|
+
} = I();
|
|
31
|
+
H(g, () => {
|
|
32
|
+
C(i, p.value) && m ? n(!0) : a(!1);
|
|
34
33
|
});
|
|
35
34
|
const v = () => {
|
|
36
|
-
D(),
|
|
35
|
+
D(), a(!1);
|
|
37
36
|
}, S = () => {
|
|
38
|
-
|
|
37
|
+
n(!1), a(!1);
|
|
39
38
|
}, O = () => {
|
|
40
|
-
A(),
|
|
39
|
+
A(), n(!1), a(!1);
|
|
41
40
|
}, R = () => {
|
|
42
|
-
|
|
43
|
-
},
|
|
41
|
+
n(!1);
|
|
42
|
+
}, T = J(i, c), b = L(T), $ = () => {
|
|
44
43
|
if (!r) return null;
|
|
45
|
-
const e =
|
|
46
|
-
boolean:
|
|
47
|
-
|
|
48
|
-
number:
|
|
49
|
-
checkbox:
|
|
50
|
-
},
|
|
51
|
-
if (!
|
|
44
|
+
const e = c.find((o) => o.filterKey === r), z = {
|
|
45
|
+
boolean: U,
|
|
46
|
+
string: P,
|
|
47
|
+
number: V,
|
|
48
|
+
checkbox: q
|
|
49
|
+
}, y = (e == null ? void 0 : e.type) && (f == null ? void 0 : f[e.type]) || z[(e == null ? void 0 : e.type) ?? "string"];
|
|
50
|
+
if (!y)
|
|
52
51
|
return console.warn(
|
|
53
|
-
`No filter component found for column "${e == null ? void 0 : e.
|
|
52
|
+
`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".`
|
|
54
53
|
), null;
|
|
55
|
-
const s = k(r),
|
|
54
|
+
const s = k(r), B = {
|
|
56
55
|
condition: (s == null ? void 0 : s.condition) || "",
|
|
57
56
|
value: (s == null ? void 0 : s.value) || ""
|
|
58
57
|
};
|
|
59
58
|
return /* @__PURE__ */ t("div", { className: "flex-1", children: /* @__PURE__ */ t("div", { className: "mb-4", children: /* @__PURE__ */ t("div", { className: "", children: /* @__PURE__ */ t(
|
|
60
|
-
|
|
59
|
+
y,
|
|
61
60
|
{
|
|
62
|
-
value:
|
|
63
|
-
onChange: ({ condition:
|
|
64
|
-
filterOptions: e
|
|
65
|
-
|
|
61
|
+
value: B,
|
|
62
|
+
onChange: ({ condition: o, value: h }) => K(r, o, h),
|
|
63
|
+
filterOptions: e != null && e.options ? Object.entries(e.options).map(([o, h]) => ({
|
|
64
|
+
label: o,
|
|
65
|
+
value: o,
|
|
66
|
+
total: h
|
|
67
|
+
})) : void 0
|
|
68
|
+
},
|
|
69
|
+
r
|
|
66
70
|
) }) }) });
|
|
67
71
|
};
|
|
68
|
-
return /* @__PURE__ */ l("div", { className: "relative", ref:
|
|
72
|
+
return /* @__PURE__ */ l("div", { className: "relative", ref: g, children: [
|
|
69
73
|
/* @__PURE__ */ l(
|
|
70
|
-
|
|
74
|
+
x,
|
|
71
75
|
{
|
|
72
76
|
onClick: (e) => {
|
|
73
|
-
e.stopPropagation(),
|
|
77
|
+
e.stopPropagation(), a(!m);
|
|
74
78
|
},
|
|
75
|
-
variant:
|
|
76
|
-
shade:
|
|
79
|
+
variant: d ? "filled" : "stroke",
|
|
80
|
+
shade: d ? "brand" : "neutral",
|
|
77
81
|
size: "small",
|
|
78
82
|
children: [
|
|
79
83
|
"Filter ",
|
|
80
|
-
|
|
84
|
+
d && `(${p.value.length})`
|
|
81
85
|
]
|
|
82
86
|
}
|
|
83
87
|
),
|
|
84
|
-
|
|
88
|
+
m && /* @__PURE__ */ l("div", { className: "absolute top-full left-0 mt-2 w-[512px] bg-surface-neutral-default border border-stroke-solid-light rounded-2xl z-10 overflow-hidden shadow-lg", children: [
|
|
85
89
|
/* @__PURE__ */ l("div", { className: "flex min-h-[442px]", children: [
|
|
86
90
|
/* @__PURE__ */ l("div", { className: "w-48 border-r border-stroke-solid-light p-2 flex flex-col gap-1.5", children: [
|
|
87
91
|
/* @__PURE__ */ t("div", { className: "p-2 pb-1", children: /* @__PURE__ */ t("h3", { className: "leading-none-medium-sm text-text-neutral-secondary", children: "Filters" }) }),
|
|
88
|
-
|
|
92
|
+
c.map((e) => /* @__PURE__ */ l(
|
|
89
93
|
"button",
|
|
90
94
|
{
|
|
91
|
-
onClick: () =>
|
|
92
|
-
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.
|
|
95
|
+
onClick: () => N(e.filterKey),
|
|
96
|
+
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"}`,
|
|
93
97
|
children: [
|
|
94
98
|
/* @__PURE__ */ t("span", { className: "truncate", children: e.title }),
|
|
95
|
-
|
|
99
|
+
w(e.filterKey) && /* @__PURE__ */ t(E, { className: "w-4 h-4 text-text-brand-secondary flex-shrink-0 ml-2" })
|
|
96
100
|
]
|
|
97
101
|
},
|
|
98
|
-
e.
|
|
102
|
+
e.filterKey
|
|
99
103
|
))
|
|
100
104
|
] }),
|
|
101
|
-
/* @__PURE__ */ t("div", { className: "flex-1 flex flex-col", children: r ?
|
|
105
|
+
/* @__PURE__ */ t("div", { className: "flex-1 flex flex-col", children: r ? $() : /* @__PURE__ */ t("div", { className: "flex-1 flex items-center justify-center text-text-neutral-muted", children: "Select a column to configure its filter" }) })
|
|
102
106
|
] }),
|
|
103
107
|
!!b && /* @__PURE__ */ l("div", { className: "flex justify-between items-end p-4 border-t border-stroke-solid-medium min-h-[71px]", children: [
|
|
104
|
-
/* @__PURE__ */ t(
|
|
108
|
+
/* @__PURE__ */ t(G, { selectedFilters: i, schema: c }),
|
|
105
109
|
/* @__PURE__ */ l("div", { className: "flex justify-end gap-2", children: [
|
|
106
|
-
/* @__PURE__ */ t(
|
|
110
|
+
/* @__PURE__ */ t(x, { onClick: j, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
|
|
107
111
|
/* @__PURE__ */ t(
|
|
108
|
-
|
|
112
|
+
x,
|
|
109
113
|
{
|
|
110
114
|
onClick: v,
|
|
111
115
|
variant: "filled",
|
|
@@ -117,18 +121,18 @@ const ie = () => {
|
|
|
117
121
|
] })
|
|
118
122
|
] })
|
|
119
123
|
] }),
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
F && /* @__PURE__ */ t(
|
|
125
|
+
M,
|
|
122
126
|
{
|
|
123
127
|
onClose: R,
|
|
124
128
|
onKeepChanges: S,
|
|
125
129
|
onRevertChanges: O,
|
|
126
130
|
onApplyChanges: v,
|
|
127
|
-
hasUnsavedChanges:
|
|
131
|
+
hasUnsavedChanges: C(i, p.value)
|
|
128
132
|
}
|
|
129
133
|
)
|
|
130
134
|
] });
|
|
131
135
|
};
|
|
132
136
|
export {
|
|
133
|
-
|
|
137
|
+
ne as TableFilterButton
|
|
134
138
|
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsxs as i, jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import * as u from "react";
|
|
3
|
+
import { Button as h } from "../button/button.js";
|
|
4
|
+
import { useTableFilterContext as U } from "./table-filter.context.js";
|
|
5
|
+
import I from "./filters/text.js";
|
|
6
|
+
import P from "./filters/boolean.js";
|
|
7
|
+
import V from "./filters/number/number.js";
|
|
8
|
+
import q from "./filters/checkbox.js";
|
|
9
|
+
import E from "../assets/icons/circle-check-filled.js";
|
|
10
|
+
import { useClickOutside as G } from "../../hooks/useClickOutside.js";
|
|
11
|
+
import { getFilterCount as H } from "./selected-filters-display/selected-filters-display.utils.js";
|
|
12
|
+
import { FilterConfirmationDialog as J } from "./close-filter-confirm/filter-confirmation-dialog.js";
|
|
13
|
+
import { hasUnsavedFilterChangesForColumn as k } from "./close-filter-confirm/filter-confirmation-dialog.utils.js";
|
|
14
|
+
const le = ({ filterName: o }) => {
|
|
15
|
+
const [a, l] = u.useState(!1), [x, r] = u.useState(!1), C = u.useRef(null), {
|
|
16
|
+
getFilterForColumn: w,
|
|
17
|
+
hasAppliedFilterForColumn: A,
|
|
18
|
+
updateColumnFilter: g,
|
|
19
|
+
applyFilters: d,
|
|
20
|
+
resetToAppliedFilters: O,
|
|
21
|
+
filterSchema: R,
|
|
22
|
+
filterComponents: c = {},
|
|
23
|
+
tempFilters: F,
|
|
24
|
+
filter: v
|
|
25
|
+
} = U();
|
|
26
|
+
G(C, () => {
|
|
27
|
+
k(o, F, v.value) && a ? r(!0) : l(!1);
|
|
28
|
+
});
|
|
29
|
+
const $ = () => {
|
|
30
|
+
d(), l(!1);
|
|
31
|
+
}, j = () => {
|
|
32
|
+
r(!1), l(!1);
|
|
33
|
+
}, z = () => {
|
|
34
|
+
O(), r(!1), l(!1);
|
|
35
|
+
}, D = () => {
|
|
36
|
+
r(!1);
|
|
37
|
+
}, e = R.find((n) => n.filterKey === o);
|
|
38
|
+
if (!e)
|
|
39
|
+
return console.warn(`Column "${o}" not found in schema`), null;
|
|
40
|
+
const K = {
|
|
41
|
+
boolean: P,
|
|
42
|
+
string: I,
|
|
43
|
+
number: V,
|
|
44
|
+
checkbox: q
|
|
45
|
+
}, b = e.type && (c == null ? void 0 : c[e.type]) || K[e.type ?? "string"];
|
|
46
|
+
if (!b)
|
|
47
|
+
return console.warn(
|
|
48
|
+
`No filter component found for column "${e.filterKey}" with type "${e.type}". Provide a custom filter component or use supported types: "string", "number", "boolean", "checkbox".`
|
|
49
|
+
), null;
|
|
50
|
+
const t = w(o), p = A(o), y = e.options ? Object.entries(e.options).map(([n, f]) => ({
|
|
51
|
+
label: n,
|
|
52
|
+
value: n,
|
|
53
|
+
total: f
|
|
54
|
+
})) : void 0, m = t ? H(t, y) : void 0, S = {
|
|
55
|
+
condition: (t == null ? void 0 : t.condition) || "",
|
|
56
|
+
value: (t == null ? void 0 : t.value) || ""
|
|
57
|
+
}, T = () => {
|
|
58
|
+
g(o, "", ""), d(), l(!1);
|
|
59
|
+
}, B = () => {
|
|
60
|
+
d(), l(!1);
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ i("div", { className: "relative", ref: C, children: [
|
|
63
|
+
/* @__PURE__ */ s(
|
|
64
|
+
h,
|
|
65
|
+
{
|
|
66
|
+
onClick: () => {
|
|
67
|
+
l(!a);
|
|
68
|
+
},
|
|
69
|
+
variant: p ? "filled" : "stroke",
|
|
70
|
+
shade: p ? "brand" : "neutral",
|
|
71
|
+
size: "small",
|
|
72
|
+
children: /* @__PURE__ */ i("span", { className: "flex items-center gap-2", children: [
|
|
73
|
+
e.title,
|
|
74
|
+
p && /* @__PURE__ */ s(E, { className: "w-4 h-4 text-white flex-shrink-0" })
|
|
75
|
+
] })
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
a && /* @__PURE__ */ i("div", { className: "absolute top-full left-0 mt-2 w-80 bg-surface-neutral-default border border-stroke-solid-light rounded-2xl z-10 overflow-hidden shadow-lg", children: [
|
|
79
|
+
/* @__PURE__ */ s(
|
|
80
|
+
b,
|
|
81
|
+
{
|
|
82
|
+
value: S,
|
|
83
|
+
onChange: ({ condition: n, value: f }) => g(o, n, f),
|
|
84
|
+
filterOptions: y
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
!!m && /* @__PURE__ */ i("div", { className: "flex justify-between gap-2 p-3 border-t border-stroke-solid-medium", children: [
|
|
88
|
+
/* @__PURE__ */ s(h, { onClick: T, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
|
|
89
|
+
/* @__PURE__ */ s(h, { onClick: B, variant: "filled", shade: "neutral", size: "small", children: `Apply${m !== void 0 ? ` ${m}` : ""}` })
|
|
90
|
+
] })
|
|
91
|
+
] }),
|
|
92
|
+
x && /* @__PURE__ */ s(
|
|
93
|
+
J,
|
|
94
|
+
{
|
|
95
|
+
onClose: D,
|
|
96
|
+
onKeepChanges: j,
|
|
97
|
+
onRevertChanges: z,
|
|
98
|
+
onApplyChanges: $,
|
|
99
|
+
hasUnsavedChanges: k(
|
|
100
|
+
o,
|
|
101
|
+
F,
|
|
102
|
+
v.value
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
] });
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
le as TableFilterColumnButton
|
|
110
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import i from "./table-filter.hook.js";
|
|
3
|
+
import { TableFilterContext as a } from "./table-filter.context.js";
|
|
4
|
+
const v = ({
|
|
5
|
+
children: r,
|
|
6
|
+
filterComponents: t = {},
|
|
7
|
+
filterSchema: e,
|
|
8
|
+
filter: o
|
|
9
|
+
}) => {
|
|
10
|
+
const l = i({
|
|
11
|
+
filterSchema: e,
|
|
12
|
+
filter: o || { value: [], onChange: () => {
|
|
13
|
+
} }
|
|
14
|
+
});
|
|
15
|
+
if (!o)
|
|
16
|
+
return null;
|
|
17
|
+
const n = {
|
|
18
|
+
...l,
|
|
19
|
+
filterSchema: e,
|
|
20
|
+
filter: o,
|
|
21
|
+
filterComponents: t
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ u(a.Provider, { value: n, children: r });
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
v as TableFilterProvider
|
|
27
|
+
};
|
package/dist/components/{table/components/table-filter → table-filter}/table-filter.context.d.ts
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FilterComponentType } from './table-filter.type';
|
|
1
|
+
import { FilterRule, TableFilter as TableFilterType, FilterSchema, FilterComponentType } from './table-filter.type';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
export interface TableFilterContextValue {
|
|
5
4
|
selectedColumn: string | null;
|
|
@@ -12,9 +11,8 @@ export interface TableFilterContextValue {
|
|
|
12
11
|
resetToAppliedFilters: () => void;
|
|
13
12
|
applyFilters: () => void;
|
|
14
13
|
hasActiveFilters: boolean;
|
|
15
|
-
filterableFields: TableSchema;
|
|
16
14
|
tempFilters: FilterRule[];
|
|
17
|
-
|
|
15
|
+
filterSchema: FilterSchema;
|
|
18
16
|
filter: TableFilterType;
|
|
19
17
|
filterComponents?: Record<string, FilterComponentType>;
|
|
20
18
|
}
|
package/dist/components/{table/components/table-filter → table-filter}/table-filter.hook.d.ts
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { TableFilterProps } from './table-filter.type';
|
|
3
|
-
|
|
4
|
-
declare const useTableFilter: ({ filter, schema }: TableFilterProps) => {
|
|
2
|
+
import { TableFilterProps, FilterRule } from './table-filter.type';
|
|
3
|
+
declare const useTableFilter: ({ filter, filterSchema }: TableFilterProps) => {
|
|
5
4
|
selectedColumn: string | null;
|
|
6
5
|
setSelectedColumn: React.Dispatch<React.SetStateAction<string | null>>;
|
|
7
6
|
getFilterForColumn: (columnKey: string) => FilterRule | undefined;
|
|
@@ -13,6 +12,5 @@ declare const useTableFilter: ({ filter, schema }: TableFilterProps) => {
|
|
|
13
12
|
applyFilters: () => void;
|
|
14
13
|
hasActiveFilters: boolean;
|
|
15
14
|
tempFilters: FilterRule[];
|
|
16
|
-
filterableFields: import('../../table.type').TableSchemaColumn[];
|
|
17
15
|
};
|
|
18
16
|
export default useTableFilter;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import u from "react";
|
|
2
|
-
const
|
|
3
|
-
const [i,
|
|
2
|
+
const E = ({ filter: l, filterSchema: a }) => {
|
|
3
|
+
const [i, c] = u.useState(null), [r, s] = u.useState(l.value);
|
|
4
4
|
u.useEffect(() => {
|
|
5
|
-
!i && a.length > 0 &&
|
|
5
|
+
!i && a.length > 0 && c(a[0].filterKey);
|
|
6
6
|
}, [i, a]);
|
|
7
|
-
const
|
|
8
|
-
const e =
|
|
7
|
+
const d = (t) => r.find((e) => e.field === t), F = (t) => {
|
|
8
|
+
const e = d(t);
|
|
9
9
|
return e ? Array.isArray(e.value) ? e.value.length > 0 : e.value !== "" : !1;
|
|
10
|
-
},
|
|
11
|
-
const e =
|
|
10
|
+
}, p = (t) => l.value.find((e) => e.field === t), A = (t) => {
|
|
11
|
+
const e = p(t);
|
|
12
12
|
return e ? Array.isArray(e.value) ? e.value.length > 0 : e.value !== "" : !1;
|
|
13
13
|
}, g = (t, e, o) => {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
14
|
+
const f = r.findIndex((n) => n.field === t);
|
|
15
|
+
if (f >= 0) {
|
|
16
16
|
const n = r.map(
|
|
17
|
-
(
|
|
18
|
-
...
|
|
17
|
+
(v, x) => x === f ? {
|
|
18
|
+
...v,
|
|
19
19
|
...e !== void 0 ? { condition: e } : {},
|
|
20
20
|
...o !== void 0 ? { value: o } : {}
|
|
21
|
-
} :
|
|
21
|
+
} : v
|
|
22
22
|
);
|
|
23
23
|
s(n);
|
|
24
24
|
} else {
|
|
@@ -29,31 +29,30 @@ const T = ({ filter: l, schema: v }) => {
|
|
|
29
29
|
};
|
|
30
30
|
s([...r, n]);
|
|
31
31
|
}
|
|
32
|
-
},
|
|
32
|
+
}, m = () => {
|
|
33
33
|
s([]);
|
|
34
34
|
}, C = () => {
|
|
35
35
|
s(l.value);
|
|
36
|
-
},
|
|
36
|
+
}, h = () => {
|
|
37
37
|
const t = r.filter((e) => Array.isArray(e.value) ? e.value.length > 0 : e.value !== "");
|
|
38
38
|
l.onChange(t);
|
|
39
|
-
},
|
|
39
|
+
}, y = l.value.length > 0;
|
|
40
40
|
return u.useEffect(() => {
|
|
41
41
|
s(l.value);
|
|
42
42
|
}, [l.value]), {
|
|
43
43
|
selectedColumn: i,
|
|
44
|
-
setSelectedColumn:
|
|
45
|
-
getFilterForColumn:
|
|
46
|
-
hasFilterForColumn:
|
|
44
|
+
setSelectedColumn: c,
|
|
45
|
+
getFilterForColumn: d,
|
|
46
|
+
hasFilterForColumn: F,
|
|
47
47
|
hasAppliedFilterForColumn: A,
|
|
48
48
|
updateColumnFilter: g,
|
|
49
|
-
clearAllFilters:
|
|
49
|
+
clearAllFilters: m,
|
|
50
50
|
resetToAppliedFilters: C,
|
|
51
|
-
applyFilters:
|
|
52
|
-
hasActiveFilters:
|
|
53
|
-
tempFilters: r
|
|
54
|
-
filterableFields: a
|
|
51
|
+
applyFilters: h,
|
|
52
|
+
hasActiveFilters: y,
|
|
53
|
+
tempFilters: r
|
|
55
54
|
};
|
|
56
55
|
};
|
|
57
56
|
export {
|
|
58
|
-
|
|
57
|
+
E as default
|
|
59
58
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
export type FilterCondition = 'contains' | 'notEqual' | 'equal' | '>' | '<' | '=' | '!=';
|
|
3
|
+
export type FilterRule = {
|
|
4
|
+
field: string;
|
|
5
|
+
condition?: string;
|
|
6
|
+
value: string | string[];
|
|
7
|
+
};
|
|
8
|
+
export type FilterOption = {
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
total?: number;
|
|
12
|
+
};
|
|
13
|
+
export type FilterFieldType = 'string' | 'number' | 'boolean' | 'checkbox';
|
|
14
|
+
export type FilterSchemaField = {
|
|
15
|
+
filterKey: string;
|
|
16
|
+
title: string;
|
|
17
|
+
type: FilterFieldType;
|
|
18
|
+
options?: Record<string, number>;
|
|
19
|
+
};
|
|
20
|
+
export type FilterSchema = FilterSchemaField[];
|
|
21
|
+
export type TableFilter = {
|
|
22
|
+
value: FilterRule[];
|
|
23
|
+
onChange: (filters: FilterRule[]) => void;
|
|
24
|
+
};
|
|
25
|
+
export interface TableFilterProps {
|
|
26
|
+
filterSchema: FilterSchema;
|
|
27
|
+
filter: TableFilter;
|
|
28
|
+
filterComponents?: Record<string, FilterComponentType>;
|
|
29
|
+
}
|
|
30
|
+
export type FilterComponentProps = {
|
|
31
|
+
onChange: (input: {
|
|
32
|
+
condition?: string;
|
|
33
|
+
value?: string | string[];
|
|
34
|
+
}) => void;
|
|
35
|
+
value: {
|
|
36
|
+
condition?: string;
|
|
37
|
+
value: string | string[];
|
|
38
|
+
};
|
|
39
|
+
filterOptions?: FilterOption[];
|
|
40
|
+
};
|
|
41
|
+
export interface TableFilterProviderProps extends TableFilterProps {
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
export type FilterComponentType = FC<FilterComponentProps>;
|
package/dist/routes/table.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { TableSchema } from '../components/table';
|
|
2
|
+
import { FilterSchema } from '../components/table-filter/table-filter.type';
|
|
3
|
+
export declare const createFilterSchemaFromTableSchema: (tableSchema: TableSchema) => FilterSchema;
|
|
1
4
|
declare const TablePage: () => import("react/jsx-runtime").JSX.Element;
|
|
2
5
|
export default TablePage;
|
|
@@ -8,5 +8,6 @@ export interface ColumnReOrderProps {
|
|
|
8
8
|
columns: ColumnType[];
|
|
9
9
|
onReorder?: (reorderedColumns: ColumnType[]) => void;
|
|
10
10
|
onRemove?: (columnId: string) => void;
|
|
11
|
+
renderAction?: (column: ColumnType, onRemove: ((columnId: string) => void) | undefined) => React.ReactNode;
|
|
11
12
|
className?: string;
|
|
12
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Table as default, Table, TableProvider } from './table-provider';
|
|
2
2
|
export { TableBody } from './table';
|
|
3
|
-
export type { TableProps, TableSchema, TableSchemaColumn, CellType, CellValue, CellRenderer, CellRendererProps,
|
|
3
|
+
export type { TableProps, TableSchema, TableSchemaColumn, CellType, CellValue, CellRenderer, CellRendererProps, TablePaginationConfig, SortDirection, SortColumn, TableSort, } from './table.type';
|
|
4
4
|
export { extractCellValue } from './table.utils';
|
|
5
5
|
export { DEFAULT_EMPTY_MESSAGE, TABLE_CSS_CLASSES } from './table.const';
|
|
6
6
|
export { TableContext, useTableContext } from './table.context';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { TableProps } from './table.type';
|
|
3
3
|
import { TableBody } from './table';
|
|
4
|
-
import { TableFilter } from './components/table-filter/table-filter-provider';
|
|
5
4
|
import { TableSearch } from './components/table-search';
|
|
6
5
|
import { Pagination } from './components/pagination';
|
|
7
6
|
import { TableHeaderWrapper, TableHeaderContent, TableFooter, TableFooterContent } from './components';
|
|
@@ -12,7 +11,6 @@ export interface TableProviderProps extends TableProps {
|
|
|
12
11
|
declare const TableProvider: React.FC<TableProviderProps>;
|
|
13
12
|
interface TableCompoundComponent extends React.FC<TableProviderProps> {
|
|
14
13
|
Body: typeof TableBody;
|
|
15
|
-
Filter: typeof TableFilter;
|
|
16
14
|
Search: typeof TableSearch;
|
|
17
15
|
Pagination: typeof Pagination;
|
|
18
16
|
PaginationInfo: typeof PaginationInfo;
|