@ogcio/design-system-react 1.15.0 → 1.15.2

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,6 +1,6 @@
1
- import { FC, ChangeEvent } from 'react';
1
+ import { default as React, FC, ChangeEvent } from 'react';
2
2
  import { AutocompleteItemProps } from './types.js';
3
- export declare const Autocomplete: import('react').ForwardRefExoticComponent<{
3
+ export declare const Autocomplete: React.ForwardRefExoticComponent<{
4
4
  id?: string;
5
5
  defaultValue?: string;
6
6
  disabled?: boolean;
@@ -11,9 +11,10 @@ export declare const Autocomplete: import('react').ForwardRefExoticComponent<{
11
11
  onOpen?: () => void;
12
12
  onClose?: () => void;
13
13
  isOpen?: boolean;
14
+ value?: any;
14
15
  } & {
15
- children?: import('react').ReactNode | undefined;
16
- } & Omit<import('react').InputHTMLAttributes<HTMLInputElement>, "defaultChecked" | "onChange"> & import('react').RefAttributes<HTMLInputElement>>;
16
+ children?: React.ReactNode | undefined;
17
+ } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "defaultChecked" | "onChange"> & React.RefAttributes<HTMLInputElement>>;
17
18
  export declare const renderSelectMenuOptions: (options: any[], state: any, handleOnSelectItem: (value: string) => void) => React.ReactNode[];
18
19
  export declare const AutocompleteItem: FC<AutocompleteItemProps>;
19
20
  export declare const AutocompleteGroupItem: FC<{
@@ -1,141 +1,177 @@
1
1
  "use client";
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";
2
+ import { jsxs as z, jsx as O } from "react/jsx-runtime";
3
+ import { forwardRef as J, useRef as G, useImperativeHandle as Q, useEffect as W, createElement as Y, Children as Z, isValidElement as ee } from "react";
4
+ import { cn as P } from "../cn.js";
5
+ import { translate as D } from "../i18n/utility.js";
6
+ import { InputText as te } from "../input-text/input-text.js";
7
+ import { Popover as oe } from "../popover/popover.js";
8
+ import { SelectMenu as ne, SelectMenuOption as L, SelectMenuGroupItem as le } from "../select/select-menu.js";
9
+ import { AUTOCOMPLETE_ACTIONS as re } from "./types.js";
10
+ import { useAutocompleteController as ae } from "./use-autocomplete-controller.js";
11
11
  const {
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);
33
- }
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,
12
+ ON_RESET: pe,
13
+ ON_SELECT_ITEM: ie,
14
+ SET_INPUT_VALUE: R,
15
+ SET_IS_OPEN: d,
16
+ TOGGLE_CLEAR_BUTTON: v,
17
+ SET_HIGHLIGHTED_INDEX: B,
18
+ SET_VALUE: se
19
+ } = re, ce = (n) => n ? "keyboard_arrow_up" : "keyboard_arrow_down", C = (n, l) => (p) => {
20
+ n && n({
21
+ target: {
22
+ name: l,
23
+ value: p
24
+ },
25
+ currentTarget: {
26
+ name: l,
27
+ value: p
28
+ },
29
+ type: "change",
30
+ bubbles: !0,
31
+ isTrusted: !0
32
+ });
33
+ }, M = (n, l) => (p) => {
34
+ n && n({
35
+ target: { name: l, value: p },
36
+ currentTarget: { name: l, value: p },
37
+ type: "blur",
38
+ bubbles: !0,
39
+ isTrusted: !0
40
+ });
41
+ }, Se = J(
42
+ (n, l) => {
43
+ var N;
44
+ const p = G(null), {
45
+ disabled: r,
46
+ children: f,
47
+ placeholder: h,
48
+ onSelectItem: y,
49
+ isLoading: g,
50
+ freeSolo: s = !1,
44
51
  onChange: b,
45
- name: O
46
- } = n, { state: t, dispatch: o, inputRef: m, getOptionLabelByValue: w, listRef: k } = Y({
52
+ onBlur: A,
53
+ name: c,
54
+ value: E
55
+ } = n, _ = G(!1), {
56
+ state: t,
57
+ dispatch: o,
58
+ inputRef: m,
59
+ getOptionLabelByValue: x,
60
+ listRef: w,
61
+ debouncedFilter: U
62
+ } = ae({
47
63
  ...n,
48
- onChange: T(b, O)
64
+ onChange: C(b, c)
49
65
  });
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) => {
66
+ Q(l, () => m.current), W(() => {
67
+ E !== void 0 && (o({ type: se, payload: E }), o({
68
+ type: R,
69
+ payload: x(f, E)
70
+ }), o({ type: v }));
71
+ }, [E]);
72
+ const V = (e) => {
73
+ o({ type: d, payload: e }), e || o({ type: v, payload: !1 });
74
+ }, H = () => {
75
+ o({ type: pe }), o({ type: d, payload: !1 }), C(b, c)("");
76
+ }, j = (e) => {
77
+ o({ type: R, payload: e }), s && C(b, c)(e), e && o({ type: d, payload: !0 }), U(e);
78
+ }, $ = (e) => {
58
79
  const {
59
- target: { value: f }
80
+ target: { value: a }
60
81
  } = 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();
82
+ e.__origin === "clear_button" ? H() : j(a), o({ type: v }), setTimeout(() => {
83
+ var u;
84
+ return (u = m.current) == null ? void 0 : u.focus();
64
85
  });
65
- }, L = () => {
86
+ }, K = () => {
66
87
  var e;
67
- o({ type: i, payload: !t.isOpen }), (e = m.current) == null || e.focus();
68
- }, H = () => {
88
+ o({ type: d, payload: !t.isOpen }), (e = m.current) == null || e.focus();
89
+ }, F = () => {
69
90
  t.isOpen || o({
70
- type: i,
91
+ type: d,
71
92
  payload: !0
72
93
  });
73
- }, E = (e) => {
94
+ }, S = (e) => {
74
95
  o({
75
- type: ee,
96
+ type: ie,
76
97
  payload: {
77
- inputValue: w(c, e),
98
+ inputValue: x(f, e),
78
99
  value: e
79
100
  }
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;
101
+ }), C(b, c)(e), setTimeout(() => {
102
+ var a;
103
+ M(A, c)(e), (a = m.current) == null || a.blur();
104
+ }, 0), y == null || y(e);
105
+ }, X = (e) => {
106
+ var i, I;
107
+ const { relatedTarget: a } = e;
108
+ if (a && ((i = w.current) != null && i.contains(a) || (I = p.current) != null && I.contains(a)) || _.current) {
109
+ setTimeout(() => _.current = !1, 0);
110
+ return;
111
+ }
112
+ const u = t.value ?? t.inputValue ?? "";
113
+ M(A, c)(u);
114
+ }, q = (e) => {
115
+ const a = t.autocompleteOptions.length, u = (i, I) => {
116
+ let T = i;
117
+ for (let k = 0; k < a; k++)
118
+ if (T = (T + I + a) % a, !t.autocompleteOptions[T].props.disabled)
119
+ return T;
87
120
  return -1;
88
121
  };
89
122
  if (e.key === "ArrowDown")
90
123
  e.preventDefault(), o({
91
- type: v,
92
- payload: t.isOpen ? h(t.highlightedIndex, 1) : 0
93
- }), o({ type: i, payload: !0 });
124
+ type: B,
125
+ payload: t.isOpen ? u(t.highlightedIndex, 1) : 0
126
+ }), o({ type: d, payload: !0 });
94
127
  else if (e.key === "ArrowUp")
95
128
  e.preventDefault(), o({
96
- type: v,
97
- payload: h(t.highlightedIndex, -1)
98
- }), o({ type: i, payload: !0 });
129
+ type: B,
130
+ payload: u(t.highlightedIndex, -1)
131
+ }), o({ type: d, payload: !0 });
99
132
  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);
133
+ const i = t.autocompleteOptions[t.highlightedIndex];
134
+ i && i.props.value && !i.props.disabled && S(i.props.value);
102
135
  }
103
136
  };
104
- return /* @__PURE__ */ j(
137
+ return /* @__PURE__ */ z(
105
138
  "div",
106
139
  {
107
- "aria-disabled": l,
108
- className: _("gi-autocomplete gi-not-prose", n.className),
140
+ "aria-disabled": r,
141
+ className: P("gi-autocomplete gi-not-prose", n.className),
109
142
  children: [
110
- /* @__PURE__ */ y(
111
- z,
143
+ /* @__PURE__ */ O(
144
+ te,
112
145
  {
113
- name: O,
114
- onKeyDown: M,
115
- onIconEndClick: L,
116
- onChange: D,
117
- onClick: H,
146
+ name: c,
147
+ onKeyDown: q,
148
+ onIconEndClick: K,
149
+ onChange: $,
150
+ onClick: F,
151
+ onBlur: X,
118
152
  clearButtonEnabled: t.isClearButtonEnabled,
119
153
  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
154
+ "aria-label": D("autocomplete.placeholder", {
155
+ defaultValue: "Type to Search"
156
+ }),
157
+ "aria-disabled": r,
158
+ disabled: r,
159
+ placeholder: h || D("autocomplete.placeholder", { defaultValue: "Type to Search" }),
160
+ iconEndClassName: P({
161
+ "gi-cursor-pointer": !r && !s,
162
+ "gi-cursor-not-allowed gi-pointer-events-none": r && !s
127
163
  }),
128
- iconEnd: a ? void 0 : oe(t.isOpen),
164
+ iconEnd: s ? void 0 : ce(t.isOpen),
129
165
  ref: m,
130
166
  iconEndRef: p,
131
167
  value: t.inputValue,
132
168
  "data-highlighted-index": t.highlightedIndex
133
169
  }
134
170
  ),
135
- /* @__PURE__ */ y(
136
- F,
171
+ /* @__PURE__ */ O(
172
+ oe,
137
173
  {
138
- onOpenChange: G,
174
+ onOpenChange: V,
139
175
  triggerRef: m,
140
176
  extraRefs: [p],
141
177
  open: t.isOpen,
@@ -151,17 +187,17 @@ const {
151
187
  }
152
188
  ]
153
189
  },
154
- children: /* @__PURE__ */ y(
155
- J,
190
+ children: /* @__PURE__ */ O(
191
+ ne,
156
192
  {
157
- onChange: E,
158
- isLoading: u,
159
- showNoData: !((S = t.autocompleteOptions) != null && S.length),
160
- ref: k,
161
- children: ne(
193
+ onChange: S,
194
+ isLoading: g,
195
+ showNoData: !((N = t.autocompleteOptions) != null && N.length),
196
+ ref: w,
197
+ children: ue(
162
198
  t.autocompleteOptions,
163
199
  t,
164
- E
200
+ S
165
201
  )
166
202
  }
167
203
  )
@@ -171,57 +207,57 @@ const {
171
207
  }
172
208
  );
173
209
  }
174
- ), ne = (n, r, p) => n.map((l, c) => {
175
- if (r.optionType === "AutocompleteItem")
176
- return /* @__PURE__ */ K(
177
- x,
210
+ ), ue = (n, l, p) => n.map((r, f) => {
211
+ if (l.optionType === "AutocompleteItem")
212
+ return /* @__PURE__ */ Y(
213
+ L,
178
214
  {
179
- ...l.props,
180
- key: `AutocompleteItem-${l.props.value}`,
181
- selected: r.value === l.props.value,
182
- isHighlighted: c === r.highlightedIndex,
183
- index: c
215
+ ...r.props,
216
+ key: `AutocompleteItem-${r.props.value}`,
217
+ selected: l.value === r.props.value,
218
+ isHighlighted: f === l.highlightedIndex,
219
+ index: f
184
220
  }
185
221
  );
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,
222
+ if (l.optionType === "AutocompleteGroupItem") {
223
+ const h = r, y = Z.toArray(h.props.children).filter((g) => ee(g)).map((g) => {
224
+ const s = g.props;
225
+ return /* @__PURE__ */ O(
226
+ L,
191
227
  {
192
- ...a,
193
- selected: r.value.toString() === a.value.toString(),
228
+ ...s,
229
+ selected: l.value.toString() === s.value.toString(),
194
230
  onChange: p,
195
- index: c
231
+ index: f
196
232
  },
197
- `SelectGroupItemNext-SelectItemNext-${a.value.toString()}`
233
+ `SelectGroupItemNext-SelectItemNext-${s.value.toString()}`
198
234
  );
199
235
  });
200
- return /* @__PURE__ */ y(
201
- Q,
236
+ return /* @__PURE__ */ O(
237
+ le,
202
238
  {
203
- label: d.props.label,
204
- children: g
239
+ label: h.props.label,
240
+ children: y
205
241
  },
206
- `Group-${d.props.label}`
242
+ `Group-${h.props.label}`
207
243
  );
208
244
  }
209
245
  return null;
210
- }), le = () => null;
211
- Object.defineProperty(le, "componentType", {
246
+ }), de = () => null;
247
+ Object.defineProperty(de, "componentType", {
212
248
  value: "AutocompleteItem",
213
249
  writable: !1,
214
250
  enumerable: !1
215
251
  });
216
- const re = () => null;
217
- Object.defineProperty(re, "componentType", {
252
+ const fe = () => null;
253
+ Object.defineProperty(fe, "componentType", {
218
254
  value: "AutocompleteGroupItem",
219
255
  writable: !1,
220
256
  enumerable: !1
221
257
  });
222
258
  export {
223
- ye as Autocomplete,
224
- re as AutocompleteGroupItem,
225
- le as AutocompleteItem,
226
- ne as renderSelectMenuOptions
259
+ Se as Autocomplete,
260
+ fe as AutocompleteGroupItem,
261
+ de as AutocompleteItem,
262
+ ue as renderSelectMenuOptions
227
263
  };
@@ -74,6 +74,7 @@ export type AutocompleteProps = PropsWithChildren<{
74
74
  onClose?: () => void;
75
75
  /** Controls whether the dropdown is open (controlled mode). */
76
76
  isOpen?: boolean;
77
+ value?: any;
77
78
  }> & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'defaultChecked'>;
78
79
  export type AutocompleteItemProps = {
79
80
  children: string;
@@ -1,12 +1,13 @@
1
1
  import { AutocompleteAction, AutocompleteState, AutocompleteOptionItemElement, AutocompleteProps } from './types.js';
2
- export declare const useAutocompleteController: ({ children, defaultValue, isOpen, freeSolo, onOpen, onClose, onChange, }: {
2
+ export declare const useAutocompleteController: ({ children, defaultValue, isOpen, freeSolo, onOpen, onClose, onChange, value, }: {
3
3
  onChange?: (input: string, name?: string) => void;
4
4
  ref?: any;
5
- } & Pick<AutocompleteProps, "children" | "defaultValue" | "isOpen" | "freeSolo" | "onOpen" | "onClose">) => {
5
+ } & Pick<AutocompleteProps, "children" | "defaultValue" | "isOpen" | "freeSolo" | "onOpen" | "onClose" | "value">) => {
6
6
  state: AutocompleteState;
7
7
  dispatch: import('react').ActionDispatch<[action: AutocompleteAction]>;
8
8
  inputRef: import('react').RefObject<HTMLInputElement | null>;
9
9
  listRef: import('react').RefObject<HTMLDivElement | null>;
10
10
  validChildren: AutocompleteOptionItemElement[];
11
11
  getOptionLabelByValue: (children: any, value: string) => string;
12
+ debouncedFilter: import('lodash').DebouncedFunc<(input: string) => void>;
12
13
  };