@ztwoint/z-ui 0.1.45 → 0.1.46
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/components/pagination/index.d.ts +1 -0
- package/dist/components/table/components/pagination/pagination.hook.d.ts +1 -1
- package/dist/components/table/components/pagination/pagination.hook.js +20 -16
- package/dist/components/table/components/table-filter/filters/checkbox.js +35 -51
- package/dist/components/table/components/table-filter/filters/text.js +41 -39
- package/dist/components/table/components/table-filter/index.d.ts +4 -1
- package/dist/components/table/components/table-filter/selected-filters-display/index.d.ts +2 -0
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.d.ts +3 -0
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.js +30 -0
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +12 -0
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +6 -0
- package/dist/components/table/components/table-filter/selected-filters-display/selected-filters-display.utils.js +26 -0
- package/dist/components/table/components/table-filter/table-filter-button.d.ts +2 -0
- package/dist/components/table/components/table-filter/table-filter-button.js +103 -0
- package/dist/components/table/components/table-filter/table-filter-column-button.d.ts +3 -0
- package/dist/components/table/components/table-filter/table-filter-column-button.js +78 -0
- package/dist/components/table/components/table-filter/table-filter-column-button.type.d.ts +3 -0
- package/dist/components/table/components/table-filter/table-filter-provider.d.ts +14 -0
- package/dist/components/table/components/table-filter/table-filter-provider.js +32 -0
- package/dist/components/table/components/table-filter/table-filter.context.d.ts +21 -0
- package/dist/components/table/components/table-filter/table-filter.context.js +13 -0
- package/dist/components/table/components/table-filter/table-filter.hook.d.ts +1 -2
- package/dist/components/table/components/table-filter/table-filter.hook.js +39 -37
- package/dist/components/table/index.d.ts +1 -2
- package/dist/components/table/table-provider.d.ts +1 -1
- package/dist/components/table/table-provider.js +13 -13
- package/dist/components/table/table.type.d.ts +2 -0
- package/dist/components/table/table.utils.d.ts +0 -1
- package/dist/components/table/table.utils.js +5 -3
- package/dist/components/table-card/table-card.js +69 -64
- package/dist/components/table-card/table-card.type.d.ts +7 -7
- package/dist/css/styles/tailwind.css +1 -1
- package/dist/hooks/useClickOutside.d.ts +1 -0
- package/dist/hooks/useClickOutside.js +14 -0
- package/dist/index.js +107 -110
- package/dist/types/components/table/components/pagination/index.d.ts +1 -0
- package/dist/types/components/table/components/pagination/pagination.hook.d.ts +1 -1
- package/dist/types/components/table/components/table-filter/index.d.ts +4 -1
- package/dist/types/components/table/components/table-filter/selected-filters-display/index.d.ts +2 -0
- package/dist/types/components/table/components/table-filter/selected-filters-display/selected-filters-display.d.ts +3 -0
- package/dist/types/components/table/components/table-filter/selected-filters-display/selected-filters-display.type.d.ts +12 -0
- package/dist/types/components/table/components/table-filter/selected-filters-display/selected-filters-display.utils.d.ts +6 -0
- package/dist/types/components/table/components/table-filter/table-filter-button.d.ts +2 -0
- package/dist/types/components/table/components/table-filter/table-filter-column-button.d.ts +3 -0
- package/dist/types/components/table/components/table-filter/table-filter-column-button.type.d.ts +3 -0
- package/dist/types/components/table/components/table-filter/table-filter-provider.d.ts +14 -0
- package/dist/types/components/table/components/table-filter/table-filter.context.d.ts +21 -0
- package/dist/types/components/table/components/table-filter/table-filter.hook.d.ts +1 -2
- package/dist/types/components/table/index.d.ts +1 -2
- package/dist/types/components/table/table-provider.d.ts +1 -1
- package/dist/types/components/table/table.type.d.ts +2 -0
- package/dist/types/components/table/table.utils.d.ts +0 -1
- package/dist/types/components/table-card/table-card.type.d.ts +7 -7
- package/dist/types/hooks/useClickOutside.d.ts +1 -0
- package/package.json +2 -1
- package/dist/components/table/components/table-filter/table-filter.d.ts +0 -9
- package/dist/components/table/components/table-filter/table-filter.js +0 -120
- package/dist/types/components/table/components/table-filter/table-filter.d.ts +0 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Pagination, default } from './pagination';
|
|
2
|
+
export { PaginationInfo, PaginationQuickJumper } from './components';
|
|
2
3
|
export type { PaginationProps, PaginationInfoProps, PaginationQuickJumperProps, } from './pagination.type';
|
|
3
4
|
export { usePagination } from './pagination.hook';
|
|
4
5
|
export { usePaginationQuickJumper } from './components/pagination-quick-jumper.hook';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PaginationHookProps, PaginationHookReturn } from './pagination.type';
|
|
2
|
-
export declare const usePagination: (
|
|
2
|
+
export declare const usePagination: ({ currentPage, totalPage, maxVisiblePages, }: PaginationHookProps) => PaginationHookReturn & {
|
|
3
3
|
goToPage: (page: number) => boolean;
|
|
4
4
|
canGoToPage: (page: number) => boolean;
|
|
5
5
|
};
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
import { calculateVisiblePages as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { useMemo as u, useCallback as s } from "react";
|
|
2
|
+
import { calculateVisiblePages as a, isValidPageNumber as m } from "./pagination.utils.js";
|
|
3
|
+
const f = ({
|
|
4
|
+
currentPage: e,
|
|
5
|
+
totalPage: o,
|
|
6
|
+
maxVisiblePages: i
|
|
7
|
+
}) => {
|
|
8
|
+
const t = u(
|
|
9
|
+
() => a({ currentPage: e, totalPage: o, maxVisiblePages: i }),
|
|
10
|
+
[e, o, i]
|
|
11
|
+
), n = s(
|
|
12
|
+
(r) => m(r, o),
|
|
13
|
+
[o]
|
|
14
|
+
), c = s(
|
|
15
|
+
(r) => n(r),
|
|
16
|
+
[n]
|
|
13
17
|
);
|
|
14
18
|
return {
|
|
15
|
-
...
|
|
16
|
-
goToPage:
|
|
17
|
-
canGoToPage:
|
|
19
|
+
...t,
|
|
20
|
+
goToPage: c,
|
|
21
|
+
canGoToPage: n
|
|
18
22
|
};
|
|
19
23
|
};
|
|
20
24
|
export {
|
|
21
|
-
|
|
25
|
+
f as usePagination
|
|
22
26
|
};
|
|
@@ -1,74 +1,58 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { MagnifierIcon as
|
|
1
|
+
import { jsx as t, jsxs as s } from "react/jsx-runtime";
|
|
2
|
+
import { useState as i, useEffect as h } from "react";
|
|
3
|
+
import { MagnifierIcon as y } from "../../../../assets/icons/magnifier-icon.js";
|
|
4
4
|
import C from "../../../../assets/icons/x.js";
|
|
5
|
-
const
|
|
6
|
-
const [n,
|
|
5
|
+
const k = ["includesAny", "includesAll", "excludes"], j = ({ value: r, onChange: d, filterOptions: c = [] }) => {
|
|
6
|
+
const [n, o] = i([]), [u, m] = i(""), [x, f] = i(c), p = (e) => {
|
|
7
7
|
m(e.target.value);
|
|
8
|
-
const
|
|
9
|
-
(
|
|
8
|
+
const a = c.filter(
|
|
9
|
+
(l) => l.label.toLowerCase().includes(e.target.value.toLowerCase())
|
|
10
10
|
);
|
|
11
|
-
|
|
11
|
+
f(a);
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, []),
|
|
16
|
-
Array.isArray(
|
|
17
|
-
}, [
|
|
18
|
-
const v = (e,
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
m(""),
|
|
13
|
+
h(() => {
|
|
14
|
+
r.condition || d({ condition: k[0] });
|
|
15
|
+
}, []), h(() => {
|
|
16
|
+
Array.isArray(r.value) ? o(r.value.filter(Boolean)) : o([]);
|
|
17
|
+
}, [r.value]);
|
|
18
|
+
const v = (e, a) => {
|
|
19
|
+
let l;
|
|
20
|
+
a ? l = [...n, e] : l = n.filter((g) => g !== e), o(l), d({ value: l });
|
|
21
|
+
}, b = () => {
|
|
22
|
+
m(""), f(c);
|
|
23
23
|
}, N = (e) => n.includes(e);
|
|
24
|
-
return c.length === 0 ? /* @__PURE__ */ t("div", { className: "text-text-neutral-muted text-sm", children: "No filter options available for this column" }) : /* @__PURE__ */
|
|
25
|
-
/* @__PURE__ */
|
|
26
|
-
/* @__PURE__ */ t(
|
|
24
|
+
return c.length === 0 ? /* @__PURE__ */ t("div", { className: "text-text-neutral-muted text-sm", children: "No filter options available for this column" }) : /* @__PURE__ */ s("div", { className: "flex flex-col", children: [
|
|
25
|
+
/* @__PURE__ */ s("div", { className: "relative border-b border-stroke-solid-medium", children: [
|
|
26
|
+
/* @__PURE__ */ t(y, { className: "absolute left-3 top-3.5 text-text-neutral-muted" }),
|
|
27
27
|
/* @__PURE__ */ t(
|
|
28
28
|
"input",
|
|
29
29
|
{
|
|
30
30
|
placeholder: "Search options",
|
|
31
|
-
value:
|
|
32
|
-
onChange:
|
|
33
|
-
className: "border-none outline-none bg-surface-neutral-default text-text-neutral-primary rounded p-3 pl-
|
|
31
|
+
value: u,
|
|
32
|
+
onChange: p,
|
|
33
|
+
className: "border-none outline-none bg-surface-neutral-default text-text-neutral-primary rounded p-3 pl-8 leading-none-medium-sm w-full"
|
|
34
34
|
}
|
|
35
35
|
),
|
|
36
|
-
|
|
36
|
+
u && /* @__PURE__ */ t("span", { className: "absolute right-3 top-3.5", onClick: b, children: /* @__PURE__ */ t(C, {}) })
|
|
37
37
|
] }),
|
|
38
|
-
/* @__PURE__ */
|
|
39
|
-
/* @__PURE__ */
|
|
40
|
-
"select",
|
|
41
|
-
{
|
|
42
|
-
value: s.condition,
|
|
43
|
-
onChange: (e) => d({ condition: e.target.value }),
|
|
44
|
-
className: "border border-stroke-solid-medium bg-surface-neutral-default text-text-neutral-primary rounded px-2 py-1 text-sm mb-3",
|
|
45
|
-
children: h.map((e) => /* @__PURE__ */ r("option", { value: e, children: [
|
|
46
|
-
e === "includesAny" && "Includes any of",
|
|
47
|
-
e === "includesAll" && "Includes all of",
|
|
48
|
-
e === "excludes" && "Excludes"
|
|
49
|
-
] }, e))
|
|
50
|
-
}
|
|
51
|
-
),
|
|
52
|
-
/* @__PURE__ */ t("div", { className: "space-y-2 max-h-48 overflow-y-auto", children: p.map((e) => /* @__PURE__ */ r("label", { className: "flex items-center space-x-2 cursor-pointer", children: [
|
|
38
|
+
/* @__PURE__ */ t("div", { className: "flex flex-col p-3", children: /* @__PURE__ */ t("div", { className: "space-y-5 h-full overflow-y-auto", children: x.map((e) => /* @__PURE__ */ s("div", { className: "flex justify-between items-center", children: [
|
|
39
|
+
/* @__PURE__ */ s("label", { className: "flex items-center space-x-2 cursor-pointer", children: [
|
|
53
40
|
/* @__PURE__ */ t(
|
|
54
41
|
"input",
|
|
55
42
|
{
|
|
56
43
|
type: "checkbox",
|
|
57
44
|
checked: N(e.value),
|
|
58
|
-
onChange: (
|
|
59
|
-
className: "rounded border-stroke-solid-medium text-text-neutral-primary focus:ring-2 focus:ring-blue-500"
|
|
45
|
+
onChange: (a) => v(e.value, a.target.checked)
|
|
60
46
|
}
|
|
61
47
|
),
|
|
62
|
-
/* @__PURE__ */ t("span", { className: "text-text-neutral-primary
|
|
63
|
-
] }
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return (l == null ? void 0 : l.label) || e;
|
|
69
|
-
}).join(", ") })
|
|
48
|
+
/* @__PURE__ */ t("span", { className: "text-text-neutral-primary leading-none-medium-sm", children: e.label })
|
|
49
|
+
] }),
|
|
50
|
+
e.total && /* @__PURE__ */ s("span", { className: "text-text-neutral-muted text-sm", children: [
|
|
51
|
+
"[",
|
|
52
|
+
e.total,
|
|
53
|
+
"]"
|
|
70
54
|
] })
|
|
71
|
-
] })
|
|
55
|
+
] }, e.value)) }) })
|
|
72
56
|
] });
|
|
73
57
|
};
|
|
74
58
|
export {
|
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import
|
|
4
|
-
import { MagnifierIcon as
|
|
1
|
+
import { jsxs as l, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect as c } from "react";
|
|
3
|
+
import s from "../../../../assets/icons/x.js";
|
|
4
|
+
import { MagnifierIcon as u } from "../../../../assets/icons/magnifier-icon.js";
|
|
5
|
+
import { Input as d } from "../../../../input/input.js";
|
|
5
6
|
const o = [
|
|
6
7
|
{ label: "Contains", value: "contains" },
|
|
7
8
|
{ label: "Does not equal", value: "notEqual" },
|
|
8
9
|
{ label: "Equals", value: "equals" }
|
|
9
|
-
],
|
|
10
|
-
var
|
|
11
|
-
const
|
|
10
|
+
], h = ({ value: t, onChange: a }) => {
|
|
11
|
+
var i;
|
|
12
|
+
const n = () => {
|
|
12
13
|
a({ value: "" });
|
|
13
14
|
};
|
|
14
|
-
return
|
|
15
|
+
return c(() => {
|
|
15
16
|
t.condition || a({ condition: o[0].value });
|
|
16
|
-
}, []), /* @__PURE__ */
|
|
17
|
-
/* @__PURE__ */
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/* @__PURE__ */ l(
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
}, []), /* @__PURE__ */ l("div", { className: "flex flex-col gap-3", children: [
|
|
18
|
+
/* @__PURE__ */ e("div", { className: "p-4 relative", children: /* @__PURE__ */ e(
|
|
19
|
+
d,
|
|
20
|
+
{
|
|
21
|
+
leftIcon: /* @__PURE__ */ e(u, {}),
|
|
22
|
+
size: "large",
|
|
23
|
+
placeholder: "Search options",
|
|
24
|
+
value: t.value,
|
|
25
|
+
rightIcon: t.value ? /* @__PURE__ */ e(s, { onClick: n }) : null,
|
|
26
|
+
onChange: (r) => a({ value: r.target.value }),
|
|
27
|
+
className: ""
|
|
28
|
+
}
|
|
29
|
+
) }),
|
|
30
|
+
/* @__PURE__ */ e("div", { className: "flex flex-col gap-2 p-3", children: t.value && /* @__PURE__ */ l("div", { className: "flex items-center justify-center gap-2 px-3 py-2", children: [
|
|
31
|
+
/* @__PURE__ */ e("span", { className: "text-text-neutral-muted text-xs font-medium uppercase tracking-wide", children: (i = o.find((r) => r.value === t.condition)) == null ? void 0 : i.label }),
|
|
32
|
+
/* @__PURE__ */ l("div", { className: "flex items-center gap-1", children: [
|
|
33
|
+
/* @__PURE__ */ l("span", { className: "text-text-neutral-primary text-sm font-medium px-2 py-1 bg-surface-neutral-default rounded border border-stroke-solid-medium", children: [
|
|
34
|
+
"“",
|
|
35
|
+
t.value,
|
|
36
|
+
"”"
|
|
37
|
+
] }),
|
|
38
|
+
/* @__PURE__ */ e(
|
|
39
|
+
"button",
|
|
40
|
+
{
|
|
41
|
+
onClick: n,
|
|
42
|
+
className: "flex items-center justify-center w-5 h-5 rounded-full bg-surface-neutral-hovered hover:bg-surface-neutral-pressed transition-colors",
|
|
43
|
+
title: "Remove filter",
|
|
44
|
+
children: /* @__PURE__ */ e(s, { className: "w-3 h-3 text-text-neutral-muted" })
|
|
45
|
+
}
|
|
46
|
+
)
|
|
45
47
|
] })
|
|
46
|
-
] })
|
|
48
|
+
] }) })
|
|
47
49
|
] });
|
|
48
50
|
};
|
|
49
51
|
export {
|
|
50
|
-
|
|
52
|
+
h as default
|
|
51
53
|
};
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export { TableFilter } from './table-filter';
|
|
1
|
+
export { TableFilterProvider, TableFilter } from './table-filter-provider';
|
|
2
|
+
export { TableFilterButton } from './table-filter-button';
|
|
3
|
+
export { TableFilterColumnButton } from './table-filter-column-button';
|
|
4
|
+
export { useTableFilterContext } from './table-filter.context';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsxs as e, jsx as a, Fragment as i } from "react/jsx-runtime";
|
|
2
|
+
import * as m from "react";
|
|
3
|
+
import { createFilterDisplayItems as d, calculateTotalCount as o } from "./selected-filters-display.utils.js";
|
|
4
|
+
const u = ({
|
|
5
|
+
selectedFilters: r,
|
|
6
|
+
schema: s
|
|
7
|
+
}) => {
|
|
8
|
+
const l = d(r, s), n = o(l);
|
|
9
|
+
return /* @__PURE__ */ e("div", { className: "flex flex-col gap-2.5 max-w-md", children: [
|
|
10
|
+
n > 0 && /* @__PURE__ */ e("span", { className: "text-text-neutral-primary leading-none-medium-sm", children: [
|
|
11
|
+
n,
|
|
12
|
+
" total"
|
|
13
|
+
] }),
|
|
14
|
+
/* @__PURE__ */ a("div", { className: "flex flex-wrap items-center gap-2.5 max-w-md", children: l.map((t, c) => /* @__PURE__ */ e(m.Fragment, { children: [
|
|
15
|
+
/* @__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: [
|
|
16
|
+
t.fieldTitle,
|
|
17
|
+
" ",
|
|
18
|
+
t.count !== void 0 && /* @__PURE__ */ e(i, { children: [
|
|
19
|
+
"[",
|
|
20
|
+
/* @__PURE__ */ a("span", { className: "text-text-neutral-secondary", children: t.count }),
|
|
21
|
+
"]"
|
|
22
|
+
] })
|
|
23
|
+
] }) }),
|
|
24
|
+
c < l.length - 1 && /* @__PURE__ */ a("span", { className: "text-text-neutral-muted", children: "•" })
|
|
25
|
+
] }, t.field)) })
|
|
26
|
+
] });
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
u as SelectedFiltersDisplay
|
|
30
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FilterRule, TableSchema } from '../../../table.type';
|
|
2
|
+
export interface SelectedFilterDisplayProps {
|
|
3
|
+
selectedFilters: FilterRule[];
|
|
4
|
+
schema: TableSchema;
|
|
5
|
+
}
|
|
6
|
+
export interface FilterDisplayItem {
|
|
7
|
+
field: string;
|
|
8
|
+
fieldTitle: string;
|
|
9
|
+
value: string | string[];
|
|
10
|
+
condition?: string;
|
|
11
|
+
count?: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FilterRule, TableSchema, FilterOption } from '../../../table.type';
|
|
2
|
+
import { FilterDisplayItem } from './selected-filters-display.type';
|
|
3
|
+
export declare const formatFilterValue: (value: string | string[]) => string;
|
|
4
|
+
export declare const getFilterCount: (filterRule: FilterRule, filterOptions?: FilterOption[]) => number | undefined;
|
|
5
|
+
export declare const createFilterDisplayItems: (selectedFilters: FilterRule[], schema: TableSchema) => FilterDisplayItem[];
|
|
6
|
+
export declare const calculateTotalCount: (filterDisplayItems: FilterDisplayItem[]) => number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const a = (r, n) => {
|
|
2
|
+
if (!(!n || n.length === 0))
|
|
3
|
+
if (Array.isArray(r.value)) {
|
|
4
|
+
const t = n.filter(
|
|
5
|
+
(u) => r.value.includes(u.value)
|
|
6
|
+
).reduce((u, o) => u + (o.total || 0), 0);
|
|
7
|
+
return t > 0 ? t : void 0;
|
|
8
|
+
} else {
|
|
9
|
+
const e = n.find((t) => t.value === r.value);
|
|
10
|
+
return e == null ? void 0 : e.total;
|
|
11
|
+
}
|
|
12
|
+
}, l = (r, n) => r.filter((e) => Array.isArray(e.value) ? e.value.length > 0 : e.value !== "").map((e) => {
|
|
13
|
+
const t = n.find((o) => o.key === e.field), u = a(e, t == null ? void 0 : t.filterOptions);
|
|
14
|
+
return {
|
|
15
|
+
field: e.field,
|
|
16
|
+
fieldTitle: (t == null ? void 0 : t.title) || e.field,
|
|
17
|
+
value: e.value,
|
|
18
|
+
condition: e.condition,
|
|
19
|
+
count: u
|
|
20
|
+
};
|
|
21
|
+
}), c = (r) => r.reduce((n, e) => n + (e.count || 0), 0);
|
|
22
|
+
export {
|
|
23
|
+
c as calculateTotalCount,
|
|
24
|
+
l as createFilterDisplayItems,
|
|
25
|
+
a as getFilterCount
|
|
26
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsxs as l, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import * as f from "react";
|
|
3
|
+
import { Button as c } from "../../../button/button.js";
|
|
4
|
+
import { useTableFilterContext as O } from "./table-filter.context.js";
|
|
5
|
+
import z from "./filters/text.js";
|
|
6
|
+
import S from "./filters/boolean.js";
|
|
7
|
+
import $ from "./filters/number/number.js";
|
|
8
|
+
import B from "./filters/checkbox.js";
|
|
9
|
+
import R from "../../../assets/icons/circle-check-filled.js";
|
|
10
|
+
import { SelectedFiltersDisplay as P } from "./selected-filters-display/selected-filters-display.js";
|
|
11
|
+
import { useClickOutside as D } from "../../../../hooks/useClickOutside.js";
|
|
12
|
+
const Q = () => {
|
|
13
|
+
const [d, o] = f.useState(!1), m = f.useRef(null), {
|
|
14
|
+
selectedColumn: r,
|
|
15
|
+
setSelectedColumn: h,
|
|
16
|
+
getFilterForColumn: x,
|
|
17
|
+
hasFilterForColumn: b,
|
|
18
|
+
updateColumnFilter: v,
|
|
19
|
+
clearAllFilters: y,
|
|
20
|
+
applyFilters: F,
|
|
21
|
+
hasActiveFilters: i,
|
|
22
|
+
filterableFields: k,
|
|
23
|
+
tempFilters: N,
|
|
24
|
+
schema: p,
|
|
25
|
+
filter: g,
|
|
26
|
+
filterComponents: n = {}
|
|
27
|
+
} = O();
|
|
28
|
+
D(m, () => o(!1));
|
|
29
|
+
const w = () => {
|
|
30
|
+
F(), o(!1);
|
|
31
|
+
}, C = () => {
|
|
32
|
+
if (!r) return null;
|
|
33
|
+
const e = p.find((a) => a.key === r), T = {
|
|
34
|
+
boolean: S,
|
|
35
|
+
text: z,
|
|
36
|
+
number: $,
|
|
37
|
+
checkbox: B
|
|
38
|
+
}, u = (n == null ? void 0 : n[(e == null ? void 0 : e.cellType) || ""]) || T[(e == null ? void 0 : e.cellType) || "text"];
|
|
39
|
+
if (!u)
|
|
40
|
+
return console.warn(
|
|
41
|
+
`No filter component found for column "${e == null ? void 0 : e.key}" with cellType "${e == null ? void 0 : e.cellType}". Provide a custom filter component or use supported types: "text", "number", "boolean", "checkbox".`
|
|
42
|
+
), null;
|
|
43
|
+
const s = x(r), j = {
|
|
44
|
+
condition: (s == null ? void 0 : s.condition) || "",
|
|
45
|
+
value: (s == null ? void 0 : s.value) || ""
|
|
46
|
+
};
|
|
47
|
+
return /* @__PURE__ */ t("div", { className: "flex-1", children: /* @__PURE__ */ t("div", { className: "mb-4", children: /* @__PURE__ */ t("div", { className: "", children: /* @__PURE__ */ t(
|
|
48
|
+
u,
|
|
49
|
+
{
|
|
50
|
+
value: j,
|
|
51
|
+
onChange: ({ condition: a, value: A }) => v(r, a, A),
|
|
52
|
+
filterOptions: e == null ? void 0 : e.filterOptions
|
|
53
|
+
}
|
|
54
|
+
) }) }) });
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ l("div", { className: "relative", ref: m, children: [
|
|
57
|
+
/* @__PURE__ */ l(
|
|
58
|
+
c,
|
|
59
|
+
{
|
|
60
|
+
onClick: (e) => {
|
|
61
|
+
e.stopPropagation(), o(!d);
|
|
62
|
+
},
|
|
63
|
+
variant: i ? "filled" : "stroke",
|
|
64
|
+
shade: i ? "brand" : "neutral",
|
|
65
|
+
size: "small",
|
|
66
|
+
children: [
|
|
67
|
+
"Filter ",
|
|
68
|
+
i && `(${g.value.length})`
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
d && /* @__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: [
|
|
73
|
+
/* @__PURE__ */ l("div", { className: "flex min-h-[442px]", children: [
|
|
74
|
+
/* @__PURE__ */ l("div", { className: "w-48 border-r border-stroke-solid-light p-2 flex flex-col gap-1.5", children: [
|
|
75
|
+
/* @__PURE__ */ t("div", { className: "p-2 pb-1", children: /* @__PURE__ */ t("h3", { className: "leading-none-medium-sm text-text-neutral-secondary", children: "Filters" }) }),
|
|
76
|
+
k.map((e) => /* @__PURE__ */ l(
|
|
77
|
+
"button",
|
|
78
|
+
{
|
|
79
|
+
onClick: () => h(e.key),
|
|
80
|
+
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.key ? "bg-surface-neutral-focused text-text-brand-primary" : "text-text-neutral-primary"}`,
|
|
81
|
+
children: [
|
|
82
|
+
/* @__PURE__ */ t("span", { className: "truncate", children: e.title }),
|
|
83
|
+
b(e.key) && /* @__PURE__ */ t(R, { className: "w-4 h-4 text-text-brand-secondary flex-shrink-0 ml-2" })
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
e.key
|
|
87
|
+
))
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ t("div", { className: "flex-1 flex flex-col", children: r ? C() : /* @__PURE__ */ t("div", { className: "flex-1 flex items-center justify-center text-text-neutral-muted", children: "Select a column to configure its filter" }) })
|
|
90
|
+
] }),
|
|
91
|
+
/* @__PURE__ */ l("div", { className: "flex justify-between items-end p-4 border-t border-stroke-solid-medium", children: [
|
|
92
|
+
/* @__PURE__ */ t(P, { selectedFilters: N, schema: p }),
|
|
93
|
+
/* @__PURE__ */ l("div", { className: "flex justify-end gap-2", children: [
|
|
94
|
+
/* @__PURE__ */ t(c, { onClick: y, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
|
|
95
|
+
/* @__PURE__ */ t(c, { onClick: w, variant: "filled", shade: "neutral", size: "small", children: "Apply" })
|
|
96
|
+
] })
|
|
97
|
+
] })
|
|
98
|
+
] })
|
|
99
|
+
] });
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
Q as TableFilterButton
|
|
103
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsxs as r, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import * as h from "react";
|
|
3
|
+
import { Button as c } from "../../../button/button.js";
|
|
4
|
+
import { useTableFilterContext as g } from "./table-filter.context.js";
|
|
5
|
+
import T from "./filters/text.js";
|
|
6
|
+
import A from "./filters/boolean.js";
|
|
7
|
+
import O from "./filters/number/number.js";
|
|
8
|
+
import z from "./filters/checkbox.js";
|
|
9
|
+
import $ from "../../../assets/icons/circle-check-filled.js";
|
|
10
|
+
import { useClickOutside as j } from "../../../../hooks/useClickOutside.js";
|
|
11
|
+
const E = ({ filterName: l }) => {
|
|
12
|
+
const [d, n] = h.useState(!1), u = h.useRef(null);
|
|
13
|
+
j(u, () => n(!1));
|
|
14
|
+
const {
|
|
15
|
+
getFilterForColumn: b,
|
|
16
|
+
hasAppliedFilterForColumn: C,
|
|
17
|
+
updateColumnFilter: m,
|
|
18
|
+
applyFilters: p,
|
|
19
|
+
schema: x,
|
|
20
|
+
filterComponents: i = {}
|
|
21
|
+
} = g(), e = x.find((a) => a.key === l);
|
|
22
|
+
if (!e)
|
|
23
|
+
return console.warn(`Column "${l}" not found in schema`), null;
|
|
24
|
+
if (e.filterable === !1)
|
|
25
|
+
return console.warn(`Column "${l}" is not filterable`), null;
|
|
26
|
+
const k = {
|
|
27
|
+
boolean: A,
|
|
28
|
+
text: T,
|
|
29
|
+
number: O,
|
|
30
|
+
checkbox: z
|
|
31
|
+
}, f = (i == null ? void 0 : i[e.cellType || ""]) || k[e.cellType || "text"];
|
|
32
|
+
if (!f)
|
|
33
|
+
return console.warn(
|
|
34
|
+
`No filter component found for column "${e.key}" with cellType "${e.cellType}". Provide a custom filter component or use supported types: "text", "number", "boolean", "checkbox".`
|
|
35
|
+
), null;
|
|
36
|
+
const o = b(l), s = C(l), F = {
|
|
37
|
+
condition: (o == null ? void 0 : o.condition) || "",
|
|
38
|
+
value: (o == null ? void 0 : o.value) || ""
|
|
39
|
+
}, v = () => {
|
|
40
|
+
m(l, "", ""), p(), n(!1);
|
|
41
|
+
}, w = () => {
|
|
42
|
+
p(), n(!1);
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ r("div", { className: "relative", ref: u, children: [
|
|
45
|
+
/* @__PURE__ */ t(
|
|
46
|
+
c,
|
|
47
|
+
{
|
|
48
|
+
onClick: () => {
|
|
49
|
+
n(!d);
|
|
50
|
+
},
|
|
51
|
+
variant: s ? "filled" : "stroke",
|
|
52
|
+
shade: s ? "brand" : "neutral",
|
|
53
|
+
size: "small",
|
|
54
|
+
children: /* @__PURE__ */ r("span", { className: "flex items-center gap-2", children: [
|
|
55
|
+
e.title,
|
|
56
|
+
s && /* @__PURE__ */ t($, { className: "w-4 h-4 text-white flex-shrink-0" })
|
|
57
|
+
] })
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
d && /* @__PURE__ */ r("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: [
|
|
61
|
+
/* @__PURE__ */ t(
|
|
62
|
+
f,
|
|
63
|
+
{
|
|
64
|
+
value: F,
|
|
65
|
+
onChange: ({ condition: a, value: y }) => m(l, a, y),
|
|
66
|
+
filterOptions: e.filterOptions
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
/* @__PURE__ */ r("div", { className: "flex justify-between gap-2 p-3 border-t border-stroke-solid-medium", children: [
|
|
70
|
+
/* @__PURE__ */ t(c, { onClick: v, variant: "stroke", shade: "neutral", size: "small", children: "Clear All" }),
|
|
71
|
+
/* @__PURE__ */ t(c, { onClick: w, variant: "filled", shade: "neutral", size: "small", children: "Apply" })
|
|
72
|
+
] })
|
|
73
|
+
] })
|
|
74
|
+
] });
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
E as TableFilterColumnButton
|
|
78
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TableFilterProps } from './table-filter.type';
|
|
2
|
+
import { TableFilterButton } from './table-filter-button';
|
|
3
|
+
import { TableFilterColumnButton } from './table-filter-column-button';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
export interface TableFilterProviderProps extends TableFilterProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare const TableFilterProvider: React.FC<TableFilterProviderProps>;
|
|
9
|
+
interface TableFilterCompoundComponent extends React.FC<TableFilterProviderProps> {
|
|
10
|
+
FilterButton: typeof TableFilterButton;
|
|
11
|
+
FilterColumnButton: typeof TableFilterColumnButton;
|
|
12
|
+
}
|
|
13
|
+
export declare const TableFilter: TableFilterCompoundComponent;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import m from "./table-filter.hook.js";
|
|
3
|
+
import { TableFilterContext as a } from "./table-filter.context.js";
|
|
4
|
+
import { TableFilterButton as F } from "./table-filter-button.js";
|
|
5
|
+
import { TableFilterColumnButton as b } from "./table-filter-column-button.js";
|
|
6
|
+
const p = ({
|
|
7
|
+
children: e,
|
|
8
|
+
filterComponents: l = {},
|
|
9
|
+
schema: o,
|
|
10
|
+
filter: t
|
|
11
|
+
}) => {
|
|
12
|
+
const n = m({
|
|
13
|
+
schema: o,
|
|
14
|
+
filter: t || { value: [], onChange: () => {
|
|
15
|
+
} }
|
|
16
|
+
});
|
|
17
|
+
if (!t)
|
|
18
|
+
return null;
|
|
19
|
+
const i = {
|
|
20
|
+
...n,
|
|
21
|
+
schema: o,
|
|
22
|
+
filter: t,
|
|
23
|
+
filterComponents: l
|
|
24
|
+
};
|
|
25
|
+
return /* @__PURE__ */ u(a.Provider, { value: i, children: e });
|
|
26
|
+
}, r = p;
|
|
27
|
+
r.FilterButton = F;
|
|
28
|
+
r.FilterColumnButton = b;
|
|
29
|
+
export {
|
|
30
|
+
r as TableFilter,
|
|
31
|
+
p as TableFilterProvider
|
|
32
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TableSchema, TableFilter as TableFilterType, FilterRule } from '../../table.type';
|
|
2
|
+
import { FilterComponentType } from './table-filter.type';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export interface TableFilterContextValue {
|
|
5
|
+
selectedColumn: string | null;
|
|
6
|
+
setSelectedColumn: (column: string | null) => void;
|
|
7
|
+
getFilterForColumn: (columnKey: string) => FilterRule | undefined;
|
|
8
|
+
hasFilterForColumn: (columnKey: string) => boolean;
|
|
9
|
+
hasAppliedFilterForColumn: (columnKey: string) => boolean;
|
|
10
|
+
updateColumnFilter: (columnKey: string, condition?: string, value?: string | string[]) => void;
|
|
11
|
+
clearAllFilters: () => void;
|
|
12
|
+
applyFilters: () => void;
|
|
13
|
+
hasActiveFilters: boolean;
|
|
14
|
+
filterableFields: TableSchema;
|
|
15
|
+
tempFilters: FilterRule[];
|
|
16
|
+
schema: TableSchema;
|
|
17
|
+
filter: TableFilterType;
|
|
18
|
+
filterComponents?: Record<string, FilterComponentType>;
|
|
19
|
+
}
|
|
20
|
+
export declare const TableFilterContext: React.Context<TableFilterContextValue | undefined>;
|
|
21
|
+
export declare const useTableFilterContext: () => TableFilterContextValue;
|