@ogcio/design-system-react 1.12.4 → 1.14.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 (123) hide show
  1. package/dist/accordion/accordion-item.js +1 -1
  2. package/dist/alert/alert.js +1 -1
  3. package/dist/autocomplete/autocomplete.d.ts +21 -3
  4. package/dist/autocomplete/autocomplete.js +212 -237
  5. package/dist/autocomplete/types.d.ts +29 -7
  6. package/dist/autocomplete/types.js +2 -1
  7. package/dist/autocomplete/use-autocomplete-controller.d.ts +12 -0
  8. package/dist/autocomplete/use-autocomplete-controller.js +169 -0
  9. package/dist/button/button.js +27 -22
  10. package/dist/button/helpers.d.ts +1 -1
  11. package/dist/button/helpers.js +14 -12
  12. package/dist/button/types.d.ts +1 -1
  13. package/dist/button-group/button-group.d.ts +1 -0
  14. package/dist/button-group/button-group.js +67 -60
  15. package/dist/card/card-next.js +28 -28
  16. package/dist/checkbox/checkbox.d.ts +7 -1
  17. package/dist/combo-box/dropdown-item.js +30 -30
  18. package/dist/data-grid/editable-table-cell.d.ts +3 -0
  19. package/dist/data-grid/editable-table-cell.js +73 -0
  20. package/dist/data-grid/tanstack/tanstack-helpers.d.ts +11 -0
  21. package/dist/data-grid/tanstack/tanstack-helpers.js +1799 -0
  22. package/dist/data-grid/types.d.ts +20 -0
  23. package/dist/data-grid/types.js +1 -0
  24. package/dist/drawer/drawer.content.js +6 -6
  25. package/dist/drawer/drawer.js +8 -8
  26. package/dist/error-text/error-text.js +1 -1
  27. package/dist/forms/form-field/form-field.js +4 -4
  28. package/dist/forms/form-field-with-tag/form-field-with-tag.js +1 -1
  29. package/dist/header/components/header-slot.js +38 -27
  30. package/dist/header/header.js +5 -5
  31. package/dist/heading/heading.js +1 -1
  32. package/dist/hint-text/hint-text.js +1 -1
  33. package/dist/hooks/use-aria-hider.d.ts +1 -0
  34. package/dist/hooks/use-aria-hider.js +20 -0
  35. package/dist/hooks/use-combined-refs.d.ts +5 -0
  36. package/dist/hooks/use-combined-refs.js +10 -0
  37. package/dist/hooks/use-focus-trap.d.ts +2 -0
  38. package/dist/hooks/use-focus-trap.js +678 -0
  39. package/dist/hooks/use-scroll-highlighted-item.d.ts +1 -0
  40. package/dist/hooks/use-scroll-highlighted-item.js +16 -0
  41. package/dist/icon/icon.js +46 -46
  42. package/dist/icon/icons.d.ts +2 -2
  43. package/dist/icon/icons.js +5 -1
  44. package/dist/icon/svgs/placeholder.js +2 -2
  45. package/dist/icon-button/icon-button.js +24 -22
  46. package/dist/index-2sRBqKFV.js +78 -0
  47. package/dist/{index-DNkhmzZp.js → index-CB-zPpNk.js} +44 -44
  48. package/dist/index.d.ts +9 -6
  49. package/dist/index.js +135 -130
  50. package/dist/input-checkbox/input-checkbox.d.ts +9 -2
  51. package/dist/input-checkbox/input-checkbox.js +65 -42
  52. package/dist/input-checkbox/types.d.ts +5 -0
  53. package/dist/input-checkbox-group/input-checkbox-group.js +22 -16
  54. package/dist/input-checkbox-group/types.d.ts +1 -0
  55. package/dist/input-radio/input-radio.js +15 -15
  56. package/dist/input-radio-group/input-radio-group.js +24 -17
  57. package/dist/input-radio-group/types.d.ts +1 -0
  58. package/dist/input-text/input-text.d.ts +22 -0
  59. package/dist/input-text/input-text.js +121 -100
  60. package/dist/input-text/type.d.ts +5 -0
  61. package/dist/label/label.js +1 -1
  62. package/dist/link/link.js +1 -1
  63. package/dist/list/list.js +3 -3
  64. package/dist/lodash-D1c5hFAM.js +3677 -0
  65. package/dist/modal/modal.content.js +1 -1
  66. package/dist/modal/modal.d.ts +8 -2
  67. package/dist/modal/modal.js +166 -131
  68. package/dist/popover/popover.d.ts +1 -1
  69. package/dist/popover/popover.js +534 -526
  70. package/dist/popover/types.d.ts +1 -0
  71. package/dist/popover/utilities.d.ts +2 -0
  72. package/dist/popover/utilities.js +16 -0
  73. package/dist/primitives/anchor.js +1 -1
  74. package/dist/primitives/button.d.ts +3 -0
  75. package/dist/primitives/button.js +9 -0
  76. package/dist/progress-bar/progress-bar.js +8 -8
  77. package/dist/progress-stepper/progress-stepper.js +12 -12
  78. package/dist/score-select/score-select.js +3 -3
  79. package/dist/select/select-menu.d.ts +2 -2
  80. package/dist/select/select-menu.js +113 -110
  81. package/dist/select/select-native.d.ts +5 -2
  82. package/dist/select/select-native.js +45 -15
  83. package/dist/select/select-next.d.ts +14 -2
  84. package/dist/select/select-next.js +190 -142
  85. package/dist/select/select-search.d.ts +3 -0
  86. package/dist/select/select-search.js +24 -0
  87. package/dist/select/select.d.ts +4 -2
  88. package/dist/select/select.js +3 -2
  89. package/dist/select/types.d.ts +25 -1
  90. package/dist/side-nav/side-nav.js +23 -23
  91. package/dist/spinner/spinner.js +1 -1
  92. package/dist/stack/stack.js +40 -49
  93. package/dist/styles.css +2 -3
  94. package/dist/table/index.d.ts +8 -0
  95. package/dist/table/index.js +19 -0
  96. package/dist/table/table-data.d.ts +16 -2
  97. package/dist/table/table-data.js +64 -17
  98. package/dist/table/table-header.d.ts +4 -1
  99. package/dist/table/table-header.js +58 -18
  100. package/dist/table/table-pagination.d.ts +8 -0
  101. package/dist/table/table-pagination.js +97 -0
  102. package/dist/table/table-row.js +7 -6
  103. package/dist/table/table.d.ts +4 -1
  104. package/dist/table/table.js +22 -15
  105. package/dist/tabs/scrollable-tab-list.d.ts +9 -0
  106. package/dist/tabs/scrollable-tab-list.js +84 -0
  107. package/dist/tabs/tab-item.d.ts +9 -15
  108. package/dist/tabs/tab-item.js +85 -38
  109. package/dist/tabs/tab-list.d.ts +2 -5
  110. package/dist/tabs/tab-list.js +83 -49
  111. package/dist/tabs/tab-panel.d.ts +2 -7
  112. package/dist/tabs/tab-panel.js +2 -5
  113. package/dist/tabs/tabs.d.ts +2 -7
  114. package/dist/tabs/tabs.js +24 -20
  115. package/dist/tabs/types.d.ts +64 -0
  116. package/dist/tabs/types.js +1 -0
  117. package/dist/text-input/text-input.d.ts +1 -0
  118. package/dist/textarea/textarea.d.ts +1 -2
  119. package/dist/textarea/textarea.js +60 -60
  120. package/dist/toast/ds-toast.js +1 -1
  121. package/dist/tooltip/tooltip.js +1 -1
  122. package/package.json +6 -6
  123. package/dist/index-ntYL1VRC.js +0 -64
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsxs as d, Fragment as u, jsx as i } from "react/jsx-runtime";
3
3
  import { useState as y, useRef as b } from "react";
4
- import { c as h } from "../index-DNkhmzZp.js";
4
+ import { c as h } from "../index-CB-zPpNk.js";
5
5
  import { cn as r } from "../cn.js";
6
6
  import { Icon as w } from "../icon/icon.js";
7
7
  const I = h({
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsxs as n, jsx as r } from "react/jsx-runtime";
3
3
  import { useState as D } from "react";
4
- import { c as h } from "../index-DNkhmzZp.js";
4
+ import { c as h } from "../index-CB-zPpNk.js";
5
5
  import { cn as v } from "../cn.js";
6
6
  import { translate as k } from "../i18n/utility.js";
7
7
  import { Icon as w } from "../icon/icon.js";
@@ -1,4 +1,22 @@
1
- import { FC } from 'react';
2
- import { AutocompleteItemProps, AutocompleteProps } from './types.js';
3
- export declare const Autocomplete: FC<AutocompleteProps>;
1
+ import { FC, ChangeEvent } from 'react';
2
+ import { AutocompleteItemProps } from './types.js';
3
+ export declare const Autocomplete: import('react').ForwardRefExoticComponent<{
4
+ id?: string;
5
+ defaultValue?: string;
6
+ disabled?: boolean;
7
+ onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
8
+ freeSolo?: boolean;
9
+ isLoading?: boolean;
10
+ onSelectItem?: (item: string) => void;
11
+ onOpen?: () => void;
12
+ onClose?: () => void;
13
+ isOpen?: boolean;
14
+ } & {
15
+ children?: import('react').ReactNode | undefined;
16
+ } & Omit<import('react').InputHTMLAttributes<HTMLInputElement>, "defaultChecked" | "onChange"> & import('react').RefAttributes<HTMLInputElement>>;
17
+ export declare const renderSelectMenuOptions: (options: any[], state: any, handleOnSelectItem: (value: string) => void) => React.ReactNode[];
4
18
  export declare const AutocompleteItem: FC<AutocompleteItemProps>;
19
+ export declare const AutocompleteGroupItem: FC<{
20
+ children?: any;
21
+ label: string;
22
+ }>;
@@ -1,252 +1,227 @@
1
1
  "use client";
2
- import { jsxs as G, jsx as E } from "react/jsx-runtime";
3
- import { useRef as C, useReducer as H, useEffect as m, createElement as j, isValidElement as K, Children as X } from "react";
4
- import { cn as N } from "../cn.js";
5
- import { InputText as $ } from "../input-text/input-text.js";
6
- import { Popover as q } from "../popover/popover.js";
7
- import { SelectMenu as z, SelectMenuOption as F } from "../select/select-menu.js";
8
- import { AUTOCOMPLETE_ACTIONS as J } from "./types.js";
2
+ import { jsxs as j, jsx as y } from "react/jsx-runtime";
3
+ import { forwardRef as B, useRef as V, useImperativeHandle as $, createElement as K, Children as X, isValidElement as q } from "react";
4
+ import { cn as _ } from "../cn.js";
5
+ import { translate as A } from "../i18n/utility.js";
6
+ import { InputText as z } from "../input-text/input-text.js";
7
+ import { Popover as F } from "../popover/popover.js";
8
+ import { SelectMenu as J, SelectMenuOption as x, SelectMenuGroupItem as Q } from "../select/select-menu.js";
9
+ import { AUTOCOMPLETE_ACTIONS as W } from "./types.js";
10
+ import { useAutocompleteController as Y } from "./use-autocomplete-controller.js";
9
11
  const {
10
- ON_RESET: v,
11
- ON_SELECT_ITEM: L,
12
- SET_INPUT_VALUE: h,
13
- SET_IS_OPEN: u,
14
- SET_OPTIONS: T,
15
- TOGGLE_CLEAR_BUTTON: O,
16
- SET_VALUE: R,
17
- SET_HIGHLIGHTED_INDEX: b
18
- } = J, Q = (t, o) => {
19
- switch (o.type) {
20
- case u:
21
- return { ...t, isOpen: o.payload };
22
- case h:
23
- return { ...t, inputValue: o.payload };
24
- case T:
25
- return { ...t, autocompleteOptions: o.payload };
26
- case R:
27
- return { ...t, value: o.payload };
28
- case O:
29
- return {
30
- ...t,
31
- isClearButtonEnabled: o.payload || !!t.inputValue
32
- };
33
- case v:
34
- return {
35
- ...t,
36
- value: "",
37
- inputValue: "",
38
- isClearButtonEnabled: !1,
39
- highlightedIndex: -1
40
- };
41
- case L:
42
- return {
43
- ...t,
44
- inputValue: o.payload.inputValue,
45
- value: o.payload.value,
46
- isOpen: !1,
47
- isClearButtonEnabled: !0
48
- };
49
- case b:
50
- return { ...t, highlightedIndex: o.payload, isOpen: !0 };
51
- default:
52
- return t;
12
+ ON_RESET: Z,
13
+ ON_SELECT_ITEM: ee,
14
+ SET_INPUT_VALUE: te,
15
+ SET_IS_OPEN: i,
16
+ TOGGLE_CLEAR_BUTTON: N,
17
+ SET_HIGHLIGHTED_INDEX: v
18
+ } = W, oe = (n) => n ? "keyboard_arrow_up" : "keyboard_arrow_down", T = (n, r) => (p) => {
19
+ if (n) {
20
+ const l = {
21
+ target: {
22
+ name: r,
23
+ value: p
24
+ },
25
+ currentTarget: {
26
+ name: r,
27
+ value: p
28
+ },
29
+ bubbles: !0,
30
+ isTrusted: !0
31
+ };
32
+ n == null || n(l);
53
33
  }
54
- }, W = (t, o) => {
55
- var l, y;
56
- const r = ((l = t.props.children) == null ? void 0 : l.toString().toLowerCase()) || "", s = (y = t.props.value) == null ? void 0 : y.toLowerCase(), c = o.toLowerCase();
57
- return r.includes(c) || s.includes(c);
58
- }, _ = (t) => {
59
- var r, s;
60
- const o = ((r = t == null ? void 0 : t.type) == null ? void 0 : r.componentType) || ((s = t == null ? void 0 : t.props) == null ? void 0 : s.__mdxType);
61
- return K(t) && o === "AutocompleteItem";
62
- }, S = (t) => X.toArray(t).filter((o) => _(o)) || [], I = (t, o) => {
63
- var r;
64
- return (((r = S(t).find((s) => s.props.value === o)) == null ? void 0 : r.props.children) || "").toString();
65
- }, re = ({
66
- disabled: t,
67
- children: o,
68
- defaultValue: r = "",
69
- onChange: s,
70
- ...c
71
- }) => {
72
- const l = C(null), y = C(null), x = C(!1), [n, a] = H(Q, {
73
- isOpen: !1,
74
- value: r,
75
- inputValue: r ? I(o, r) : "",
76
- autocompleteOptions: o,
77
- isClearButtonEnabled: !1,
78
- highlightedIndex: -1
79
- }), f = S(n.autocompleteOptions), V = (e) => {
80
- if (s && l.current) {
81
- const p = {
82
- target: {
83
- ...l.current,
34
+ }, ye = B(
35
+ (n, r) => {
36
+ var S;
37
+ const p = V(null), {
38
+ disabled: l,
39
+ children: c,
40
+ placeholder: d,
41
+ onSelectItem: g,
42
+ isLoading: u,
43
+ freeSolo: a = !1,
44
+ onChange: b,
45
+ name: O
46
+ } = n, { state: t, dispatch: o, inputRef: m, getOptionLabelByValue: w, listRef: k } = Y({
47
+ ...n,
48
+ onChange: T(b, O)
49
+ });
50
+ $(r, () => m.current);
51
+ const G = (e) => {
52
+ o({ type: i, payload: e }), e || o({ type: N, payload: !1 });
53
+ }, P = () => {
54
+ o({ type: Z }), o({ type: i, payload: !1 }), T(b, O)("");
55
+ }, R = (e) => {
56
+ o({ type: te, payload: e }), a && T(b, O)(e), e && o({ type: i, payload: !0 });
57
+ }, D = (e) => {
58
+ const {
59
+ target: { value: f }
60
+ } = e;
61
+ e.__origin === "clear_button" ? P() : R(f), o({ type: N }), setTimeout(() => {
62
+ var h;
63
+ return (h = m.current) == null ? void 0 : h.focus();
64
+ });
65
+ }, L = () => {
66
+ var e;
67
+ o({ type: i, payload: !t.isOpen }), (e = m.current) == null || e.focus();
68
+ }, H = () => {
69
+ t.isOpen || o({
70
+ type: i,
71
+ payload: !0
72
+ });
73
+ }, E = (e) => {
74
+ o({
75
+ type: ee,
76
+ payload: {
77
+ inputValue: w(c, e),
84
78
  value: e
85
- },
86
- currentTarget: l.current,
87
- bubbles: !0,
88
- isTrusted: !0
79
+ }
80
+ }), g && g(e);
81
+ }, M = (e) => {
82
+ const f = t.autocompleteOptions.length, h = (s, U) => {
83
+ let I = s;
84
+ for (let C = 0; C < f; C++)
85
+ if (I = (I + U + f) % f, !t.autocompleteOptions[I].props.disabled)
86
+ return I;
87
+ return -1;
89
88
  };
90
- s(p);
91
- }
92
- }, k = (e) => {
93
- a({ type: u, payload: e }), e || a({ type: O, payload: !1 });
94
- }, B = (e) => {
95
- const {
96
- target: { value: p }
97
- } = e;
98
- e.__origin === "clear_button" ? (a({ type: v }), a({ type: u, payload: !1 }), V("")) : (a({ type: h, payload: p }), p && a({ type: u, payload: !0 })), a({ type: O }), setTimeout(() => {
99
- var i;
100
- return (i = l.current) == null ? void 0 : i.focus();
101
- });
102
- }, P = () => {
103
- var e;
104
- a({ type: u, payload: !n.isOpen }), (e = l.current) == null || e.focus();
105
- }, D = () => {
106
- n.isOpen || a({
107
- type: u,
108
- payload: !0
109
- });
110
- }, w = (e) => {
111
- a({
112
- type: L,
113
- payload: {
114
- inputValue: I(o, e),
115
- value: e
89
+ if (e.key === "ArrowDown")
90
+ e.preventDefault(), o({
91
+ type: v,
92
+ payload: t.isOpen ? h(t.highlightedIndex, 1) : 0
93
+ }), o({ type: i, payload: !0 });
94
+ else if (e.key === "ArrowUp")
95
+ e.preventDefault(), o({
96
+ type: v,
97
+ payload: h(t.highlightedIndex, -1)
98
+ }), o({ type: i, payload: !0 });
99
+ else if (e.key === "Enter" && t.highlightedIndex >= 0) {
100
+ const s = t.autocompleteOptions[t.highlightedIndex];
101
+ s && s.props.value && !s.props.disabled && E(s.props.value);
116
102
  }
117
- }), V(e);
118
- };
119
- m(() => {
120
- var p;
121
- const e = f.find(
122
- (i) => _(i) && i.props.value === n.value
123
- );
124
- e && a({
125
- type: h,
126
- payload: ((p = e.props.children) == null ? void 0 : p.toString()) || ""
127
- });
128
- }, [n.value]), m(() => {
129
- var p;
130
- if (!x.current) {
131
- x.current = !0;
132
- return;
133
- }
134
- n.inputValue === "" && n.value === "" && ((p = l.current) == null || p.focus());
135
- }, [n.isClearButtonEnabled]), m(() => {
136
- var e;
137
- if (n.isOpen)
138
- (e = l.current) == null || e.focus();
139
- else {
140
- const p = I(o, n.value);
141
- p && n.value ? (a({
142
- type: h,
143
- payload: p
144
- }), a({ type: u, payload: !1 })) : a({ type: v }), a({ type: O });
145
- }
146
- }, [n.isOpen]), m(() => {
147
- if (n.inputValue && o) {
148
- const e = S(o).filter(
149
- (p) => W(p, n.inputValue)
150
- );
151
- a({ type: T, payload: e }), !n.isOpen && !n.value && a({ type: u, payload: !0 });
152
- } else
153
- a({ type: R, payload: "" }), a({ type: T, payload: o });
154
- }, [n.inputValue]);
155
- const U = (e) => {
156
- const p = f.length, i = (d, M) => {
157
- let g = d;
158
- for (let A = 0; A < p; A++)
159
- if (g = (g + M + p) % p, !f[g].props.disabled)
160
- return g;
161
- return -1;
162
103
  };
163
- if (e.key === "ArrowDown")
164
- e.preventDefault(), a({
165
- type: b,
166
- payload: n.isOpen ? i(n.highlightedIndex, 1) : 0
167
- });
168
- else if (e.key === "ArrowUp")
169
- e.preventDefault(), a({
170
- type: b,
171
- payload: i(n.highlightedIndex, -1)
172
- });
173
- else if (e.key === "Enter" && n.highlightedIndex >= 0) {
174
- const d = f[n.highlightedIndex];
175
- d && d.props.value && !d.props.disabled && w(d.props.value);
176
- }
177
- };
178
- return /* @__PURE__ */ G(
179
- "div",
180
- {
181
- ...c,
182
- "aria-disabled": t,
183
- className: N("gi-autocomplete gi-not-prose", c.className),
184
- children: [
185
- /* @__PURE__ */ E(
186
- $,
187
- {
188
- onKeyDown: U,
189
- onIconEndClick: P,
190
- onChange: B,
191
- onClick: D,
192
- clearButtonEnabled: n.isClearButtonEnabled,
193
- inputActionPosition: "beforeSuffix",
194
- "aria-label": "Type to Search",
195
- "aria-disabled": t,
196
- disabled: t,
197
- placeholder: n.inputValue || "Type to Search",
198
- iconEndClassName: N({
199
- "gi-cursor-pointer": !t,
200
- "gi-cursor-not-allowed gi-pointer-events-none": t
201
- }),
202
- iconEnd: n.isOpen ? "arrow_drop_up" : "arrow_drop_down",
203
- ref: l,
204
- iconEndRef: y,
205
- value: n.inputValue,
206
- "data-highlighted-index": n.highlightedIndex
207
- }
208
- ),
209
- /* @__PURE__ */ E(
210
- q,
211
- {
212
- onOpenChange: k,
213
- triggerRef: l,
214
- extraRefs: [y],
215
- open: n.isOpen,
216
- options: {
217
- placement: "bottom-start",
218
- strategy: "absolute",
219
- modifiers: [
220
- { name: "preventOverflow", options: { padding: 8 } },
104
+ return /* @__PURE__ */ j(
105
+ "div",
106
+ {
107
+ "aria-disabled": l,
108
+ className: _("gi-autocomplete gi-not-prose", n.className),
109
+ children: [
110
+ /* @__PURE__ */ y(
111
+ z,
112
+ {
113
+ name: O,
114
+ onKeyDown: M,
115
+ onIconEndClick: L,
116
+ onChange: D,
117
+ onClick: H,
118
+ clearButtonEnabled: t.isClearButtonEnabled,
119
+ inputActionPosition: "beforeSuffix",
120
+ "aria-label": A("autocomplete.placeholder"),
121
+ "aria-disabled": l,
122
+ disabled: l,
123
+ placeholder: d || A("autocomplete.placeholder"),
124
+ iconEndClassName: _({
125
+ "gi-cursor-pointer": !l && !a,
126
+ "gi-cursor-not-allowed gi-pointer-events-none": l && !a
127
+ }),
128
+ iconEnd: a ? void 0 : oe(t.isOpen),
129
+ ref: m,
130
+ iconEndRef: p,
131
+ value: t.inputValue,
132
+ "data-highlighted-index": t.highlightedIndex
133
+ }
134
+ ),
135
+ /* @__PURE__ */ y(
136
+ F,
137
+ {
138
+ onOpenChange: G,
139
+ triggerRef: m,
140
+ extraRefs: [p],
141
+ open: t.isOpen,
142
+ maxHeight: 304,
143
+ options: {
144
+ placement: "bottom-start",
145
+ strategy: "absolute",
146
+ modifiers: [
147
+ { name: "offset", options: { offset: [0, 4] } },
148
+ {
149
+ name: "flip",
150
+ options: { fallbackPlacements: ["top"] }
151
+ }
152
+ ]
153
+ },
154
+ children: /* @__PURE__ */ y(
155
+ J,
221
156
  {
222
- name: "flip",
223
- options: { fallbackPlacements: ["top", "right", "left"] }
157
+ onChange: E,
158
+ isLoading: u,
159
+ showNoData: !((S = t.autocompleteOptions) != null && S.length),
160
+ ref: k,
161
+ children: ne(
162
+ t.autocompleteOptions,
163
+ t,
164
+ E
165
+ )
224
166
  }
225
- ]
226
- },
227
- children: /* @__PURE__ */ E(z, { onChange: w, children: f.map(
228
- (e, p) => _(e) ? /* @__PURE__ */ j(
229
- F,
230
- {
231
- ...e.props,
232
- key: `AutocompleteItem-${e.props.value}`,
233
- selected: n.value === e.props.value,
234
- isHighlighted: p === n.highlightedIndex
235
- }
236
- ) : null
237
- ) })
238
- }
239
- )
240
- ]
241
- }
242
- );
243
- }, Y = () => null;
244
- Object.defineProperty(Y, "componentType", {
167
+ )
168
+ }
169
+ )
170
+ ]
171
+ }
172
+ );
173
+ }
174
+ ), ne = (n, r, p) => n.map((l, c) => {
175
+ if (r.optionType === "AutocompleteItem")
176
+ return /* @__PURE__ */ K(
177
+ x,
178
+ {
179
+ ...l.props,
180
+ key: `AutocompleteItem-${l.props.value}`,
181
+ selected: r.value === l.props.value,
182
+ isHighlighted: c === r.highlightedIndex,
183
+ index: c
184
+ }
185
+ );
186
+ if (r.optionType === "AutocompleteGroupItem") {
187
+ const d = l, g = X.toArray(d.props.children).filter((u) => q(u)).map((u) => {
188
+ const a = u.props;
189
+ return /* @__PURE__ */ y(
190
+ x,
191
+ {
192
+ ...a,
193
+ selected: r.value.toString() === a.value.toString(),
194
+ onChange: p,
195
+ index: c
196
+ },
197
+ `SelectGroupItemNext-SelectItemNext-${a.value.toString()}`
198
+ );
199
+ });
200
+ return /* @__PURE__ */ y(
201
+ Q,
202
+ {
203
+ label: d.props.label,
204
+ children: g
205
+ },
206
+ `Group-${d.props.label}`
207
+ );
208
+ }
209
+ return null;
210
+ }), le = () => null;
211
+ Object.defineProperty(le, "componentType", {
245
212
  value: "AutocompleteItem",
246
213
  writable: !1,
247
214
  enumerable: !1
248
215
  });
216
+ const re = () => null;
217
+ Object.defineProperty(re, "componentType", {
218
+ value: "AutocompleteGroupItem",
219
+ writable: !1,
220
+ enumerable: !1
221
+ });
249
222
  export {
250
- re as Autocomplete,
251
- Y as AutocompleteItem
223
+ ye as Autocomplete,
224
+ re as AutocompleteGroupItem,
225
+ le as AutocompleteItem,
226
+ ne as renderSelectMenuOptions
252
227
  };
@@ -1,4 +1,4 @@
1
- import { ReactElement } from 'react';
1
+ import { ChangeEvent, PropsWithChildren, ReactElement } from 'react';
2
2
  import { SelectMenuOptionProps } from '../select/types.js';
3
3
  export declare const AUTOCOMPLETE_ACTIONS: {
4
4
  readonly SET_IS_OPEN: "SET_IS_OPEN";
@@ -9,14 +9,16 @@ export declare const AUTOCOMPLETE_ACTIONS: {
9
9
  readonly TOGGLE_CLEAR_BUTTON: "TOGGLE_CLEAR_BUTTON";
10
10
  readonly ON_SELECT_ITEM: "ON_SELECT_ITEM";
11
11
  readonly SET_HIGHLIGHTED_INDEX: "SET_HIGHLIGHTED_INDEX";
12
+ readonly SET_OPTION_TYPE: "SET_OPTION_TYPE";
12
13
  };
13
14
  export type AutocompleteState = {
14
15
  isOpen: boolean;
15
16
  value: string;
16
17
  inputValue: string;
17
18
  isClearButtonEnabled: boolean;
18
- autocompleteOptions: React.ReactNode;
19
+ autocompleteOptions: any[];
19
20
  highlightedIndex: number;
21
+ optionType: string;
20
22
  };
21
23
  export type AutocompleteAction = {
22
24
  type: typeof AUTOCOMPLETE_ACTIONS.SET_IS_OPEN;
@@ -26,12 +28,15 @@ export type AutocompleteAction = {
26
28
  payload: string;
27
29
  } | {
28
30
  type: typeof AUTOCOMPLETE_ACTIONS.SET_OPTIONS;
29
- payload: React.ReactNode;
31
+ payload: any[];
30
32
  } | {
31
33
  type: typeof AUTOCOMPLETE_ACTIONS.SET_VALUE;
32
34
  payload: string;
33
35
  } | {
34
36
  type: typeof AUTOCOMPLETE_ACTIONS.ON_RESET;
37
+ } | {
38
+ type: typeof AUTOCOMPLETE_ACTIONS.SET_OPTION_TYPE;
39
+ payload: string;
35
40
  } | {
36
41
  type: typeof AUTOCOMPLETE_ACTIONS.TOGGLE_CLEAR_BUTTON;
37
42
  payload?: boolean;
@@ -48,11 +53,28 @@ export type AutocompleteAction = {
48
53
  export type AutocompleteOptionItemElement = ReactElement<SelectMenuOptionProps & {
49
54
  selectedValue: string;
50
55
  }>;
51
- export type AutocompleteProps = {
56
+ export type AutocompleteProps = PropsWithChildren<{
57
+ /** Unique identifier for the autocomplete component. */
58
+ id?: string;
59
+ /** Initial selected value when the component is first rendered. */
52
60
  defaultValue?: string;
53
- onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
54
- children: ReactElement<AutocompleteItemProps> | ReactElement<AutocompleteItemProps>[];
55
- } & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'defaultChecked'>;
61
+ /** When true, disables the autocomplete input and prevents user interaction. */
62
+ disabled?: boolean;
63
+ /** Callback function triggered when the input value changes */
64
+ onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
65
+ /** Enables typing freeform values not limited to the dropdown options and keep the value inside the Input. */
66
+ freeSolo?: boolean;
67
+ /** Displays loading spinner inside the dropdown list. */
68
+ isLoading?: boolean;
69
+ /** Callback triggered when an option is selected from the dropdown. */
70
+ onSelectItem?: (item: string) => void;
71
+ /** Callback triggered when the dropdown is opened. */
72
+ onOpen?: () => void;
73
+ /** Callback triggered when the dropdown is closed. */
74
+ onClose?: () => void;
75
+ /** Controls whether the dropdown is open (controlled mode). */
76
+ isOpen?: boolean;
77
+ }> & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'defaultChecked'>;
56
78
  export type AutocompleteItemProps = {
57
79
  children: string;
58
80
  className?: string;
@@ -6,7 +6,8 @@ const E = {
6
6
  ON_RESET: "ON_RESET",
7
7
  TOGGLE_CLEAR_BUTTON: "TOGGLE_CLEAR_BUTTON",
8
8
  ON_SELECT_ITEM: "ON_SELECT_ITEM",
9
- SET_HIGHLIGHTED_INDEX: "SET_HIGHLIGHTED_INDEX"
9
+ SET_HIGHLIGHTED_INDEX: "SET_HIGHLIGHTED_INDEX",
10
+ SET_OPTION_TYPE: "SET_OPTION_TYPE"
10
11
  };
11
12
  export {
12
13
  E as AUTOCOMPLETE_ACTIONS
@@ -0,0 +1,12 @@
1
+ import { AutocompleteAction, AutocompleteState, AutocompleteOptionItemElement, AutocompleteProps } from './types.js';
2
+ export declare const useAutocompleteController: ({ children, defaultValue, isOpen, freeSolo, onOpen, onClose, onChange, }: {
3
+ onChange?: (input: string, name?: string) => void;
4
+ ref?: any;
5
+ } & Pick<AutocompleteProps, "children" | "defaultValue" | "isOpen" | "freeSolo" | "onOpen" | "onClose">) => {
6
+ state: AutocompleteState;
7
+ dispatch: import('react').ActionDispatch<[action: AutocompleteAction]>;
8
+ inputRef: import('react').RefObject<HTMLInputElement | null>;
9
+ listRef: import('react').RefObject<HTMLDivElement | null>;
10
+ validChildren: AutocompleteOptionItemElement[];
11
+ getOptionLabelByValue: (children: any, value: string) => string;
12
+ };