@fluidattacks/design 10.2.0 → 10.3.1

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,275 +1,280 @@
1
- import { jsx as d, jsxs as p } from "react/jsx-runtime";
2
- import b from "../../../_virtual/dayjs.min.js";
3
- import { l as Q } from "../../../_virtual/lodash.js";
4
- import { forwardRef as U, useContext as Z, useMemo as ee, useCallback as C, Fragment as te } from "react";
1
+ import { jsx as u, jsxs as V } from "react/jsx-runtime";
2
+ import C from "../../../_virtual/dayjs.min.js";
3
+ import { l as Z } from "../../../_virtual/lodash.js";
4
+ import { forwardRef as ee, useContext as te, useMemo as se, useCallback as S, Fragment as le } from "react";
5
5
  import { useTheme as oe } from "styled-components";
6
- import { IncludeExcludeMenu as se } from "./include-exclude/index.js";
7
- import { Options as ne } from "./options/index.js";
8
- import { formatValue as M } from "./utils.js";
9
- import { FiltersContext as re } from "../context/index.js";
10
- import { StyledModalContainer as le, StyledFloatingActions as ce, StyledHeader as ae, StyledContent as ie, StyledActionButton as v } from "../styles.js";
11
- import { MAX_FILTERS_LENGTH as de } from "../utils.js";
12
- import { Container as j } from "../../container/index.js";
13
- import { Search as ue } from "../../search/index.js";
14
- import { Toggle as me } from "../../toggle/index.js";
6
+ import { IncludeExcludeMenu as ne } from "./include-exclude/index.js";
7
+ import { Options as re } from "./options/index.js";
8
+ import { formatValue as A } from "./utils.js";
9
+ import { FiltersContext as ce } from "../context/index.js";
10
+ import { StyledModalContainer as ae, StyledFloatingActions as ie, StyledHeader as de, StyledContent as ue, StyledActionButton as H } from "../styles.js";
11
+ import { MAX_FILTERS_LENGTH as me } from "../utils.js";
12
+ import { Container as F } from "../../container/index.js";
13
+ import { Search as fe } from "../../search/index.js";
14
+ import { Toggle as he } from "../../toggle/index.js";
15
15
  import "../../typography/heading/index.js";
16
16
  import "../../typography/span/index.js";
17
- import { Text as H } from "../../typography/text/index.js";
18
- import { parseCheckboxesFilterValue as S, formatCheckboxesFilterValue as A } from "../../../utils/filters.js";
19
- const Ie = U(function({ hideTitle: x = !1, label: V, options: m }, F) {
20
- const w = oe(), {
17
+ import { Text as Y } from "../../typography/text/index.js";
18
+ import { parseCheckboxesFilterValue as y, formatCheckboxesFilterValue as I } from "../../../utils/filters.js";
19
+ const z = (p) => p.type === "combobox" || p.type === "multiSelect", xe = (p, f) => {
20
+ const g = new Set(
21
+ (f ?? []).filter((a) => a.type === "list" || a.type === "combobox").flatMap((a) => (a.items ?? []).map((k) => k.value))
22
+ );
23
+ return p.filter((a) => !g.has(a));
24
+ }, Oe = ee(function({ hideTitle: f = !1, label: g, options: a }, k) {
25
+ const R = oe(), {
21
26
  id: t,
22
- searchValues: { searchFilter: h },
23
- setSearchValues: I,
24
- values: Y,
25
- setValues: f,
26
- scrollState: z
27
- } = Z(re), { ref: B } = z, g = Y[t], k = (m ?? []).some(
28
- (e) => e.type !== "combobox" && (e.items ?? []).length > de
29
- ), L = m?.find(
27
+ searchValues: { searchFilter: x },
28
+ setSearchValues: L,
29
+ values: B,
30
+ setValues: h,
31
+ scrollState: D
32
+ } = te(ce), { ref: T } = D, b = B[t], $ = (a ?? []).some(
33
+ (e) => !z(e) && (e.items ?? []).length > me
34
+ ), O = a?.find(
30
35
  (e) => e.type === "includeExclude"
31
- ), y = m?.find(
36
+ ), M = a?.find(
32
37
  (e) => e.type === "checkboxes" && e.excludeLabel
33
- ), { mode: D, values: T } = S(g ?? ""), W = D === "exclude", _ = T.length > 0, N = !x || k || y !== void 0, $ = ee(() => m?.map((e) => {
38
+ ), { mode: W, values: _ } = y(b ?? ""), G = W === "exclude", X = _.length > 0, v = !f || $ || M !== void 0, w = se(() => a?.map((e) => {
34
39
  const s = e?.items ?? [];
35
- return e.type === "combobox" ? s : s.filter(
36
- (u) => u.label?.toLowerCase().includes(h.toLowerCase()) ?? !1
40
+ return z(e) ? s : s.filter(
41
+ (m) => m.label?.toLowerCase().includes(x.toLowerCase()) ?? !1
37
42
  );
38
- }) ?? [], [m, h]), G = C(() => {
39
- f((e) => ({ ...e, [t]: "" }));
40
- }, [f, t]), X = C(() => {
41
- f((e) => {
42
- const { mode: s, values: u } = S(
43
+ }) ?? [], [a, x]), q = S(() => {
44
+ h((e) => ({ ...e, [t]: "" }));
45
+ }, [h, t]), J = S(() => {
46
+ h((e) => {
47
+ const { mode: s, values: m } = y(
43
48
  e[t] ?? ""
44
- ), o = [
45
- ...u,
46
- ...$.flat().map((l) => l.value)
49
+ ), l = [
50
+ ...m,
51
+ ...w.flat().map((r) => r.value)
47
52
  ];
48
53
  return {
49
54
  ...e,
50
- [t]: A({ mode: s, values: o })
55
+ [t]: I({ mode: s, values: l })
51
56
  };
52
57
  });
53
- }, [f, t, $]), q = C(() => {
54
- f((e) => {
55
- const { mode: s, values: u } = S(
58
+ }, [h, t, w]), K = S(() => {
59
+ h((e) => {
60
+ const { mode: s, values: m } = y(
56
61
  e[t] ?? ""
57
62
  );
58
63
  return {
59
64
  ...e,
60
- [t]: A({
65
+ [t]: I({
61
66
  mode: s === "exclude" ? "include" : "exclude",
62
- values: u
67
+ values: m
63
68
  })
64
69
  };
65
70
  });
66
- }, [f, t]), J = C(
71
+ }, [h, t]), P = S(
67
72
  (e) => {
68
- I((s) => ({
73
+ L((s) => ({
69
74
  ...s,
70
75
  searchFilter: e.target.value
71
76
  }));
72
77
  },
73
- [I]
74
- ), K = C(
75
- (e, s, u) => {
76
- f((o) => {
77
- if (s === "checkboxes") {
78
- const { mode: l, values: r } = S(
79
- o[t] ?? ""
80
- ), c = r.includes(e) ? r.filter((n) => n !== e) : [...r, e];
78
+ [L]
79
+ ), Q = S(
80
+ (e, s, m) => {
81
+ h((l) => {
82
+ if (s === "checkboxes" || s === "multiSelect") {
83
+ const { mode: r, values: c } = y(
84
+ l[t] ?? ""
85
+ ), n = s === "multiSelect" ? xe(c, a) : c, o = n.includes(e) ? n.filter((d) => d !== e) : [...n, e];
81
86
  return {
82
- ...o,
83
- [t]: A({ mode: l, values: c })
87
+ ...l,
88
+ [t]: I({ mode: r, values: o })
84
89
  };
85
90
  }
86
91
  if (s === "dateRange") {
87
- const l = M(o[t] ?? ""), r = l.filter(
88
- (a) => a !== "-" && !RegExp(/^\d+\-\d+\-\d+$/).test(a.trim())
89
- ), c = l.filter(
90
- (a) => b(a).isValid() && b(a).isAfter(b("1903-01-01"))
91
- ), n = b(e, "YYYY-MM-DD", !0), i = ["-", "-"];
92
- return c.length === 2 ? (i[0] = c[0], i[1] = c[1]) : c.length === 1 && (n.isAfter(b(c[0])) ? (i[0] = c[0], i[1] = e) : (i[0] = e, i[1] = c[0])), i[u ?? 0] = e, { ...o, [t]: [...r, ...i].join(",") };
92
+ const r = A(l[t] ?? ""), c = r.filter(
93
+ (i) => i !== "-" && !RegExp(/^\d+\-\d+\-\d+$/).test(i.trim())
94
+ ), n = r.filter(
95
+ (i) => C(i).isValid() && C(i).isAfter(C("1903-01-01"))
96
+ ), o = C(e, "YYYY-MM-DD", !0), d = ["-", "-"];
97
+ return n.length === 2 ? (d[0] = n[0], d[1] = n[1]) : n.length === 1 && (o.isAfter(C(n[0])) ? (d[0] = n[0], d[1] = e) : (d[0] = e, d[1] = n[0])), d[m ?? 0] = e, { ...l, [t]: [...c, ...d].join(",") };
93
98
  }
94
99
  if (s === "numberRange") {
95
- const l = M(o[t] ?? ""), r = l.filter(
96
- (a) => a !== "-" && !RegExp(/^\d+$/).test(a.trim())
97
- ), c = l.filter(
98
- (a) => a === "-" || RegExp(/^\d+$/).test(a.trim())
99
- ), n = ["-", "-"];
100
- c.forEach((a, R) => {
101
- if (R >= 2) return;
102
- const E = a.trim();
103
- RegExp(/^\d+$/).test(E) ? n[R] = Number(E) : E === "-" && (n[R] = "-");
100
+ const r = A(l[t] ?? ""), c = r.filter(
101
+ (i) => i !== "-" && !RegExp(/^\d+$/).test(i.trim())
102
+ ), n = r.filter(
103
+ (i) => i === "-" || RegExp(/^\d+$/).test(i.trim())
104
+ ), o = ["-", "-"];
105
+ n.forEach((i, E) => {
106
+ if (E >= 2) return;
107
+ const j = i.trim();
108
+ RegExp(/^\d+$/).test(j) ? o[E] = Number(j) : j === "-" && (o[E] = "-");
104
109
  });
105
- const i = u ?? 0;
110
+ const d = m ?? 0;
106
111
  if (e === "" || e === void 0 || e === null)
107
- n[i] = "-";
112
+ o[d] = "-";
108
113
  else {
109
- const a = Number(e);
110
- n[i] = Q.isNaN(a) ? "-" : a;
114
+ const i = Number(e);
115
+ o[d] = Z.isNaN(i) ? "-" : i;
111
116
  }
112
- return n[0] === "-" && n[1] === "-" ? {
113
- ...o,
114
- [t]: r.length > 0 ? r.join(",") : ""
117
+ return o[0] === "-" && o[1] === "-" ? {
118
+ ...l,
119
+ [t]: c.length > 0 ? c.join(",") : ""
115
120
  } : {
116
- ...o,
117
- [t]: [...n, ...r].join(",")
121
+ ...l,
122
+ [t]: [...o, ...c].join(",")
118
123
  };
119
124
  }
120
125
  if (s === "combobox" || s === "list") {
121
- const l = M(o[t] ?? ""), r = new Set(
122
- (m ?? []).flatMap(
123
- (n) => (n.items ?? []).map((i) => i.value)
126
+ const r = A(l[t] ?? ""), c = new Set(
127
+ (a ?? []).flatMap(
128
+ (o) => (o.items ?? []).map((d) => d.value)
124
129
  )
125
- ), c = l.filter(
126
- (n) => !r.has(n.trim()) && (n === "-" || RegExp(/^\d+$/).test(n) || RegExp(/^\d+\-\d+\-\d+$/).test(n.trim()))
130
+ ), n = r.filter(
131
+ (o) => !c.has(o.trim()) && (o === "-" || RegExp(/^\d+$/).test(o) || RegExp(/^\d+\-\d+\-\d+$/).test(o.trim()))
127
132
  );
128
- return { ...o, [t]: [...c, e].join(",") };
133
+ return { ...l, [t]: [...n, e].join(",") };
129
134
  }
130
135
  if (s === "textCheckbox") {
131
- const l = o[t] ?? "", r = l.match(/^textCheck:(true|false),(.*)$/), c = r ? r[2] : l, n = e === "true";
132
- return !n && c === "" ? { ...o, [t]: "" } : { ...o, [t]: `textCheck:${n},${c}` };
136
+ const r = l[t] ?? "", c = r.match(/^textCheck:(true|false),(.*)$/), n = c ? c[2] : r, o = e === "true";
137
+ return !o && n === "" ? { ...l, [t]: "" } : { ...l, [t]: `textCheck:${o},${n}` };
133
138
  }
134
139
  if (s === "text") {
135
- const r = (o[t] ?? "").match(/^textCheck:(true|false),/);
136
- return r ? e === "" && r[1] === "false" ? { ...o, [t]: "" } : { ...o, [t]: `textCheck:${r[1]},${e}` } : { ...o, [t]: e };
140
+ const c = (l[t] ?? "").match(/^textCheck:(true|false),/);
141
+ return c ? e === "" && c[1] === "false" ? { ...l, [t]: "" } : { ...l, [t]: `textCheck:${c[1]},${e}` } : { ...l, [t]: e };
137
142
  }
138
- return { ...o, [t]: e };
143
+ return { ...l, [t]: e };
139
144
  });
140
145
  },
141
- [t, m, f]
146
+ [t, a, h]
142
147
  );
143
- if (L)
144
- return /* @__PURE__ */ d(
145
- se,
148
+ if (O)
149
+ return /* @__PURE__ */ u(
150
+ ne,
146
151
  {
147
152
  id: t,
148
- label: V,
149
- option: L,
150
- ref: F
153
+ label: g,
154
+ option: O,
155
+ ref: k
151
156
  }
152
157
  );
153
- const P = g !== void 0 && g !== "" && h === "" || k && h !== "", O = /* @__PURE__ */ p(te, { children: [
154
- g && h === "" ? /* @__PURE__ */ d(
155
- v,
158
+ const U = b !== void 0 && b !== "" && x === "" || $ && x !== "", N = /* @__PURE__ */ V(le, { children: [
159
+ b && x === "" ? /* @__PURE__ */ u(
160
+ H,
156
161
  {
157
162
  $variant: "lowRelevance",
158
163
  "data-testid": "reset-all-filters",
159
- onClick: G,
164
+ onClick: q,
160
165
  type: "button",
161
166
  children: "Reset all"
162
167
  }
163
168
  ) : void 0,
164
- k && h !== "" ? /* @__PURE__ */ d(
165
- v,
169
+ $ && x !== "" ? /* @__PURE__ */ u(
170
+ H,
166
171
  {
167
172
  $variant: "lowRelevance",
168
173
  "data-testid": "select-all-filters",
169
- onClick: X,
174
+ onClick: J,
170
175
  type: "button",
171
176
  children: "Select all"
172
177
  }
173
178
  ) : void 0
174
179
  ] });
175
- return /* @__PURE__ */ p(
176
- le,
180
+ return /* @__PURE__ */ V(
181
+ ae,
177
182
  {
178
183
  $left: "346px",
179
184
  "data-testid": "options-menu",
180
- ref: F,
185
+ ref: k,
181
186
  children: [
182
- x && !N && P ? /* @__PURE__ */ d(ce, { "data-testid": "options-menu-floating-actions", children: O }) : void 0,
183
- N ? /* @__PURE__ */ p(ae, { "data-testid": "options-menu-header", children: [
184
- /* @__PURE__ */ p(
185
- j,
187
+ f && !v && U ? /* @__PURE__ */ u(ie, { "data-testid": "options-menu-floating-actions", children: N }) : void 0,
188
+ v ? /* @__PURE__ */ V(de, { "data-testid": "options-menu-header", children: [
189
+ /* @__PURE__ */ V(
190
+ F,
186
191
  {
187
192
  display: "flex",
188
- justify: x ? "flex-end" : "space-between",
193
+ justify: f ? "flex-end" : "space-between",
189
194
  width: "100%",
190
195
  children: [
191
- x ? void 0 : /* @__PURE__ */ d(
192
- H,
196
+ f ? void 0 : /* @__PURE__ */ u(
197
+ Y,
193
198
  {
194
- color: w.palette.gray[800],
199
+ color: R.palette.gray[800],
195
200
  fontWeight: "bold",
196
201
  size: "md",
197
- children: `Select ${V}`
202
+ children: `Select ${g}`
198
203
  }
199
204
  ),
200
- O
205
+ N
201
206
  ]
202
207
  }
203
208
  ),
204
- y ? /* @__PURE__ */ d(
205
- j,
209
+ M ? /* @__PURE__ */ u(
210
+ F,
206
211
  {
207
212
  "data-testid": "exclude-toggle-row",
208
213
  display: "flex",
209
214
  justify: "space-between",
210
215
  width: "100%",
211
- children: /* @__PURE__ */ d(
212
- me,
216
+ children: /* @__PURE__ */ u(
217
+ he,
213
218
  {
214
- defaultChecked: W,
215
- disabled: !_,
219
+ defaultChecked: G,
220
+ disabled: !X,
216
221
  justify: "space-between",
217
- leftText: y.excludeLabel,
222
+ leftText: M.excludeLabel,
218
223
  name: `${t}-exclude`,
219
- onChange: q,
224
+ onChange: K,
220
225
  variant: "inline"
221
226
  }
222
227
  )
223
228
  }
224
229
  ) : void 0,
225
- k ? /* @__PURE__ */ d(
226
- ue,
230
+ $ ? /* @__PURE__ */ u(
231
+ fe,
227
232
  {
228
233
  name: "options-search",
229
- onChange: J,
230
- placeholder: `Search ${V}...`,
231
- value: h
234
+ onChange: P,
235
+ placeholder: `Search ${g}...`,
236
+ value: x
232
237
  }
233
238
  ) : void 0
234
239
  ] }) : void 0,
235
- /* @__PURE__ */ d(
236
- j,
240
+ /* @__PURE__ */ u(
241
+ F,
237
242
  {
238
243
  "data-testid": "options-scrollable-menu",
239
- ref: B,
244
+ ref: T,
240
245
  scroll: "y",
241
246
  width: "100%",
242
- children: m?.map((e, s, u) => {
243
- const o = e.type === "checkboxes", l = !o || ($[s]?.length ?? 0) > 0;
244
- return /* @__PURE__ */ d(
247
+ children: a?.map((e, s, m) => {
248
+ const l = e.type === "checkboxes", r = !l || (w[s]?.length ?? 0) > 0;
249
+ return /* @__PURE__ */ u(
245
250
  "div",
246
251
  {
247
252
  style: { position: "relative" },
248
- children: /* @__PURE__ */ p(
249
- ie,
253
+ children: /* @__PURE__ */ V(
254
+ ue,
250
255
  {
251
- $border: u.length > 1 && s > 0,
252
- $overflow: o,
253
- style: { padding: l ? w.spacing[0.875] : 0 },
256
+ $border: m.length > 1 && s > 0,
257
+ $overflow: l,
258
+ style: { padding: r ? R.spacing[0.875] : 0 },
254
259
  children: [
255
- x || e.showLabel === !0 || u.length > 1 && !o ? /* @__PURE__ */ d(
256
- H,
260
+ f || e.showLabel === !0 || m.length > 1 && !l ? /* @__PURE__ */ u(
261
+ Y,
257
262
  {
258
- color: w.palette.gray[x ? 800 : 400],
263
+ color: R.palette.gray[f ? 800 : 400],
259
264
  fontWeight: "bold",
260
265
  mb: 0.5,
261
266
  size: "md",
262
267
  children: e.label
263
268
  }
264
269
  ) : void 0,
265
- /* @__PURE__ */ d(
266
- ne,
270
+ /* @__PURE__ */ u(
271
+ re,
267
272
  {
268
- filterValue: g,
269
- filteredItems: $[s] ?? [],
273
+ filterValue: b,
274
+ filteredItems: w[s] ?? [],
270
275
  id: t,
271
- label: V,
272
- onChange: K,
276
+ label: g,
277
+ onChange: Q,
273
278
  option: e
274
279
  }
275
280
  )
@@ -287,5 +292,5 @@ const Ie = U(function({ hideTitle: x = !1, label: V, options: m }, F) {
287
292
  );
288
293
  });
289
294
  export {
290
- Ie as OptionsMenu
295
+ Oe as OptionsMenu
291
296
  };