@nice2dev/ui 1.4.17 → 1.4.18

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,10 +1,10 @@
1
- import { jsxs as t, jsx as n } from "react/jsx-runtime";
2
- import { useNiceTranslation as Ue, useOverlayFocus as Oe, NiceIcon as le } from "@nice2dev/ui-core";
3
- import { useRef as b, useState as X, useCallback as _, useMemo as D, useEffect as de, useId as Ve, useLayoutEffect as He } from "react";
1
+ import { jsxs as o, jsx as n } from "react/jsx-runtime";
2
+ import { useNiceTranslation as ze, useOverlayFocus as Oe, NiceIcon as I } from "@nice2dev/ui-core";
3
+ import { useRef as D, useState as Z, useCallback as k, useMemo as R, useEffect as ue, useId as Ve, useLayoutEffect as He } from "react";
4
4
  import { useListKeyboardNav as Me } from "../../utility/useListKeyboardNav.mjs";
5
5
  /* empty css */
6
- import { useDropdownAlignment as ze, FlagIcon as ue } from "./pickerCommons.mjs";
7
- const je = [
6
+ import { useDropdownAlignment as je, FlagIcon as ge } from "./pickerCommons.mjs";
7
+ const Je = [
8
8
  { code: "en", nativeName: "English", englishName: "English", flagCountryCode: "GB" },
9
9
  { code: "en-US", nativeName: "English (US)", englishName: "English (US)", flagCountryCode: "US" },
10
10
  { code: "en-GB", nativeName: "English (UK)", englishName: "English (UK)", flagCountryCode: "GB" },
@@ -80,142 +80,143 @@ const je = [
80
80
  { code: "th", nativeName: "ไทย", englishName: "Thai", flagCountryCode: "TH" },
81
81
  { code: "vi", nativeName: "Tiếng Việt", englishName: "Vietnamese", flagCountryCode: "VN" },
82
82
  { code: "id", nativeName: "Bahasa Indonesia", englishName: "Indonesian", flagCountryCode: "ID" }
83
- ], Je = ({
83
+ ], qe = ({
84
84
  value: d,
85
- defaultValue: ge,
85
+ defaultValue: me,
86
86
  onChange: w,
87
- placeholder: me,
88
- showSearch: he = !0,
89
- searchThreshold: Ne = 8,
90
- searchPlaceholder: Z,
91
- isOpen: R,
92
- onOpenChange: Q,
93
- showFlagInValue: fe = !0,
94
- showFlagInMenu: pe = !0,
95
- showTextInValue: Ce,
96
- showTextInMenu: ve = !0,
97
- showCodeInValue: ye,
87
+ placeholder: he,
88
+ showSearch: Ne = !0,
89
+ searchThreshold: fe = 8,
90
+ searchPlaceholder: Q,
91
+ isOpen: A,
92
+ onOpenChange: Y,
93
+ showFlagInValue: pe = !0,
94
+ triggerIcon: W = "flag",
95
+ showFlagInMenu: Ce = !0,
96
+ showTextInValue: ve,
97
+ showTextInMenu: ye = !0,
98
+ showCodeInValue: _e,
98
99
  showCodeInMenu: ke = !0,
99
- displayName: _e = "native",
100
+ displayName: we = "native",
100
101
  compact: r = !1,
101
- variant: A = "default",
102
- dropdownAlign: we,
102
+ variant: P = "default",
103
+ dropdownAlign: Se,
103
104
  disabled: m = !1,
104
- languages: Se,
105
+ languages: $e,
105
106
  allowedCodes: h,
106
- priorityCodes: P = ["en", "pl", "de", "fr", "es"],
107
- allowClear: $e = !1,
108
- size: Y = "md",
109
- className: Le = "",
107
+ priorityCodes: x = ["en", "pl", "de", "fr", "es"],
108
+ allowClear: Le = !1,
109
+ size: ee = "md",
110
+ className: be = "",
110
111
  style: Ee,
111
- label: x,
112
+ label: B,
112
113
  helperText: S,
113
- error: o,
114
+ error: t,
114
115
  required: Ie,
115
- readOnly: B,
116
- loading: F,
117
- labelPlacement: be,
116
+ readOnly: F,
117
+ loading: T,
118
+ labelPlacement: De,
118
119
  errorPlacement: N,
119
120
  labelWidth: $,
120
121
  controlWidth: L,
121
- id: De,
122
+ id: Re,
122
123
  "data-testid": f = "nice-language-picker",
123
- "aria-label": Re
124
+ "aria-label": Ae
124
125
  }) => {
125
- const { t: u } = Ue(), T = b(null), W = b(null), ee = b(null), [Ae, ne] = X(ge), [Pe, xe] = X(!1), i = R ?? Pe, c = _(
126
+ const { t: u } = ze(), G = D(null), ne = D(null), ae = D(null), [Pe, ie] = Z(me), [xe, Be] = Z(!1), i = A ?? xe, c = k(
126
127
  (e) => {
127
128
  const a = typeof e == "function" ? e(i) : e;
128
- R === void 0 && xe(a), Q?.(a);
129
+ A === void 0 && Be(a), Y?.(a);
129
130
  },
130
- [i, R, Q]
131
- ), [p, E] = X(""), ae = Ce ?? (!r && A !== "ghost"), Be = ye ?? !1, ie = r ? 320 : 280, Fe = ze(
131
+ [i, A, Y]
132
+ ), [p, b] = Z(""), oe = ve ?? (!r && P !== "ghost"), Fe = _e ?? !1, te = r ? 320 : 280, Te = je(
132
133
  i,
133
- W,
134
- we ?? (r ? "auto" : "left"),
135
- ie
136
- ), C = d !== void 0 ? d : Ae, G = Se ?? je, l = D(() => {
134
+ ne,
135
+ Se ?? (r ? "auto" : "left"),
136
+ te
137
+ ), C = d !== void 0 ? d : Pe, K = $e ?? Je, l = R(() => {
137
138
  if (!h || h.length === 0)
138
- return G;
139
- const e = h.map((k) => k.toLowerCase()), a = new Set(e), J = new Set(e.map((k) => k.split("-")[0])), g = G.filter((k) => {
140
- const q = k.code.toLowerCase();
141
- return !!(a.has(q) || !q.includes("-") && J.has(q));
139
+ return K;
140
+ const e = h.map((_) => _.toLowerCase()), a = new Set(e), q = new Set(e.map((_) => _.split("-")[0])), g = K.filter((_) => {
141
+ const X = _.code.toLowerCase();
142
+ return !!(a.has(X) || !X.includes("-") && q.has(X));
142
143
  });
143
144
  return process.env.NODE_ENV !== "production" && g.length === 0 && console.warn(
144
145
  `[Nice2Dev] <NiceLanguagePicker> received \`allowedCodes\` but none matched any entry in the language list. Picker will render empty. Got codes: ${JSON.stringify(h)}. Tip: pass canonical BCP-47 primary tags (e.g. \`pl\`, not \`pl-PL\`).`
145
146
  ), g;
146
- }, [G, h]), K = D(() => {
147
- if (!P?.length)
147
+ }, [K, h]), U = R(() => {
148
+ if (!x?.length)
148
149
  return l;
149
- const e = new Set(P), a = l.filter((g) => e.has(g.code)), J = l.filter((g) => !e.has(g.code));
150
- return [...a, ...J];
151
- }, [l, P]), I = D(() => {
150
+ const e = new Set(x), a = l.filter((g) => e.has(g.code)), q = l.filter((g) => !e.has(g.code));
151
+ return [...a, ...q];
152
+ }, [l, x]), E = R(() => {
152
153
  if (!p)
153
- return K;
154
+ return U;
154
155
  const e = p.toLowerCase();
155
- return K.filter(
156
+ return U.filter(
156
157
  (a) => a.nativeName.toLowerCase().includes(e) || a.englishName.toLowerCase().includes(e) || a.code.toLowerCase().includes(e)
157
158
  );
158
- }, [K, p]), s = D(() => C ? l.find((e) => e.code === C) ?? null : null, [C, l]), U = he && l.length >= Ne;
159
- de(() => {
159
+ }, [U, p]), s = R(() => C ? l.find((e) => e.code === C) ?? null : null, [C, l]), z = Ne && l.length >= fe;
160
+ ue(() => {
160
161
  if (!i)
161
162
  return;
162
163
  const e = (a) => {
163
- T.current && !T.current.contains(a.target) && (c(!1), E(""));
164
+ G.current && !G.current.contains(a.target) && (c(!1), b(""));
164
165
  };
165
166
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
166
167
  }, [i, c]);
167
- const te = _(
168
+ const ce = k(
168
169
  (e) => {
169
- d === void 0 && ne(e.code), w?.(e), c(!1), E("");
170
+ d === void 0 && ie(e.code), w?.(e), c(!1), b("");
170
171
  },
171
172
  [d, w, c]
172
- ), O = _(() => {
173
- d === void 0 && ne(void 0), w?.(null);
174
- }, [d, w]), Te = _(
173
+ ), O = k(() => {
174
+ d === void 0 && ie(void 0), w?.(null);
175
+ }, [d, w]), Ge = k(
175
176
  (e) => {
176
177
  e.stopPropagation(), O();
177
178
  },
178
179
  [O]
179
- ), V = $e && !!s && !m && !B, H = b(null), oe = _(() => {
180
- c(!1), E("");
180
+ ), V = Le && !!s && !m && !F, H = D(null), se = k(() => {
181
+ c(!1), b("");
181
182
  }, [c]), {
182
183
  activeIndex: M,
183
- setActiveIndex: z,
184
- handleKeyDown: ce
185
- } = Me(I, {
184
+ setActiveIndex: j,
185
+ handleKeyDown: re
186
+ } = Me(E, {
186
187
  open: i,
187
- onSelect: (e) => te(e),
188
- onClose: oe,
189
- onOpen: () => !m && !B && c(!0),
188
+ onSelect: (e) => ce(e),
189
+ onClose: se,
190
+ onOpen: () => !m && !F && c(!0),
190
191
  intentRef: H
191
- }), Ge = (e) => {
192
+ }), Ke = (e) => {
192
193
  if ((e.key === "Delete" || e.key === "Backspace") && V && !i) {
193
194
  e.preventDefault(), O();
194
195
  return;
195
196
  }
196
- ce(e);
197
+ re(e);
197
198
  };
198
199
  Oe(H, {
199
200
  open: i,
200
201
  modal: !1,
201
- initialFocus: U ? ee : "none",
202
- onClose: oe
203
- }), de(() => {
204
- z(0);
205
- }, [p, z]);
206
- const se = Ve(), v = `${se}-listbox`, y = i && I[M] ? `${v}-${M}` : void 0;
202
+ initialFocus: z ? ae : "none",
203
+ onClose: se
204
+ }), ue(() => {
205
+ j(0);
206
+ }, [p, j]);
207
+ const le = Ve(), v = `${le}-listbox`, y = i && E[M] ? `${v}-${M}` : void 0;
207
208
  He(() => {
208
209
  y && document.getElementById(y)?.scrollIntoView?.({ block: "nearest" });
209
210
  }, [y]);
210
- const j = (e) => _e === "english" ? e.englishName : e.nativeName, re = De ?? `${se}-trigger`, Ke = Re ?? (!!x || (s ? ae : !r) ? void 0 : s ? u("languagePicker.ariaLabelValue", "Language: {name}").replace(
211
+ const J = (e) => we === "english" ? e.englishName : e.nativeName, de = Re ?? `${le}-trigger`, Ue = Ae ?? (!!B || (s ? oe : !r) ? void 0 : s ? u("languagePicker.ariaLabelValue", "Language: {name}").replace(
211
212
  "{name}",
212
- j(s)
213
+ J(s)
213
214
  ) : u("languagePicker.ariaLabel", "Language"));
214
- return /* @__PURE__ */ t(
215
+ return /* @__PURE__ */ o(
215
216
  "div",
216
217
  {
217
- ref: T,
218
- className: `nice-field nice-field--${Y} nice-field--language-picker ${be === "left" ? "nice-field--label-left" : ""} ${N === "right" ? "nice-field--error-right" : ""} ${o ? "nice-field--error" : ""} ${F ? "nice-field--loading" : ""} nice-country-picker nice-language-picker nice-country-picker--${Y} ${r ? "nice-country-picker--compact" : ""} ${A === "ghost" ? "nice-country-picker--ghost" : ""} ${i ? "nice-country-picker--open" : ""} ${m ? "nice-country-picker--disabled" : ""} ${Le}`,
218
+ ref: G,
219
+ className: `nice-field nice-field--${ee} nice-field--language-picker ${De === "left" ? "nice-field--label-left" : ""} ${N === "right" ? "nice-field--error-right" : ""} ${t ? "nice-field--error" : ""} ${T ? "nice-field--loading" : ""} nice-country-picker nice-language-picker nice-country-picker--${ee} ${r ? "nice-country-picker--compact" : ""} ${P === "ghost" ? "nice-country-picker--ghost" : ""} ${i ? "nice-country-picker--open" : ""} ${m ? "nice-country-picker--disabled" : ""} ${be}`,
219
220
  style: {
220
221
  ...Ee,
221
222
  ...$ != null && {
@@ -226,66 +227,69 @@ const je = [
226
227
  }
227
228
  },
228
229
  "data-testid": f,
229
- "aria-busy": F || void 0,
230
+ "aria-busy": T || void 0,
230
231
  children: [
231
- x && /* @__PURE__ */ t("label", { className: "nice-field__label", htmlFor: re, children: [
232
- x,
232
+ B && /* @__PURE__ */ o("label", { className: "nice-field__label", htmlFor: de, children: [
233
+ B,
233
234
  Ie && /* @__PURE__ */ n("span", { className: "nice-field__required", children: "*" })
234
235
  ] }),
235
- /* @__PURE__ */ t("div", { className: "nice-field__control", children: [
236
- /* @__PURE__ */ t(
236
+ /* @__PURE__ */ o("div", { className: "nice-field__control", children: [
237
+ /* @__PURE__ */ o(
237
238
  "button",
238
239
  {
239
- ref: W,
240
+ ref: ne,
240
241
  type: "button",
241
242
  className: "nice-country-picker__trigger",
242
243
  onClick: (e) => {
243
- m || B || (e.stopPropagation(), c(!i));
244
+ m || F || (e.stopPropagation(), c(!i));
244
245
  },
245
- onKeyDown: Ge,
246
+ onKeyDown: Ke,
246
247
  disabled: m,
247
- id: re,
248
- "aria-label": Ke,
248
+ id: de,
249
+ "aria-label": Ue,
249
250
  role: "combobox",
250
251
  "aria-keyshortcuts": V ? "Delete" : void 0,
251
252
  "aria-haspopup": "listbox",
252
253
  "aria-expanded": i,
253
254
  "aria-controls": i ? v : void 0,
254
- "aria-activedescendant": U ? void 0 : y,
255
- "aria-invalid": o ? !0 : void 0,
255
+ "aria-activedescendant": z ? void 0 : y,
256
+ "aria-invalid": t ? !0 : void 0,
256
257
  "data-testid": `${f}-trigger`,
257
258
  children: [
258
- s ? /* @__PURE__ */ t("span", { className: "nice-country-picker__value", children: [
259
- fe && /* @__PURE__ */ n("span", { className: "nice-country-picker__flag", "aria-hidden": "true", children: /* @__PURE__ */ n(ue, { code: s.flagCountryCode }) }),
260
- ae && /* @__PURE__ */ n("span", { className: "nice-country-picker__name", children: j(s) }),
261
- Be && /* @__PURE__ */ t("span", { className: "nice-country-picker__dial-code", children: [
259
+ s ? /* @__PURE__ */ o("span", { className: "nice-country-picker__value", children: [
260
+ pe && /* @__PURE__ */ n("span", { className: "nice-country-picker__flag", "aria-hidden": "true", children: W === "globe" ? /* @__PURE__ */ n(I, { name: "globe", size: 18 }) : /* @__PURE__ */ n(ge, { code: s.flagCountryCode }) }),
261
+ oe && /* @__PURE__ */ n("span", { className: "nice-country-picker__name", children: J(s) }),
262
+ Fe && /* @__PURE__ */ o("span", { className: "nice-country-picker__dial-code", children: [
262
263
  "(",
263
264
  s.code,
264
265
  ")"
265
266
  ] })
266
- ] }) : /* @__PURE__ */ n("span", { className: "nice-country-picker__placeholder", children: r ? "" : me ?? u("controls.select", "Select language") }),
267
- /* @__PURE__ */ t("span", { className: "nice-country-picker__icons", children: [
267
+ ] }) : /* @__PURE__ */ o("span", { className: "nice-country-picker__placeholder", children: [
268
+ W === "globe" && /* @__PURE__ */ n("span", { className: "nice-country-picker__flag", "aria-hidden": "true", children: /* @__PURE__ */ n(I, { name: "globe", size: 18 }) }),
269
+ r ? "" : he ?? u("controls.select", "Select language")
270
+ ] }),
271
+ /* @__PURE__ */ o("span", { className: "nice-country-picker__icons", children: [
268
272
  V && // the pointer's shortcut for Delete / Backspace on the trigger
269
273
  /* @__PURE__ */ n(
270
274
  "span",
271
275
  {
272
276
  className: "nice-country-picker__clear",
273
- onClick: Te,
277
+ onClick: Ge,
274
278
  role: "presentation",
275
- children: /* @__PURE__ */ n(le, { name: "close", size: 14 })
279
+ children: /* @__PURE__ */ n(I, { name: "close", size: 14 })
276
280
  }
277
281
  ),
278
- A !== "ghost" && /* @__PURE__ */ n("span", { className: "nice-country-picker__arrow", children: /* @__PURE__ */ n(le, { name: i ? "chevron-up" : "chevron-down", size: 16 }) })
282
+ P !== "ghost" && /* @__PURE__ */ n("span", { className: "nice-country-picker__arrow", children: /* @__PURE__ */ n(I, { name: i ? "chevron-up" : "chevron-down", size: 16 }) })
279
283
  ] })
280
284
  ]
281
285
  }
282
286
  ),
283
- i && /* @__PURE__ */ t(
287
+ i && /* @__PURE__ */ o(
284
288
  "div",
285
289
  {
286
- className: `nice-country-picker__dropdown nice-country-picker__dropdown--align-${Fe}`,
290
+ className: `nice-country-picker__dropdown nice-country-picker__dropdown--align-${Te}`,
287
291
  style: r ? {
288
- minWidth: `${ie}px`,
292
+ minWidth: `${te}px`,
289
293
  maxWidth: "calc(100vw - 16px)"
290
294
  } : void 0,
291
295
  role: "listbox",
@@ -293,16 +297,16 @@ const je = [
293
297
  id: v,
294
298
  "data-testid": `${f}-dropdown`,
295
299
  children: [
296
- U && /* @__PURE__ */ n("div", { className: "nice-country-picker__search", children: /* @__PURE__ */ n(
300
+ z && /* @__PURE__ */ n("div", { className: "nice-country-picker__search", children: /* @__PURE__ */ n(
297
301
  "input",
298
302
  {
299
- ref: ee,
303
+ ref: ae,
300
304
  type: "text",
301
305
  value: p,
302
- onChange: (e) => E(e.target.value),
303
- onKeyDown: ce,
304
- placeholder: Z ?? u("languagePicker.filter", "Filter languages…"),
305
- "aria-label": Z ?? u("languagePicker.filter", "Filter languages…"),
306
+ onChange: (e) => b(e.target.value),
307
+ onKeyDown: re,
308
+ placeholder: Q ?? u("languagePicker.filter", "Filter languages…"),
309
+ "aria-label": Q ?? u("languagePicker.filter", "Filter languages…"),
306
310
  "aria-controls": v,
307
311
  "aria-activedescendant": y,
308
312
  "aria-autocomplete": "list",
@@ -310,21 +314,21 @@ const je = [
310
314
  "data-testid": `${f}-search`
311
315
  }
312
316
  ) }),
313
- /* @__PURE__ */ n("div", { className: "nice-country-picker__list", children: I.length === 0 ? /* @__PURE__ */ n("div", { className: "nice-country-picker__empty", children: u("noData", "No languages found") }) : I.map((e, a) => (
317
+ /* @__PURE__ */ n("div", { className: "nice-country-picker__list", children: E.length === 0 ? /* @__PURE__ */ n("div", { className: "nice-country-picker__empty", children: u("noData", "No languages found") }) : E.map((e, a) => (
314
318
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events -- keys: the combobox (aria-activedescendant)
315
- /* @__PURE__ */ t(
319
+ /* @__PURE__ */ o(
316
320
  "div",
317
321
  {
318
322
  id: `${v}-${a}`,
319
323
  className: `nice-country-picker__option ${e.code === C ? "nice-country-picker__option--selected" : ""} ${a === M ? "nice-country-picker__option--highlighted" : ""}`,
320
- onClick: () => te(e),
321
- onMouseEnter: () => z(a),
324
+ onClick: () => ce(e),
325
+ onMouseEnter: () => j(a),
322
326
  role: "option",
323
327
  "aria-selected": e.code === C,
324
328
  "data-testid": `${f}-option-${e.code}`,
325
329
  children: [
326
- pe && /* @__PURE__ */ n("span", { className: "nice-country-picker__flag", "aria-hidden": "true", children: /* @__PURE__ */ n(ue, { code: e.flagCountryCode }) }),
327
- ve && /* @__PURE__ */ n("span", { className: "nice-country-picker__name", children: j(e) }),
330
+ Ce && /* @__PURE__ */ n("span", { className: "nice-country-picker__flag", "aria-hidden": "true", children: /* @__PURE__ */ n(ge, { code: e.flagCountryCode }) }),
331
+ ye && /* @__PURE__ */ n("span", { className: "nice-country-picker__name", children: J(e) }),
328
332
  ke && /* @__PURE__ */ n("span", { className: "nice-country-picker__dial-code", children: e.code })
329
333
  ]
330
334
  },
@@ -334,18 +338,18 @@ const je = [
334
338
  ]
335
339
  }
336
340
  ),
337
- F && /* @__PURE__ */ n("span", { className: "nice-field__spinner", children: /* @__PURE__ */ n("span", { className: "nice-spinner nice-spinner--sm" }) }),
338
- N === "right" && o && /* @__PURE__ */ n("div", { className: "nice-field__error", role: "alert", children: o }),
339
- N === "right" && !o && S && /* @__PURE__ */ n("div", { className: "nice-field__helper", children: S })
341
+ T && /* @__PURE__ */ n("span", { className: "nice-field__spinner", children: /* @__PURE__ */ n("span", { className: "nice-spinner nice-spinner--sm" }) }),
342
+ N === "right" && t && /* @__PURE__ */ n("div", { className: "nice-field__error", role: "alert", children: t }),
343
+ N === "right" && !t && S && /* @__PURE__ */ n("div", { className: "nice-field__helper", children: S })
340
344
  ] }),
341
- N !== "right" && o && /* @__PURE__ */ n("div", { className: "nice-field__error", role: "alert", children: o }),
342
- N !== "right" && !o && S && /* @__PURE__ */ n("div", { className: "nice-field__helper", children: S })
345
+ N !== "right" && t && /* @__PURE__ */ n("div", { className: "nice-field__error", role: "alert", children: t }),
346
+ N !== "right" && !t && S && /* @__PURE__ */ n("div", { className: "nice-field__helper", children: S })
343
347
  ]
344
348
  }
345
349
  );
346
350
  };
347
- process.env.NODE_ENV !== "production" && (Je.displayName = "NiceLanguagePicker");
351
+ process.env.NODE_ENV !== "production" && (qe.displayName = "NiceLanguagePicker");
348
352
  export {
349
- je as LANGUAGES,
350
- Je as NiceLanguagePicker
353
+ Je as LANGUAGES,
354
+ qe as NiceLanguagePicker
351
355
  };
@@ -64,7 +64,7 @@ const Ge = (t, v) => {
64
64
  P === void 0 && Pe(r), Y?.(r);
65
65
  },
66
66
  [c, P, Y]
67
- ), [k, D] = G(""), ce = Ne ?? (!l && R !== "ghost"), Re = Z ?? (l ? 24 : 28), Se = Z ?? 32, re = l ? 320 : 280, Oe = qe(
67
+ ), [k, D] = G(""), ce = Ne ?? (!l && R !== "ghost"), Re = Z ?? (l ? 24 : 28), Se = Z ?? 40, re = l ? 320 : 280, Oe = qe(
68
68
  c,
69
69
  ne,
70
70
  we ?? (l ? "auto" : "left"),