@uva-glass/component-library 3.27.1 → 3.27.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.
- package/dist/assets/MultiSelectBox.css +1 -1
- package/dist/assets/TextArea.css +1 -1
- package/dist/components/MultiSelectBox/MultiSelectBox.d.ts +3 -1
- package/dist/components/MultiSelectBox/MultiSelectBox.js +82 -78
- package/dist/components/MultiSelectBox/MultiSelectBox.js.map +1 -1
- package/dist/components/SelectListbox/SelectListBox.stories.js +5 -0
- package/dist/components/SelectListbox/SelectListBox.stories.js.map +1 -1
- package/dist/components/SelectListbox/SelectProvider.js +24 -33
- package/dist/components/SelectListbox/SelectProvider.js.map +1 -1
- package/dist/components/TextArea/TextArea.js +14 -14
- package/package.json +1 -1
|
@@ -1,50 +1,41 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as g, useContext as
|
|
3
|
-
const
|
|
4
|
-
const [
|
|
5
|
-
|
|
6
|
-
},
|
|
2
|
+
import { createContext as g, useContext as p, useState as l, useRef as C, useId as P } from "react";
|
|
3
|
+
const d = g({}), L = ({ options: e, defaultValue: o, children: i }) => {
|
|
4
|
+
const [c, v] = l({ value: "", label: "" }), [x, s] = l(!1), [f, r] = l(-1), I = C(P()), b = () => {
|
|
5
|
+
s((t) => !t);
|
|
6
|
+
}, u = (t) => e.find((n) => n.value === t) || {
|
|
7
7
|
value: -1,
|
|
8
8
|
label: "",
|
|
9
9
|
selectedLabel: "-"
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
}, a = (t) => {
|
|
11
|
+
const n = e.findIndex((S) => S.value === t.value);
|
|
12
|
+
r(n), v(t), s(!1);
|
|
13
13
|
};
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
const e = t.find((s) => s.value === l) || {
|
|
17
|
-
value: -1,
|
|
18
|
-
label: "",
|
|
19
|
-
selectedLabel: "-"
|
|
20
|
-
};
|
|
21
|
-
r(e);
|
|
22
|
-
}
|
|
23
|
-
}, [l]), /* @__PURE__ */ m(
|
|
24
|
-
a.Provider,
|
|
14
|
+
return o !== -1 && !c.value && a(u(o)), /* @__PURE__ */ m(
|
|
15
|
+
d.Provider,
|
|
25
16
|
{
|
|
26
17
|
value: {
|
|
27
|
-
options:
|
|
28
|
-
selectedValue:
|
|
29
|
-
setSelectedValue:
|
|
30
|
-
isOpen:
|
|
31
|
-
setIsOpen:
|
|
18
|
+
options: e,
|
|
19
|
+
selectedValue: c,
|
|
20
|
+
setSelectedValue: a,
|
|
21
|
+
isOpen: x,
|
|
22
|
+
setIsOpen: s,
|
|
32
23
|
toggleListbox: b,
|
|
33
|
-
getValue:
|
|
34
|
-
activeIndex:
|
|
35
|
-
setActiveIndex:
|
|
36
|
-
listboxId:
|
|
24
|
+
getValue: u,
|
|
25
|
+
activeIndex: f,
|
|
26
|
+
setActiveIndex: r,
|
|
27
|
+
listboxId: I.current
|
|
37
28
|
},
|
|
38
|
-
children:
|
|
29
|
+
children: i
|
|
39
30
|
}
|
|
40
31
|
);
|
|
41
32
|
}, O = () => {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
33
|
+
const e = p(d);
|
|
34
|
+
if (e === void 0) throw new Error("useSelect can only be used in an SelectProvider");
|
|
35
|
+
return e;
|
|
45
36
|
};
|
|
46
37
|
export {
|
|
47
|
-
|
|
38
|
+
L as SelectProvider,
|
|
48
39
|
O as useSelect
|
|
49
40
|
};
|
|
50
41
|
//# sourceMappingURL=SelectProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectProvider.js","sources":["../../../src/components/SelectListbox/SelectProvider.tsx"],"sourcesContent":["import { createContext, useContext, useState, useId, useRef
|
|
1
|
+
{"version":3,"file":"SelectProvider.js","sources":["../../../src/components/SelectListbox/SelectProvider.tsx"],"sourcesContent":["import { createContext, useContext, useState, useId, useRef } from 'react';\n\nimport type { PropsWithChildren } from 'react';\n\nexport type SelectValue = string | number | null;\n\nexport type OptionValue = {\n value: SelectValue;\n label: string;\n selectedLabel?: string;\n disabled?: boolean;\n};\nexport interface SelectListboxContext {\n options: OptionValue[];\n selectedValue: OptionValue;\n setSelectedValue: (v: OptionValue) => void;\n isOpen: boolean;\n setIsOpen: (v: boolean) => void;\n toggleListbox: () => void;\n getValue: (value: SelectValue) => OptionValue;\n activeIndex: number;\n setActiveIndex: (v: number) => void;\n listboxId: string;\n}\n\nconst SelectContext = createContext<SelectListboxContext>({} as SelectListboxContext);\n\ninterface Props {\n options: OptionValue[];\n defaultValue: SelectValue;\n}\n\nexport const SelectProvider = ({ options, defaultValue, children }: PropsWithChildren<Props>) => {\n const [value, setValue] = useState<OptionValue>({ value: '', label: '' });\n const [isOpen, setIsOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(-1);\n const listboxId = useRef<string>(useId());\n\n const toggleListbox = () => {\n setIsOpen((status) => !status);\n };\n\n const getValue = (value: SelectValue) => {\n return (\n options.find((option) => option.value === value) || {\n value: -1,\n label: '',\n selectedLabel: '-',\n }\n );\n };\n\n const setSelectedValue = (value: OptionValue) => {\n const selectedIndex = options.findIndex((option) => option.value === value.value);\n setActiveIndex(selectedIndex);\n setValue(value);\n setIsOpen(false);\n };\n\n if (defaultValue !== -1 && !value.value) {\n setSelectedValue(getValue(defaultValue));\n }\n\n return (\n <SelectContext.Provider\n value={{\n options,\n selectedValue: value,\n setSelectedValue,\n isOpen,\n setIsOpen,\n toggleListbox,\n getValue,\n activeIndex,\n setActiveIndex,\n listboxId: listboxId.current,\n }}\n >\n {children}\n </SelectContext.Provider>\n );\n};\n\nexport const useSelect = () => {\n const context = useContext(SelectContext);\n\n if (context === undefined) throw new Error('useSelect can only be used in an SelectProvider');\n\n return context;\n};\n"],"names":["SelectContext","createContext","SelectProvider","options","defaultValue","children","value","setValue","useState","isOpen","setIsOpen","activeIndex","setActiveIndex","listboxId","useRef","useId","toggleListbox","status","getValue","option","setSelectedValue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iD;AAErF,SAAAA;AACT;"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { jsxs as _, jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as x, useState as
|
|
3
|
-
import { c as
|
|
2
|
+
import { useRef as x, useState as p } from "react";
|
|
3
|
+
import { c as d } from "../../clsx-OuTLNxxd.js";
|
|
4
4
|
import '../../assets/TextArea.css';const r = {
|
|
5
|
-
"text-area__wrapper": "_text-
|
|
6
|
-
"text-area__header": "_text-
|
|
7
|
-
"text-area__label": "_text-
|
|
8
|
-
"text-area__word-count": "_text-area__word-
|
|
9
|
-
"text-area__word-count--alert": "_text-area__word-count--
|
|
10
|
-
"text-area": "_text-
|
|
5
|
+
"text-area__wrapper": "_text-area__wrapper_1pu93_1",
|
|
6
|
+
"text-area__header": "_text-area__header_1pu93_7",
|
|
7
|
+
"text-area__label": "_text-area__label_1pu93_13",
|
|
8
|
+
"text-area__word-count": "_text-area__word-count_1pu93_20",
|
|
9
|
+
"text-area__word-count--alert": "_text-area__word-count--alert_1pu93_25",
|
|
10
|
+
"text-area": "_text-area_1pu93_1"
|
|
11
11
|
};
|
|
12
|
-
function w({ onChange:
|
|
13
|
-
const e = x(null), [o,
|
|
14
|
-
e.current && (e.current.style.height = "auto", e.current.style.height = `${e.current.scrollHeight}px`,
|
|
12
|
+
function w({ onChange: u, label: a, maxCharacters: t = 0, defaultValue: c = "" }) {
|
|
13
|
+
const e = x(null), [o, l] = p(0), s = () => {
|
|
14
|
+
e.current && (e.current.style.height = "auto", e.current.style.height = `${e.current.scrollHeight}px`, l(e.current.value.length), u(e.current.value.trim()));
|
|
15
15
|
};
|
|
16
16
|
return /* @__PURE__ */ _("div", { className: r["text-area__wrapper"], children: [
|
|
17
17
|
(a || t > 0) && /* @__PURE__ */ _("div", { className: r["text-area__header"], children: [
|
|
18
18
|
a && /* @__PURE__ */ n("span", { className: r["text-area__label"], children: a }),
|
|
19
19
|
t > 0 && /* @__PURE__ */ _("div", { className: r["text-area__word-count"], children: [
|
|
20
|
-
/* @__PURE__ */ n("span", { className:
|
|
20
|
+
/* @__PURE__ */ n("span", { className: d({ [r["text-area__word-count--alert"]]: o === t }), children: o }),
|
|
21
21
|
" / ",
|
|
22
22
|
t
|
|
23
23
|
] })
|
|
@@ -28,8 +28,8 @@ function w({ onChange: c, label: a, maxCharacters: t = 0, defaultValue: l = "" }
|
|
|
28
28
|
ref: e,
|
|
29
29
|
className: r["text-area"],
|
|
30
30
|
maxLength: t > 0 ? t : void 0,
|
|
31
|
-
onInput:
|
|
32
|
-
defaultValue:
|
|
31
|
+
onInput: s,
|
|
32
|
+
defaultValue: c
|
|
33
33
|
}
|
|
34
34
|
)
|
|
35
35
|
] });
|