@nubisco/ui 5.14.0 → 5.15.1

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,408 +0,0 @@
1
- import { t as e } from "./Icon-rREAqsu0.js";
2
- import { t } from "./Label-CiWiUQ_H.js";
3
- import { t as n } from "./Message-SQvoXiWl.js";
4
- import { t as r } from "./Grid-DA2jibMM.js";
5
- import { useMenuSurface as i } from "./composables/useMenuSurface.composable.mjs";
6
- import { Fragment as a, Teleport as ee, computed as o, createBlock as s, createCommentVNode as c, createElementBlock as l, createElementVNode as u, createTextVNode as d, createVNode as f, defineComponent as p, nextTick as m, normalizeClass as h, normalizeStyle as te, onBeforeUnmount as ne, openBlock as g, ref as _, renderList as v, renderSlot as y, toDisplayString as b, unref as x, useId as re, vModelText as ie, watch as ae, withCtx as S, withDirectives as oe, withKeys as se, withModifiers as C } from "vue";
7
- import { regular as w } from "@nubisco/ui/icons/caret-down";
8
- import { regular as T } from "@nubisco/ui/icons/caret-up";
9
- //#region src/components/Select.vue?vue&type=script&setup=true&lang.ts
10
- var ce = [
11
- "id",
12
- "aria-expanded",
13
- "aria-disabled",
14
- "aria-required",
15
- "disabled"
16
- ], le = [
17
- "id",
18
- "aria-expanded",
19
- "aria-disabled",
20
- "aria-required",
21
- "disabled"
22
- ], ue = {
23
- key: 1,
24
- class: "nb-select__inner-label"
25
- }, de = {
26
- key: 0,
27
- class: "nb-select__asterisk",
28
- "aria-hidden": "true"
29
- }, fe = ["aria-multiselectable"], pe = [
30
- "aria-selected",
31
- "aria-disabled",
32
- "onMouseenter",
33
- "onClick"
34
- ], me = {
35
- key: 0,
36
- class: "nb-select__option-check",
37
- "aria-hidden": "true"
38
- }, he = {
39
- key: 0,
40
- viewBox: "0 0 10 8",
41
- fill: "none",
42
- width: "10",
43
- height: "8"
44
- }, E = { class: "nb-select__option-label" }, D = {
45
- key: 0,
46
- class: "nb-select__empty"
47
- }, O = ["placeholder", "onKeydown"], k = /* @__PURE__ */ p({
48
- __name: "Select",
49
- props: {
50
- modelValue: { default: null },
51
- options: { default: () => [] },
52
- multiple: {
53
- type: Boolean,
54
- default: !1
55
- },
56
- creatable: {
57
- type: Boolean,
58
- default: !1
59
- },
60
- createPlaceholder: { default: "" },
61
- placeholder: { default: "Select…" },
62
- name: { default: "" },
63
- disabled: {
64
- type: Boolean,
65
- default: !1
66
- },
67
- required: {
68
- type: Boolean,
69
- default: !1
70
- },
71
- id: { default: void 0 },
72
- label: { default: "" },
73
- error: { default: "" },
74
- warning: { default: "" },
75
- helper: { default: "" },
76
- variant: { default: "default" },
77
- size: { default: "md" }
78
- },
79
- emits: [
80
- "update:modelValue",
81
- "change",
82
- "create"
83
- ],
84
- setup(p, { expose: k, emit: A }) {
85
- let j = p, M = A, N = _("");
86
- function ge() {
87
- let e = N.value.trim();
88
- e && (M("create", e), N.value = "");
89
- }
90
- let P = _(!1), F = _(!1), I = _(-1), L = _(null), R = _(null), z = _(null);
91
- i(z);
92
- let B = _({
93
- position: "fixed",
94
- top: "0px",
95
- left: "0px",
96
- width: "0px",
97
- zIndex: "9999"
98
- }), _e = `nb-select-${re()}`, V = o(() => j.id ?? _e), H = o(() => j.modelValue == null ? [] : Array.isArray(j.modelValue) ? j.modelValue : [j.modelValue]), U = o(() => {
99
- if (!(j.multiple || H.value.length !== 1)) return (j.options ?? []).find((e) => e.value === H.value[0])?.icon;
100
- }), W = o(() => {
101
- if (H.value.length === 0) return "";
102
- let e = j.options ?? [];
103
- return j.multiple ? H.value.length === 1 ? e.find((e) => e.value === H.value[0])?.label ?? String(H.value[0]) : H.value.length === 2 ? H.value.map((t) => e.find((e) => e.value === t)?.label ?? String(t)).join(", ") : `${H.value.length} selected` : e.find((e) => e.value === H.value[0])?.label ?? String(H.value[0]);
104
- });
105
- function G(e) {
106
- return H.value.includes(e);
107
- }
108
- function K(e) {
109
- if (e.disabled) return;
110
- let t;
111
- if (j.multiple) {
112
- let n = [...H.value], r = n.indexOf(e.value);
113
- r >= 0 ? n.splice(r, 1) : n.push(e.value), t = n;
114
- } else t = e.value, Y();
115
- M("update:modelValue", t), M("change", t);
116
- }
117
- function q() {
118
- if (!R.value) return;
119
- let e = R.value.getBoundingClientRect(), t = z.value?.offsetHeight ?? 0, n = window.innerHeight - e.bottom, r = e.top;
120
- B.value = {
121
- position: "fixed",
122
- top: t > 0 && n < t && r > n ? `${e.top - t}px` : `${e.bottom}px`,
123
- left: `${e.left}px`,
124
- width: `${e.width}px`,
125
- zIndex: "9999"
126
- };
127
- }
128
- function J() {
129
- if (j.disabled) return;
130
- P.value = !0, q();
131
- let e = j.options ?? [];
132
- I.value = H.value.length > 0 ? Math.max(0, e.findIndex((e) => e.value === H.value[0])) : -1, m(() => {
133
- q(), $();
134
- });
135
- }
136
- function Y() {
137
- P.value = !1, I.value = -1;
138
- }
139
- function X() {
140
- P.value ? Y() : J();
141
- }
142
- function Z(e) {
143
- let t = e.target, n = L.value?.contains(t) ?? !1, r = z.value?.contains(t) ?? !1;
144
- !n && !r && Y();
145
- }
146
- function Q() {
147
- P.value && q();
148
- }
149
- ae(P, (e) => {
150
- e ? (document.addEventListener("mousedown", Z), window.addEventListener("scroll", Q, !0), window.addEventListener("resize", Q)) : (document.removeEventListener("mousedown", Z), window.removeEventListener("scroll", Q, !0), window.removeEventListener("resize", Q));
151
- }), ne(() => {
152
- document.removeEventListener("mousedown", Z), window.removeEventListener("scroll", Q, !0), window.removeEventListener("resize", Q);
153
- });
154
- function ve(e) {
155
- let t = j.options ?? [];
156
- if (!P.value) {
157
- (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && (e.preventDefault(), J());
158
- return;
159
- }
160
- e.key === "Escape" ? (Y(), e.preventDefault()) : e.key === "Tab" ? Y() : e.key === "ArrowDown" ? (e.preventDefault(), I.value = Math.min(I.value + 1, t.length - 1), $()) : e.key === "ArrowUp" ? (e.preventDefault(), I.value = Math.max(I.value - 1, 0), $()) : (e.key === "Enter" || e.key === " ") && I.value >= 0 && (e.preventDefault(), K(t[I.value]));
161
- }
162
- function $() {
163
- m(() => {
164
- !z.value || I.value < 0 || z.value.querySelectorAll(".nb-select__option")[I.value]?.scrollIntoView({ block: "nearest" });
165
- });
166
- }
167
- let ye = o(() => [
168
- "nb-select",
169
- `nb-select--${j.variant}`,
170
- `nb-select--${j.size}`,
171
- {
172
- "nb-select--open": P.value,
173
- "nb-select--focused": F.value && !P.value,
174
- "nb-select--error": !!j.error,
175
- "nb-select--warning": !j.error && !!j.warning,
176
- "nb-select--multiple": j.multiple
177
- }
178
- ]);
179
- return k({
180
- open: J,
181
- close: Y
182
- }), (i, o) => (g(), l(a, null, [u("div", {
183
- ref_key: "rootRef",
184
- ref: L,
185
- class: h(ye.value),
186
- onKeydown: ve
187
- }, [p.variant === "default" ? (g(), l(a, { key: 0 }, [
188
- i.$slots.label ? y(i.$slots, "label", { key: 0 }) : p.label ? (g(), s(t, {
189
- key: 1,
190
- for: V.value,
191
- required: p.required,
192
- disabled: p.disabled
193
- }, {
194
- default: S(() => [d(b(p.label), 1)]),
195
- _: 1
196
- }, 8, [
197
- "for",
198
- "required",
199
- "disabled"
200
- ])) : c("", !0),
201
- u("button", {
202
- id: V.value,
203
- ref_key: "triggerRef",
204
- ref: R,
205
- type: "button",
206
- class: "nb-select__trigger",
207
- role: "combobox",
208
- "aria-expanded": P.value,
209
- "aria-haspopup": "listbox",
210
- "aria-disabled": p.disabled || void 0,
211
- "aria-required": p.required || void 0,
212
- disabled: p.disabled || void 0,
213
- onClick: X,
214
- onFocus: o[0] ||= (e) => F.value = !0,
215
- onBlur: o[1] ||= (e) => F.value = !1
216
- }, [
217
- u("span", { class: h(["nb-select__value", {
218
- "nb-select__value--placeholder": !W.value,
219
- "nb-select__value--with-icon": !!U.value
220
- }]) }, [U.value ? (g(), s(e, {
221
- key: 0,
222
- class: "nb-select__value-icon",
223
- name: U.value,
224
- size: 16
225
- }, null, 8, ["name"])) : c("", !0), W.value ? y(i.$slots, "value", {
226
- key: 1,
227
- values: H.value
228
- }, () => [d(b(W.value), 1)]) : (g(), l(a, { key: 2 }, [d(b(p.placeholder), 1)], 64))], 2),
229
- p.error ? (g(), s(n, {
230
- key: 0,
231
- variant: "error",
232
- "icon-only": !0,
233
- class: "nb-select__status-icon"
234
- }, {
235
- default: S(() => [d(b(p.error), 1)]),
236
- _: 1
237
- })) : p.warning ? (g(), s(n, {
238
- key: 1,
239
- variant: "warning",
240
- "icon-only": !0,
241
- class: "nb-select__status-icon"
242
- }, {
243
- default: S(() => [d(b(p.warning), 1)]),
244
- _: 1
245
- })) : c("", !0),
246
- f(r, {
247
- align: "center",
248
- justify: "center",
249
- class: "nb-select__caret"
250
- }, {
251
- default: S(() => [f(e, {
252
- name: P.value ? x(T) : x(w),
253
- size: 16
254
- }, null, 8, ["name"])]),
255
- _: 1
256
- })
257
- ], 40, ce),
258
- p.error ? (g(), s(n, {
259
- key: 2,
260
- variant: "error",
261
- class: "nb-select__message"
262
- }, {
263
- default: S(() => [d(b(p.error), 1)]),
264
- _: 1
265
- })) : p.warning ? (g(), s(n, {
266
- key: 3,
267
- variant: "warning",
268
- class: "nb-select__message"
269
- }, {
270
- default: S(() => [d(b(p.warning), 1)]),
271
- _: 1
272
- })) : p.helper ? (g(), s(n, {
273
- key: 4,
274
- variant: "helper",
275
- class: "nb-select__message"
276
- }, {
277
- default: S(() => [d(b(p.helper), 1)]),
278
- _: 1
279
- })) : c("", !0)
280
- ], 64)) : p.variant === "fluid" ? (g(), l(a, { key: 1 }, [u("button", {
281
- id: V.value,
282
- ref_key: "triggerRef",
283
- ref: R,
284
- type: "button",
285
- class: "nb-select__trigger",
286
- role: "combobox",
287
- "aria-expanded": P.value,
288
- "aria-haspopup": "listbox",
289
- "aria-disabled": p.disabled || void 0,
290
- "aria-required": p.required || void 0,
291
- disabled: p.disabled || void 0,
292
- onClick: X,
293
- onFocus: o[2] ||= (e) => F.value = !0,
294
- onBlur: o[3] ||= (e) => F.value = !1
295
- }, [p.label || i.$slots.label ? (g(), s(r, {
296
- key: 0,
297
- dir: "row",
298
- align: "center",
299
- gap: "xs",
300
- class: "nb-select__inner-header"
301
- }, {
302
- default: S(() => [i.$slots.label ? y(i.$slots, "label", { key: 0 }) : (g(), l("label", ue, [d(b(p.label) + " ", 1), p.required ? (g(), l("span", de, "*")) : c("", !0)])), p.helper && !p.error && !p.warning ? (g(), s(n, {
303
- key: 2,
304
- variant: "helper",
305
- "icon-only": !0,
306
- class: "nb-select__inner-message"
307
- }, {
308
- default: S(() => [d(b(p.helper), 1)]),
309
- _: 1
310
- })) : c("", !0)]),
311
- _: 3
312
- })) : c("", !0), f(r, {
313
- dir: "row",
314
- align: "end",
315
- flex: "",
316
- class: "nb-select__value-row"
317
- }, {
318
- default: S(() => [u("span", { class: h(["nb-select__value", {
319
- "nb-select__value--placeholder": !W.value,
320
- "nb-select__value--with-icon": !!U.value
321
- }]) }, [U.value ? (g(), s(e, {
322
- key: 0,
323
- class: "nb-select__value-icon",
324
- name: U.value,
325
- size: 16
326
- }, null, 8, ["name"])) : c("", !0), W.value ? y(i.$slots, "value", {
327
- key: 1,
328
- values: H.value
329
- }, () => [d(b(W.value), 1)]) : (g(), l(a, { key: 2 }, [d(b(p.placeholder), 1)], 64))], 2), f(r, {
330
- align: "center",
331
- justify: "center",
332
- class: "nb-select__caret"
333
- }, {
334
- default: S(() => [f(e, {
335
- name: P.value ? x(T) : x(w),
336
- size: 16
337
- }, null, 8, ["name"])]),
338
- _: 1
339
- })]),
340
- _: 3
341
- })], 40, le), p.error ? (g(), s(n, {
342
- key: 0,
343
- variant: "error",
344
- class: "nb-select__fluid-message"
345
- }, {
346
- default: S(() => [d(b(p.error), 1)]),
347
- _: 1
348
- })) : p.warning ? (g(), s(n, {
349
- key: 1,
350
- variant: "warning",
351
- class: "nb-select__fluid-message"
352
- }, {
353
- default: S(() => [d(b(p.warning), 1)]),
354
- _: 1
355
- })) : c("", !0)], 64)) : c("", !0)], 34), (g(), s(ee, { to: "body" }, [P.value ? (g(), l("div", {
356
- key: 0,
357
- ref_key: "dropdownRef",
358
- ref: z,
359
- class: "nb-select__dropdown",
360
- style: te(B.value),
361
- role: "listbox",
362
- "aria-multiselectable": p.multiple || void 0
363
- }, [
364
- (g(!0), l(a, null, v(p.options, (t, n) => (g(), l("div", {
365
- key: t.value,
366
- class: h(["nb-select__option", {
367
- "nb-select__option--selected": G(t.value),
368
- "nb-select__option--highlighted": I.value === n,
369
- "nb-select__option--disabled": t.disabled
370
- }]),
371
- role: "option",
372
- "aria-selected": G(t.value),
373
- "aria-disabled": t.disabled || void 0,
374
- onMouseenter: (e) => I.value = n,
375
- onClick: (e) => K(t)
376
- }, [
377
- p.multiple ? (g(), l("span", me, [G(t.value) ? (g(), l("svg", he, [...o[7] ||= [u("path", {
378
- d: "M1 4l3 3 5-6",
379
- stroke: "currentColor",
380
- "stroke-width": "1.5",
381
- "stroke-linecap": "round",
382
- "stroke-linejoin": "round"
383
- }, null, -1)]])) : c("", !0)])) : c("", !0),
384
- t.icon ? (g(), s(e, {
385
- key: 1,
386
- class: "nb-select__option-icon",
387
- name: t.icon,
388
- size: 16
389
- }, null, 8, ["name"])) : c("", !0),
390
- u("span", E, [y(i.$slots, "option", { option: t }, () => [d(b(t.label), 1)])])
391
- ], 42, pe))), 128)),
392
- !p.options || p.options.length === 0 ? (g(), l("div", D, " No options ")) : c("", !0),
393
- p.creatable ? (g(), l("div", {
394
- key: 1,
395
- class: "nb-select__create",
396
- onMousedown: o[6] ||= C(() => {}, ["prevent"])
397
- }, [oe(u("input", {
398
- "onUpdate:modelValue": o[4] ||= (e) => N.value = e,
399
- type: "text",
400
- class: "nb-select__create-input",
401
- placeholder: p.createPlaceholder || "Add new…",
402
- onKeydown: [se(C(ge, ["prevent"]), ["enter"]), o[5] ||= C(() => {}, ["stop"])]
403
- }, null, 40, O), [[ie, N.value]])], 32)) : c("", !0)
404
- ], 12, fe)) : c("", !0)]))], 64));
405
- }
406
- });
407
- //#endregion
408
- export { k as t };