@fluidattacks/design 10.1.0 → 10.3.0

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.
Files changed (32) hide show
  1. package/dist/components/filters/hooks.d.ts +4 -1
  2. package/dist/components/filters/hooks.js +35 -17
  3. package/dist/components/filters/options-menu/include-exclude/multi-select.d.ts +5 -1
  4. package/dist/components/filters/options-menu/include-exclude/multi-select.js +142 -112
  5. package/dist/components/filters/options-menu/index.js +156 -151
  6. package/dist/components/filters/options-menu/options/index.js +141 -114
  7. package/dist/components/filters/options-menu/options/types.d.ts +1 -0
  8. package/dist/components/filters/options-menu/single-select/index.js +83 -97
  9. package/dist/components/filters/options-menu/single-select/styles.d.ts +1 -2
  10. package/dist/components/filters/options-menu/single-select/styles.js +5 -22
  11. package/dist/components/filters/styles.d.ts +2 -1
  12. package/dist/components/filters/styles.js +27 -10
  13. package/dist/components/filters/types.d.ts +2 -2
  14. package/dist/components/form/styles.js +12 -7
  15. package/dist/components/inputs/fields/combobox/field/index.d.ts +1 -1
  16. package/dist/components/inputs/fields/combobox/field/index.js +115 -112
  17. package/dist/components/inputs/fields/combobox/index.d.ts +1 -1
  18. package/dist/components/inputs/fields/combobox/index.js +34 -31
  19. package/dist/components/inputs/fields/combobox/index.stories.d.ts +4 -1
  20. package/dist/components/inputs/fields/combobox/option/index.d.ts +1 -1
  21. package/dist/components/inputs/fields/combobox/option/index.js +79 -68
  22. package/dist/components/inputs/fields/combobox/styles.js +10 -3
  23. package/dist/components/inputs/fields/combobox/types.d.ts +5 -0
  24. package/dist/components/inputs/fields/combobox/utils.d.ts +1 -1
  25. package/dist/components/inputs/fields/combobox/utils.js +10 -10
  26. package/dist/components/loading/index.js +11 -11
  27. package/dist/components/loading/index.stories.d.ts +2 -1
  28. package/dist/components/modal/index.stories.d.ts +4 -1
  29. package/dist/components/modal/modal-confirm/index.d.ts +1 -1
  30. package/dist/components/modal/modal-confirm/index.js +34 -20
  31. package/dist/components/modal/types.d.ts +2 -0
  32. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { useFloating } from '@floating-ui/react';
1
2
  import { ICalendarState, IScrollState, ISearchState } from './context/types';
2
3
  declare const useFilterSearchState: () => {
3
4
  searchState: ISearchState;
@@ -9,4 +10,6 @@ declare const useFilterScrollState: () => {
9
10
  declare const useFilterCalendarState: () => {
10
11
  calendarState: ICalendarState;
11
12
  };
12
- export { useFilterSearchState, useFilterScrollState, useFilterCalendarState };
13
+ /** Floats a dropdown under its bar, as wide as the bar and kept on screen. */
14
+ declare const useFloatingDropdown: () => ReturnType<typeof useFloating>;
15
+ export { useFilterSearchState, useFilterScrollState, useFilterCalendarState, useFloatingDropdown, };
@@ -1,25 +1,43 @@
1
- import { useState as s, useCallback as l, useRef as n, useMemo as o } from "react";
2
- const u = () => {
3
- const [e, t] = s({
1
+ import { useFloating as c } from "../../node_modules/@floating-ui/react/dist/floating-ui.react.js";
2
+ import { useState as s, useCallback as n, useRef as i, useMemo as d } from "react";
3
+ import { autoUpdate as p } from "../../node_modules/@floating-ui/dom/dist/floating-ui.dom.js";
4
+ import { offset as u, flip as S, shift as f, size as m } from "../../node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js";
5
+ const C = () => {
6
+ const [t, e] = s({
4
7
  previousValue: ""
5
- }), a = l(
8
+ }), a = n(
6
9
  (r) => {
7
- t((c) => ({ ...c, ...r }));
10
+ e((l) => ({ ...l, ...r }));
8
11
  },
9
12
  []
10
13
  );
11
- return { searchState: e, updateSearch: a };
12
- }, d = () => {
13
- const e = n(null);
14
- return { scrollState: o(() => ({ ref: e }), []) };
15
- }, i = () => {
16
- const [e, t] = s(!1), a = l((r) => {
17
- t(r);
14
+ return { searchState: t, updateSearch: a };
15
+ }, O = () => {
16
+ const t = i(null);
17
+ return { scrollState: d(() => ({ ref: t }), []) };
18
+ }, P = () => {
19
+ const [t, e] = s(!1), a = n((r) => {
20
+ e(r);
18
21
  }, []);
19
- return { calendarState: { isOpen: e, updateCalendarState: a } };
20
- };
22
+ return { calendarState: { isOpen: t, updateCalendarState: a } };
23
+ }, h = 4, o = 8, R = () => c({
24
+ middleware: [
25
+ u(h),
26
+ S({ padding: o }),
27
+ f({ padding: o }),
28
+ m({
29
+ apply: ({ elements: t, rects: e }) => {
30
+ t.floating.style.width = `${e.reference.width}px`;
31
+ },
32
+ padding: o
33
+ })
34
+ ],
35
+ placement: "bottom-start",
36
+ whileElementsMounted: p
37
+ });
21
38
  export {
22
- i as useFilterCalendarState,
23
- d as useFilterScrollState,
24
- u as useFilterSearchState
39
+ P as useFilterCalendarState,
40
+ O as useFilterScrollState,
41
+ C as useFilterSearchState,
42
+ R as useFloatingDropdown
25
43
  };
@@ -12,7 +12,11 @@ interface IMultiSelectSearchProps {
12
12
  onToggle: (value: string) => void;
13
13
  /** When true, this dropdown opens on navigation (e.g. chip click). */
14
14
  autoOpen?: boolean;
15
+ /** Whether the options and the summary show each value; otherwise only labels. */
16
+ showValues?: boolean;
17
+ /** Whether the dropdown floats above its container instead of being clipped by it. */
18
+ portal?: boolean;
15
19
  }
16
- declare const MultiSelectSearch: ({ name, items, selected, placeholder, onToggle, autoOpen, }: Readonly<IMultiSelectSearchProps>) => JSX.Element;
20
+ declare const MultiSelectSearch: ({ name, items, selected, placeholder, onToggle, autoOpen, showValues, portal, }: Readonly<IMultiSelectSearchProps>) => JSX.Element;
17
21
  export type { IMultiSelectSearchProps };
18
22
  export { MultiSelectSearch };
@@ -1,103 +1,123 @@
1
- import { jsxs as y, jsx as r } from "react/jsx-runtime";
2
- import { useVirtualizer as K } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
3
- import { useState as u, useRef as k, useMemo as d, useCallback as n } from "react";
4
- import { useTheme as L } from "styled-components";
5
- import { StyledCombobox as Q, StyledBar as V, StyledChips as W, StyledInput as q, StyledToggle as G, StyledDropdown as _, StyledList as A, StyledCode as J } from "./styles.js";
6
- import { NoMatches as U } from "../../search/no-matches/index.js";
7
- import { StyledItem as X } from "../../styles.js";
8
- import { matchesQuery as Y } from "../../utils.js";
9
- import { Checkbox as Z } from "../../../checkbox/index.js";
10
- import { Icon as ee } from "../../../icon/index.js";
11
- import { useClickOutside as te } from "../../../../hooks/use-click-outside.js";
12
- const oe = 36, me = ({
13
- name: l,
14
- items: g,
15
- selected: o,
16
- placeholder: E,
17
- onToggle: v,
18
- autoOpen: I = !1
1
+ import { jsxs as $, jsx as o } from "react/jsx-runtime";
2
+ import { FloatingPortal as _ } from "../../../../node_modules/@floating-ui/react/dist/floating-ui.react.js";
3
+ import { useVirtualizer as A } from "../../../../node_modules/@tanstack/react-virtual/dist/esm/index.js";
4
+ import { useState as m, useRef as R, useMemo as g, useCallback as l, forwardRef as J } from "react";
5
+ import { useTheme as U } from "styled-components";
6
+ import { StyledCombobox as V, StyledBar as X, StyledChips as Y, StyledInput as Z, StyledToggle as ee, StyledList as te, StyledCode as oe, StyledDropdown as re } from "./styles.js";
7
+ import { useFloatingDropdown as ne } from "../../hooks.js";
8
+ import { NoMatches as le } from "../../search/no-matches/index.js";
9
+ import { StyledItem as ae, StyledFloatingDropdown as ie } from "../../styles.js";
10
+ import { matchesQuery as se } from "../../utils.js";
11
+ import { Checkbox as ce } from "../../../checkbox/index.js";
12
+ import { Icon as de } from "../../../icon/index.js";
13
+ import { useClickOutside as ue } from "../../../../hooks/use-click-outside.js";
14
+ const pe = 36, fe = J(function({ children: i, floatingStyle: r, id: u, portal: p, testId: f }, s) {
15
+ return p ? /* @__PURE__ */ o(_, { children: /* @__PURE__ */ o(
16
+ ie,
17
+ {
18
+ "data-testid": f,
19
+ id: u,
20
+ ref: s,
21
+ style: r,
22
+ children: i
23
+ }
24
+ ) }) : /* @__PURE__ */ o(re, { "data-testid": f, id: u, children: i });
25
+ }), Ie = ({
26
+ name: n,
27
+ items: i,
28
+ selected: r,
29
+ placeholder: u,
30
+ onToggle: p,
31
+ autoOpen: f = !1,
32
+ showValues: s = !0,
33
+ portal: k = !1
19
34
  }) => {
20
- const z = L(), [a, w] = u(I), [p, C] = u(""), [h, b] = u(
21
- () => new Set(o)
22
- ), [T, D] = u(null), x = k(null), c = k(null), $ = d(() => new Set(o), [o]), m = d(
23
- () => [...g].sort(
24
- (e, t) => Number(h.has(t.value)) - Number(h.has(e.value))
35
+ const T = U(), [a, D] = m(f), y = k ? `popover-${n}` : `${n}-dropdown`, { floatingStyles: O, refs: S } = ne(), [v, I] = m(""), [w, E] = m(
36
+ () => new Set(r)
37
+ ), [j, P] = m(null), z = R(null), h = R(null), F = g(() => new Set(r), [r]), b = g(
38
+ () => [...i].sort(
39
+ (e, t) => Number(w.has(t.value)) - Number(w.has(e.value))
25
40
  ),
26
- [g, h]
27
- ), f = d(() => {
28
- const e = p.trim().toLowerCase();
29
- return e === "" ? m : m.filter(
30
- (t) => Y(t, e)
41
+ [i, w]
42
+ ), C = g(() => {
43
+ const e = v.trim().toLowerCase();
44
+ return e === "" ? b : b.filter(
45
+ (t) => se(t, e)
31
46
  );
32
- }, [p, m]), O = n(
33
- () => x.current,
47
+ }, [v, b]), M = l(
48
+ () => z.current,
34
49
  []
35
- ), j = n(() => oe, []), S = K({
36
- count: f.length,
37
- estimateSize: j,
38
- getScrollElement: O,
50
+ ), N = l(() => pe, []), x = A({
51
+ count: C.length,
52
+ estimateSize: N,
53
+ getScrollElement: M,
39
54
  overscan: 6,
40
55
  useFlushSync: !1
41
- }), R = S.getVirtualItems(), i = n(() => {
42
- b(new Set(o)), C(""), w(!1);
43
- }, [o]), s = n(() => {
44
- b(new Set(o)), w(!0);
45
- }, [o]), M = n(
56
+ }), B = x.getVirtualItems(), c = l(() => {
57
+ E(new Set(r)), I(""), D(!1);
58
+ }, [r]), d = l(() => {
59
+ E(new Set(r)), D(!0);
60
+ }, [r]), H = l(
46
61
  (e) => {
47
- e.preventDefault(), e.stopPropagation(), a ? i() : (c.current?.focus(), s());
62
+ e.preventDefault(), e.stopPropagation(), a ? c() : (h.current?.focus(), d());
48
63
  },
49
- [a, i, s]
50
- ), N = n(() => {
51
- c.current?.focus(), s();
52
- }, [s]), P = n(
64
+ [a, c, d]
65
+ ), K = l(() => {
66
+ h.current?.focus(), d();
67
+ }, [d]), L = l(
53
68
  (e) => (t) => {
54
- t.stopPropagation(), v(e);
69
+ t.stopPropagation(), p(e);
55
70
  },
56
- [v]
57
- ), B = n(
71
+ [p]
72
+ ), Q = l(
58
73
  (e) => {
59
- C(e.target.value);
74
+ I(e.target.value);
60
75
  },
61
76
  []
62
- ), F = n(
77
+ ), W = l(
63
78
  (e) => {
64
- e.key === "Enter" ? e.preventDefault() : e.key === "Escape" && (i(), c.current?.blur());
79
+ e.key === "Enter" ? e.preventDefault() : e.key === "Escape" && (c(), h.current?.blur());
65
80
  },
66
- [i]
67
- ), H = d(() => o.length === 0 ? "" : o.length <= 2 ? o.join(", ") : `${o.slice(0, 2).join(", ")}, +${o.length - 2} more`, [o]);
68
- return te(a ? T : null, i), /* @__PURE__ */ y(Q, { ref: D, children: [
69
- /* @__PURE__ */ y(V, { onClick: N, children: [
70
- /* @__PURE__ */ r(W, { children: /* @__PURE__ */ r(
71
- q,
81
+ [c]
82
+ ), q = g(() => {
83
+ const e = s ? r : r.map(
84
+ (t) => i.find((G) => G.value === t)?.label ?? t
85
+ );
86
+ return e.length === 0 ? "" : e.length <= 2 ? e.join(", ") : `${e.slice(0, 2).join(", ")}, +${e.length - 2} more`;
87
+ }, [i, r, s]);
88
+ return ue(a ? j : null, c, [S.floating]), /* @__PURE__ */ $(V, { ref: P, children: [
89
+ /* @__PURE__ */ $(X, { onClick: K, ref: S.setReference, children: [
90
+ /* @__PURE__ */ o(Y, { children: /* @__PURE__ */ o(
91
+ Z,
72
92
  {
73
- "aria-controls": `${l}-dropdown`,
93
+ "aria-controls": y,
74
94
  "aria-expanded": a,
75
- "aria-label": `${l}-search`,
95
+ "aria-label": `${n}-search`,
76
96
  autoComplete: "off",
77
- id: `${l}-search`,
78
- name: `${l}-search`,
79
- onChange: B,
80
- onFocus: s,
81
- onKeyDown: F,
82
- placeholder: E,
83
- ref: c,
97
+ id: `${n}-search`,
98
+ name: `${n}-search`,
99
+ onChange: Q,
100
+ onFocus: d,
101
+ onKeyDown: W,
102
+ placeholder: u,
103
+ ref: h,
84
104
  type: "search",
85
- value: a ? p : H
105
+ value: a ? v : q
86
106
  }
87
107
  ) }),
88
- /* @__PURE__ */ r(
89
- G,
108
+ /* @__PURE__ */ o(
109
+ ee,
90
110
  {
91
- "aria-controls": `${l}-dropdown`,
111
+ "aria-controls": y,
92
112
  "aria-expanded": a,
93
- "aria-label": `${l}-toggle`,
94
- onClick: M,
113
+ "aria-label": `${n}-toggle`,
114
+ onClick: H,
95
115
  type: "button",
96
- children: /* @__PURE__ */ r(
97
- ee,
116
+ children: /* @__PURE__ */ o(
117
+ de,
98
118
  {
99
119
  icon: a ? "chevron-up" : "chevron-down",
100
- iconColor: z.palette.gray[700],
120
+ iconColor: T.palette.gray[700],
101
121
  iconSize: "sm",
102
122
  iconType: "fa-light"
103
123
  }
@@ -105,48 +125,58 @@ const oe = 36, me = ({
105
125
  }
106
126
  )
107
127
  ] }),
108
- a ? /* @__PURE__ */ r(_, { "data-testid": `${l}-dropdown`, children: /* @__PURE__ */ r(A, { ref: x, role: "listbox", children: f.length > 0 ? /* @__PURE__ */ r(
109
- "div",
128
+ a ? /* @__PURE__ */ o(
129
+ fe,
110
130
  {
111
- style: {
112
- height: `${S.getTotalSize()}px`,
113
- position: "relative",
114
- width: "100%"
115
- },
116
- children: R.map((e) => {
117
- const t = f[e.index];
118
- return /* @__PURE__ */ r(
119
- "div",
120
- {
121
- "data-index": e.index,
122
- ref: S.measureElement,
123
- style: {
124
- left: 0,
125
- position: "absolute",
126
- top: `${e.start}px`,
127
- width: "100%"
128
- },
129
- children: /* @__PURE__ */ r(X, { "aria-selected": $.has(t.value), children: /* @__PURE__ */ r(
130
- Z,
131
- {
132
- checked: $.has(t.value),
133
- label: /* @__PURE__ */ y("span", { children: [
134
- /* @__PURE__ */ r(J, { children: t.value }),
135
- t.label
136
- ] }),
137
- name: t.value,
138
- onChange: P(t.value),
139
- value: t.value
140
- }
141
- ) })
131
+ floatingStyle: O,
132
+ id: y,
133
+ portal: k,
134
+ ref: S.setFloating,
135
+ testId: `${n}-dropdown`,
136
+ children: /* @__PURE__ */ o(te, { ref: z, role: "listbox", children: C.length > 0 ? /* @__PURE__ */ o(
137
+ "div",
138
+ {
139
+ style: {
140
+ height: `${x.getTotalSize()}px`,
141
+ position: "relative",
142
+ width: "100%"
142
143
  },
143
- `${l}-${t.value}`
144
- );
145
- })
144
+ children: B.map((e) => {
145
+ const t = C[e.index];
146
+ return /* @__PURE__ */ o(
147
+ "div",
148
+ {
149
+ "data-index": e.index,
150
+ ref: x.measureElement,
151
+ style: {
152
+ left: 0,
153
+ position: "absolute",
154
+ top: `${e.start}px`,
155
+ width: "100%"
156
+ },
157
+ children: /* @__PURE__ */ o(ae, { "aria-selected": F.has(t.value), children: /* @__PURE__ */ o(
158
+ ce,
159
+ {
160
+ checked: F.has(t.value),
161
+ label: s ? /* @__PURE__ */ $("span", { children: [
162
+ /* @__PURE__ */ o(oe, { children: t.value }),
163
+ t.label
164
+ ] }) : t.label,
165
+ name: t.value,
166
+ onChange: L(t.value),
167
+ value: t.value
168
+ }
169
+ ) })
170
+ },
171
+ `${n}-${t.value}`
172
+ );
173
+ })
174
+ }
175
+ ) : /* @__PURE__ */ o(le, {}) })
146
176
  }
147
- ) : /* @__PURE__ */ r(U, {}) }) }) : void 0
177
+ ) : void 0
148
178
  ] });
149
179
  };
150
180
  export {
151
- me as MultiSelectSearch
181
+ Ie as MultiSelectSearch
152
182
  };