@ogcio/design-system-react 1.15.1 → 1.15.3

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