@konstructio/ui 0.1.2-alpha.70 → 0.1.2-alpha.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,90 +1,142 @@
1
- import { jsxs as m, jsx as a } from "react/jsx-runtime";
2
- import { d as R } from "../../../../debounce-DJveWHr_.js";
3
- import { useRef as v, useCallback as u, useMemo as p } from "react";
4
- import { Button as y } from "../../../Button/Button.js";
5
- import { Filter as l } from "../../../Filter/Filter.js";
6
- import { Input as B } from "../../../Input/Input.js";
7
- import { cn as N } from "../../../../utils/index.js";
8
- import { useTableContext as T } from "../../contexts/table.hook.js";
9
- const E = ({
10
- actions: f,
11
- multiSelectFilter: h,
12
- placeholder: d,
13
- showFilterInput: g = !0,
14
- showResetButton: C = !0,
15
- resetButtonClassName: S
1
+ import { jsxs as D, jsx as n } from "react/jsx-runtime";
2
+ import { d as N } from "../../../../debounce-DJveWHr_.js";
3
+ import { useRef as P, useMemo as m, useCallback as S } from "react";
4
+ import { Button as I } from "../../../Button/Button.js";
5
+ import { Filter as r } from "../../../Filter/Filter.js";
6
+ import { Input as $ } from "../../../Input/Input.js";
7
+ import { cn as q } from "../../../../utils/index.js";
8
+ import { useTableContext as z } from "../../contexts/table.hook.js";
9
+ const U = ({
10
+ actions: b,
11
+ filters: u,
12
+ multiSelectFilter: p,
13
+ placeholder: x,
14
+ showFilterInput: w = !0,
15
+ showResetButton: M = !0,
16
+ resetButtonClassName: v
16
17
  }) => {
17
- const o = v(null), {
18
- termOfSearch: s,
19
- multiselectSelected: c,
20
- onChangeTermOfSearch: n,
21
- onSelectMultiselect: i
22
- } = T(), x = u(
23
- (e, t) => i(
18
+ const c = P(null), {
19
+ termOfSearch: d,
20
+ multiselectSelected: i,
21
+ dateFilters: h,
22
+ dateRangeFilters: y,
23
+ onChangeTermOfSearch: s,
24
+ onSelectMultiselect: F,
25
+ onSelectDateFilter: j,
26
+ onSelectDateRangeFilter: O
27
+ } = z(), T = m(
28
+ () => u ?? p?.map((e) => ({
29
+ ...e,
30
+ type: "badgeMultiSelect"
31
+ })) ?? [],
32
+ [u, p]
33
+ ), R = S(
34
+ (e, t) => F(
24
35
  e,
25
- t.map((r) => r.id)
36
+ t.map((a) => a.id)
26
37
  ),
27
- [i]
28
- ), F = u(() => {
29
- n(""), o.current && (o.current.value = "");
30
- }, [n]), M = p(
31
- () => R((e) => {
32
- n(e.target.value);
38
+ [F]
39
+ ), g = S(() => {
40
+ s(""), c.current && (c.current.value = "");
41
+ }, [s]), B = m(
42
+ () => N((e) => {
43
+ s(e.target.value);
33
44
  }, 500),
34
- [n]
35
- ), b = p(
36
- () => !!s || Object.entries(c ?? {}).map(([, e]) => e).flat().length > 0,
37
- [s, c]
38
- );
39
- return /* @__PURE__ */ m("div", { className: "w-full flex items-center justify-end pb-6", children: [
40
- g && /* @__PURE__ */ a(
41
- B,
45
+ [s]
46
+ ), A = m(
47
+ () => !!d || Object.values(i ?? {}).flat().length > 0 || Object.values(h ?? {}).some(Boolean) || Object.values(y ?? {}).some(Boolean),
48
+ [d, i, h, y]
49
+ ), k = (e) => {
50
+ const { key: t, label: a, position: l = "right" } = e;
51
+ return e.type === "textMultiSelect" ? /* @__PURE__ */ n(
52
+ r.TextMultiSelect,
42
53
  {
43
- ref: o,
44
- placeholder: d,
54
+ label: a,
55
+ position: l,
56
+ options: e.options,
57
+ onApply: (o) => {
58
+ R(t, o);
59
+ }
60
+ },
61
+ t
62
+ ) : e.type === "date" ? /* @__PURE__ */ n(
63
+ r.DateFilterDropdown,
64
+ {
65
+ label: a,
66
+ position: l,
67
+ countryCode: e.countryCode,
68
+ onApply: (o) => {
69
+ j(t, o);
70
+ }
71
+ },
72
+ t
73
+ ) : e.type === "dateRange" ? /* @__PURE__ */ n(
74
+ r.DateRangeFilterDropdown,
75
+ {
76
+ label: a,
77
+ position: l,
78
+ showTime: e.showTime,
79
+ timeFormat: e.timeFormat,
80
+ showPresets: e.showPresets,
81
+ defaultRange: e.defaultRange,
82
+ minDate: e.minDate,
83
+ maxDate: e.maxDate,
84
+ countryCode: e.countryCode,
85
+ onApply: (o) => {
86
+ O(t, o);
87
+ },
88
+ onRangeChange: e.onRangeChange
89
+ },
90
+ t
91
+ ) : /* @__PURE__ */ n(
92
+ r.BadgeMultiSelect,
93
+ {
94
+ label: a,
95
+ position: l,
96
+ options: e.options,
97
+ onApply: (o) => {
98
+ R(t, o);
99
+ }
100
+ },
101
+ t
102
+ );
103
+ };
104
+ return /* @__PURE__ */ D("div", { className: "w-full flex items-center justify-end pb-6", children: [
105
+ w && /* @__PURE__ */ n(
106
+ $,
107
+ {
108
+ ref: c,
109
+ placeholder: x,
45
110
  isSearch: !0,
46
111
  autoComplete: "false",
47
112
  className: "w-72",
48
113
  inputMode: "search",
49
- onChange: M
114
+ onChange: B
50
115
  }
51
116
  ),
52
- /* @__PURE__ */ m(l, { children: [
53
- h?.map(
54
- ({ key: e, label: t, position: r = "right", options: j }) => /* @__PURE__ */ a(
55
- l.BadgeMultiSelect,
56
- {
57
- label: t,
58
- position: r,
59
- options: j,
60
- onApply: (O) => {
61
- x(e, O);
62
- }
63
- },
64
- t
65
- )
66
- ),
67
- f?.map(({ label: e, onClick: t, variant: r = "secondary" }) => /* @__PURE__ */ a(
68
- y,
117
+ /* @__PURE__ */ D(r, { children: [
118
+ T.map(k),
119
+ b?.map(({ label: e, onClick: t, variant: a = "secondary" }) => /* @__PURE__ */ n(
120
+ I,
69
121
  {
70
- variant: r,
122
+ variant: a,
71
123
  appearance: "compact",
72
124
  onClick: t,
73
125
  children: e
74
126
  },
75
127
  e
76
128
  )),
77
- C && /* @__PURE__ */ a(
78
- l.ResetButton,
129
+ M && /* @__PURE__ */ n(
130
+ r.ResetButton,
79
131
  {
80
- className: N("select-none", S),
81
- disabled: !b,
82
- onClick: F
132
+ className: q("select-none", v),
133
+ disabled: !A,
134
+ onClick: g
83
135
  }
84
136
  )
85
137
  ] })
86
138
  ] });
87
139
  };
88
140
  export {
89
- E as Filter
141
+ U as Filter
90
142
  };
@@ -1,5 +1,5 @@
1
1
  import { ButtonProps } from '../../../Button/Button.types';
2
- import { MultiSelectFilter } from '../../VirtualizedTable.types';
2
+ import { FilterConfig, MultiSelectFilter } from '../../VirtualizedTable.types';
3
3
  export type { Option } from '../../../Filter/Filter.types';
4
4
  export type FilterAction = {
5
5
  label: string;
@@ -8,6 +8,8 @@ export type FilterAction = {
8
8
  };
9
9
  export type Props = {
10
10
  actions?: FilterAction[];
11
+ filters?: FilterConfig[];
12
+ /** @deprecated Use `filters` instead */
11
13
  multiSelectFilter?: MultiSelectFilter[];
12
14
  placeholder: string;
13
15
  showFilterInput?: boolean;
@@ -11,6 +11,11 @@ export type ContextType<TData extends RowData = RowData> = {
11
11
  termOfSearch?: string;
12
12
  page: number;
13
13
  multiselectSelected?: Record<string, string[]>;
14
+ dateFilters?: Record<string, string | undefined>;
15
+ dateRangeFilters?: Record<string, {
16
+ from?: string;
17
+ to?: string;
18
+ } | undefined>;
14
19
  totalPages: number;
15
20
  isFirstLoad: boolean;
16
21
  enableExpandedRow?: boolean;
@@ -28,5 +33,10 @@ export type ContextType<TData extends RowData = RowData> = {
28
33
  onSorting: Dispatch<SetStateAction<SortingState>>;
29
34
  onChangeTermOfSearch: (term: string) => void;
30
35
  onSelectMultiselect: (key: string, selectedValues: string[]) => void;
36
+ onSelectDateFilter: (key: string, date?: Date) => void;
37
+ onSelectDateRangeFilter: (key: string, range?: {
38
+ from?: Date;
39
+ to?: Date;
40
+ }) => void;
31
41
  };
32
42
  export declare const TableContext: import('react').Context<ContextType<unknown>>;
@@ -20,6 +20,12 @@ const r = e({
20
20
  onSelectMultiselect() {
21
21
  throw new Error("onSelectMultiselect function is not implemented");
22
22
  },
23
+ onSelectDateFilter() {
24
+ throw new Error("onSelectDateFilter function is not implemented");
25
+ },
26
+ onSelectDateRangeFilter() {
27
+ throw new Error("onSelectDateRangeFilter function is not implemented");
28
+ },
23
29
  handlePage() {
24
30
  throw new Error("handlePage function is not implemented");
25
31
  },