@uva-glass/component-library 3.39.0 → 3.39.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.
- package/dist/components/SelectListbox/components/SelectButton.js +43 -34
- package/dist/components/SelectListbox/components/SelectButton.js.map +1 -1
- package/dist/components/SelectListbox/components/SelectOption.js +40 -31
- package/dist/components/SelectListbox/components/SelectOption.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { c as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { s as
|
|
5
|
-
import { Icon as
|
|
6
|
-
import { useSelect as
|
|
7
|
-
const O =
|
|
8
|
-
const { variant:
|
|
9
|
-
|
|
1
|
+
import { jsx as c, jsxs as K } from "react/jsx-runtime";
|
|
2
|
+
import { c as m } from "../../../clsx-OuTLNxxd.js";
|
|
3
|
+
import { forwardRef as N, useRef as h, useEffect as u } from "react";
|
|
4
|
+
import { s as t } from "../../../SelectListbox.module-yzXaWwsm.js";
|
|
5
|
+
import { Icon as R } from "../../Icon/Icon.js";
|
|
6
|
+
import { useSelect as S } from "../SelectProvider.js";
|
|
7
|
+
const O = N((y, b) => {
|
|
8
|
+
const { variant: f, size: k = "default", onChange: o, buttonLabelProp: w = "label", buttonLabelBold: I, disabled: L = !1 } = y, l = h(null), i = h(!0), { listboxId: C, isOpen: e, selectedValue: s, toggleListbox: D, setIsOpen: n, setActiveIndex: p, options: d } = S() || {}, E = (r) => {
|
|
9
|
+
if (r.key.length === 1) {
|
|
10
|
+
const a = r.key.toLocaleLowerCase(), g = d.findIndex(
|
|
11
|
+
(x) => !x.disabled && x.label.toLocaleLowerCase().startsWith(a)
|
|
12
|
+
);
|
|
13
|
+
if (g !== -1) {
|
|
14
|
+
p(g), e || n(!0), r.preventDefault();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
switch (r.key) {
|
|
10
19
|
case "Enter":
|
|
11
|
-
if (
|
|
12
|
-
|
|
20
|
+
if (r.preventDefault(), !e) {
|
|
21
|
+
n(!0);
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
24
|
break;
|
|
16
25
|
case "Escape":
|
|
17
|
-
|
|
26
|
+
e && (r.stopPropagation(), p(d.findIndex((a) => a.value === s?.value)), n(!1));
|
|
18
27
|
break;
|
|
19
28
|
}
|
|
20
29
|
};
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
}, [
|
|
24
|
-
|
|
25
|
-
}), []),
|
|
26
|
-
|
|
27
|
-
}, [
|
|
30
|
+
return u(() => {
|
|
31
|
+
e ? (l.current?.children[0]).blur() : !i.current && (l.current?.children[0]).focus();
|
|
32
|
+
}, [e]), u(() => (i.current = !1, () => {
|
|
33
|
+
i.current = !0;
|
|
34
|
+
}), []), u(() => {
|
|
35
|
+
o && o(s);
|
|
36
|
+
}, [o, s]), /* @__PURE__ */ c("span", { ref: l, children: /* @__PURE__ */ K(
|
|
28
37
|
"button",
|
|
29
38
|
{
|
|
30
|
-
className:
|
|
31
|
-
[
|
|
32
|
-
[
|
|
39
|
+
className: m(t["select-listbox-trigger"], t[`select-listbox-trigger--${k}`], {
|
|
40
|
+
[t[`select-listbox-trigger--${f}`]]: f,
|
|
41
|
+
[t["select-listbox-trigger--bold"]]: I
|
|
33
42
|
}),
|
|
34
43
|
type: "button",
|
|
35
|
-
onClick:
|
|
36
|
-
onKeyDown:
|
|
37
|
-
"aria-expanded":
|
|
44
|
+
onClick: D,
|
|
45
|
+
onKeyDown: E,
|
|
46
|
+
"aria-expanded": e,
|
|
38
47
|
"aria-haspopup": "listbox",
|
|
39
|
-
"aria-label": `${
|
|
40
|
-
disabled:
|
|
41
|
-
"aria-controls":
|
|
42
|
-
...
|
|
48
|
+
"aria-label": `${s.label}`,
|
|
49
|
+
disabled: L,
|
|
50
|
+
"aria-controls": C,
|
|
51
|
+
...b && { ref: b },
|
|
43
52
|
children: [
|
|
44
|
-
/* @__PURE__ */
|
|
45
|
-
/* @__PURE__ */
|
|
46
|
-
|
|
53
|
+
/* @__PURE__ */ c("span", { className: t["select-listbox-trigger-label"], children: s[w] }),
|
|
54
|
+
/* @__PURE__ */ c(
|
|
55
|
+
R,
|
|
47
56
|
{
|
|
48
|
-
className:
|
|
49
|
-
[
|
|
57
|
+
className: m(t["select-listbox-trigger-icon"], {
|
|
58
|
+
[t["select-listbox-trigger-icon--open"]]: e
|
|
50
59
|
}),
|
|
51
60
|
name: "CheveronDown",
|
|
52
61
|
size: 16
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectButton.js","sources":["../../../../src/components/SelectListbox/components/SelectButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef, forwardRef } from 'react';\n\nimport type { KeyboardEvent } from 'react';\nimport type { OptionValue, SelectValue } from 'components/SelectListbox/SelectProvider';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { Icon } from 'components/Icon';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectButtonProps {\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight' | 'darkBorder';\n size?: 'small' | 'medium' | 'default';\n onChange?: (option: OptionValue) => void;\n buttonLabelProp?: string;\n buttonLabelBold?: boolean;\n disabled?: boolean;\n}\n\nexport const SelectButton = forwardRef<HTMLButtonElement, SelectButtonProps>((props, ref) => {\n const { variant, size = 'default', onChange, buttonLabelProp = 'label', buttonLabelBold, disabled = false } = props;\n const buttonWrapper = useRef<HTMLSpanElement>(null);\n const isFirstRender = useRef(true);\n const { listboxId, isOpen, selectedValue, toggleListbox, setIsOpen, setActiveIndex, options } = useSelect() || {};\n\n const onTriggerKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n if (!isOpen) {\n setIsOpen(true);\n return;\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setActiveIndex(options.findIndex((option) => option.value === selectedValue?.value));\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n isOpen\n ? (buttonWrapper.current?.children[0] as HTMLButtonElement).blur()\n : !isFirstRender.current && (buttonWrapper.current?.children[0] as HTMLButtonElement).focus();\n }, [isOpen]);\n\n useEffect(() => {\n isFirstRender.current = false;\n\n return () => {\n isFirstRender.current = true;\n };\n }, []);\n\n useEffect(() => {\n if (onChange) onChange(selectedValue);\n }, [onChange, selectedValue]);\n\n return (\n <span ref={buttonWrapper}>\n <button\n className={clsx(styles['select-listbox-trigger'], styles[`select-listbox-trigger--${size}`], {\n [styles[`select-listbox-trigger--${variant}`]]: variant,\n [styles['select-listbox-trigger--bold']]: buttonLabelBold,\n })}\n type=\"button\"\n onClick={toggleListbox}\n onKeyDown={onTriggerKeyDown}\n aria-expanded={isOpen}\n aria-haspopup=\"listbox\"\n aria-label={`${selectedValue.label}`}\n disabled={disabled}\n aria-controls={listboxId}\n {...(ref && { ref: ref })}\n >\n <span className={styles['select-listbox-trigger-label']}>\n {selectedValue[buttonLabelProp as keyof SelectValue]}\n </span>\n\n <Icon\n className={clsx(styles['select-listbox-trigger-icon'], {\n [styles['select-listbox-trigger-icon--open']]: isOpen,\n })}\n name=\"CheveronDown\"\n size={16}\n />\n </button>\n </span>\n );\n});\n"],"names":["SelectButton","forwardRef","props","ref","variant","size","onChange","buttonLabelProp","buttonLabelBold","disabled","buttonWrapper","useRef","isFirstRender","listboxId","isOpen","selectedValue","toggleListbox","setIsOpen","setActiveIndex","options","useSelect","onTriggerKeyDown","event","option","useEffect","jsx","jsxs","clsx","styles","Icon"],"mappings":";;;;;;AAmBO,MAAMA,IAAeC,EAAiD,CAACC,GAAOC,MAAQ;AAC3F,QAAM,EAAE,SAAAC,GAAS,MAAAC,IAAO,WAAW,UAAAC,GAAU,iBAAAC,IAAkB,SAAS,iBAAAC,GAAiB,UAAAC,IAAW,GAAA,IAAUP,GACxGQ,IAAgBC,EAAwB,IAAI,GAC5CC,IAAgBD,EAAO,EAAI,GAC3B,EAAE,WAAAE,GAAW,QAAAC,GAAQ,eAAAC,GAAe,eAAAC,GAAe,WAAAC,GAAW,gBAAAC,GAAgB,SAAAC,EAAA,IAAYC,EAAA,KAAe,CAAA,GAEzGC,IAAmB,CAACC,MAA4C;AACpE,YAAQA,EAAM,KAAA;AAAA,MACZ,KAAK;AAEH,YADAA,EAAM,eAAA,GACF,CAACR,GAAQ;AACX,UAAAG,EAAU,EAAI;AACd;AAAA,QAAA;AAEF;AAAA,MACF,KAAK;AACH,QAAIH,MACFQ,EAAM,gBAAA,GACNJ,EAAeC,EAAQ,UAAU,
|
|
1
|
+
{"version":3,"file":"SelectButton.js","sources":["../../../../src/components/SelectListbox/components/SelectButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef, forwardRef } from 'react';\n\nimport type { KeyboardEvent } from 'react';\nimport type { OptionValue, SelectValue } from 'components/SelectListbox/SelectProvider';\n\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\nimport { Icon } from 'components/Icon';\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\n\nexport interface SelectButtonProps {\n variant?: 'noborder' | 'pill' | 'pillLeft' | 'pillRight' | 'darkBorder';\n size?: 'small' | 'medium' | 'default';\n onChange?: (option: OptionValue) => void;\n buttonLabelProp?: string;\n buttonLabelBold?: boolean;\n disabled?: boolean;\n}\n\nexport const SelectButton = forwardRef<HTMLButtonElement, SelectButtonProps>((props, ref) => {\n const { variant, size = 'default', onChange, buttonLabelProp = 'label', buttonLabelBold, disabled = false } = props;\n const buttonWrapper = useRef<HTMLSpanElement>(null);\n const isFirstRender = useRef(true);\n const { listboxId, isOpen, selectedValue, toggleListbox, setIsOpen, setActiveIndex, options } = useSelect() || {};\n\n const onTriggerKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key.length === 1) {\n const key = event.key.toLocaleLowerCase();\n const optionIndexStartsWithKey = options.findIndex(\n (option) => !option.disabled && option.label.toLocaleLowerCase().startsWith(key)\n );\n if (optionIndexStartsWithKey !== -1) {\n setActiveIndex(optionIndexStartsWithKey);\n if (!isOpen) setIsOpen(true);\n event.preventDefault();\n return;\n }\n }\n\n switch (event.key) {\n case 'Enter':\n event.preventDefault();\n if (!isOpen) {\n setIsOpen(true);\n return;\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setActiveIndex(options.findIndex((option) => option.value === selectedValue?.value));\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n isOpen\n ? (buttonWrapper.current?.children[0] as HTMLButtonElement).blur()\n : !isFirstRender.current && (buttonWrapper.current?.children[0] as HTMLButtonElement).focus();\n }, [isOpen]);\n\n useEffect(() => {\n isFirstRender.current = false;\n\n return () => {\n isFirstRender.current = true;\n };\n }, []);\n\n useEffect(() => {\n if (onChange) onChange(selectedValue);\n }, [onChange, selectedValue]);\n\n return (\n <span ref={buttonWrapper}>\n <button\n className={clsx(styles['select-listbox-trigger'], styles[`select-listbox-trigger--${size}`], {\n [styles[`select-listbox-trigger--${variant}`]]: variant,\n [styles['select-listbox-trigger--bold']]: buttonLabelBold,\n })}\n type=\"button\"\n onClick={toggleListbox}\n onKeyDown={onTriggerKeyDown}\n aria-expanded={isOpen}\n aria-haspopup=\"listbox\"\n aria-label={`${selectedValue.label}`}\n disabled={disabled}\n aria-controls={listboxId}\n {...(ref && { ref: ref })}\n >\n <span className={styles['select-listbox-trigger-label']}>\n {selectedValue[buttonLabelProp as keyof SelectValue]}\n </span>\n\n <Icon\n className={clsx(styles['select-listbox-trigger-icon'], {\n [styles['select-listbox-trigger-icon--open']]: isOpen,\n })}\n name=\"CheveronDown\"\n size={16}\n />\n </button>\n </span>\n );\n});\n"],"names":["SelectButton","forwardRef","props","ref","variant","size","onChange","buttonLabelProp","buttonLabelBold","disabled","buttonWrapper","useRef","isFirstRender","listboxId","isOpen","selectedValue","toggleListbox","setIsOpen","setActiveIndex","options","useSelect","onTriggerKeyDown","event","key","option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sxs as v, Fragment as x, jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { c as I } from "../../../clsx-OuTLNxxd.js";
|
|
3
|
+
import { useRef as O, useEffect as k } from "react";
|
|
4
|
+
import { useSelect as g } from "../SelectProvider.js";
|
|
5
5
|
import { s as c } from "../../../SelectListbox.module-yzXaWwsm.js";
|
|
6
|
-
const
|
|
7
|
-
const i =
|
|
8
|
-
p(o[
|
|
9
|
-
},
|
|
10
|
-
|
|
6
|
+
const K = ({ option: a, index: s, dividerAfter: u, children: w }) => {
|
|
7
|
+
const i = O(null), { isOpen: l, activeIndex: t, setActiveIndex: r, selectedValue: n, setSelectedValue: p, setIsOpen: f, options: o } = g(), y = (e) => {
|
|
8
|
+
p(o[e]), f(!1);
|
|
9
|
+
}, h = (e) => {
|
|
10
|
+
if (e.key.length === 1) {
|
|
11
|
+
const D = e.key.toLocaleLowerCase(), d = o.findIndex(
|
|
12
|
+
(b) => !b.disabled && b.label.toLocaleLowerCase().startsWith(D)
|
|
13
|
+
);
|
|
14
|
+
if (d !== -1) {
|
|
15
|
+
r(d), e.preventDefault();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
switch (e.key) {
|
|
11
20
|
case "Tab":
|
|
12
|
-
|
|
21
|
+
e.preventDefault(), l && f(!1);
|
|
13
22
|
break;
|
|
14
23
|
case "ArrowDown":
|
|
15
24
|
case "ArrowUp":
|
|
16
|
-
if (
|
|
25
|
+
if (e.preventDefault(), !l)
|
|
17
26
|
return;
|
|
18
|
-
|
|
27
|
+
e.key === "ArrowDown" && t < o.length - 1 && r(t + 1), e.key === "ArrowUp" && t > 0 && r(t - 1);
|
|
19
28
|
break;
|
|
20
29
|
case "Enter":
|
|
21
|
-
|
|
30
|
+
e.preventDefault(), o?.length && t > -1 && !o[t].disabled && y(t);
|
|
22
31
|
break;
|
|
23
32
|
case "Escape":
|
|
24
|
-
|
|
33
|
+
l && (e.stopPropagation(), f(!1));
|
|
25
34
|
break;
|
|
26
35
|
}
|
|
27
36
|
};
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
}, [
|
|
31
|
-
n.value ===
|
|
32
|
-
}, [
|
|
33
|
-
/* @__PURE__ */
|
|
37
|
+
return k(() => {
|
|
38
|
+
s === t && (l ? i.current?.focus() : i.current?.blur());
|
|
39
|
+
}, [t, s, l]), k(() => {
|
|
40
|
+
n.value === a.value && r(s);
|
|
41
|
+
}, [s, a.value, n.value, r]), /* @__PURE__ */ v(x, { children: [
|
|
42
|
+
/* @__PURE__ */ m(
|
|
34
43
|
"li",
|
|
35
44
|
{
|
|
36
|
-
className:
|
|
37
|
-
[c["select-listbox-option--active"]]:
|
|
38
|
-
[c["select-listbox-option--divider"]]:
|
|
45
|
+
className: I(c["select-listbox-option"], {
|
|
46
|
+
[c["select-listbox-option--active"]]: s === t,
|
|
47
|
+
[c["select-listbox-option--divider"]]: s + 1 === u
|
|
39
48
|
}),
|
|
40
|
-
...!
|
|
41
|
-
onClick: () => p(
|
|
42
|
-
onKeyDown:
|
|
49
|
+
...!a.disabled && {
|
|
50
|
+
onClick: () => p(a),
|
|
51
|
+
onKeyDown: h,
|
|
43
52
|
tabIndex: 0,
|
|
44
53
|
role: "option",
|
|
45
|
-
"aria-selected": n.value ===
|
|
54
|
+
"aria-selected": n.value === a.value
|
|
46
55
|
},
|
|
47
56
|
ref: i,
|
|
48
|
-
children:
|
|
57
|
+
children: w
|
|
49
58
|
},
|
|
50
|
-
`${
|
|
59
|
+
`${a.value}`
|
|
51
60
|
),
|
|
52
|
-
|
|
61
|
+
s + 1 === u && /* @__PURE__ */ m("div", { className: c["select-listbox-divider"], "aria-hidden": "true" })
|
|
53
62
|
] });
|
|
54
63
|
};
|
|
55
64
|
export {
|
|
56
|
-
|
|
65
|
+
K as SelectOption
|
|
57
66
|
};
|
|
58
67
|
//# sourceMappingURL=SelectOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectOption.js","sources":["../../../../src/components/SelectListbox/components/SelectOption.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\n\nimport type { KeyboardEvent, ReactNode } from 'react';\nimport type { OptionValue } from 'components/SelectListbox/SelectProvider';\n\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\n\nexport interface SelectOptionProps {\n option: OptionValue;\n index: number;\n key: string | number;\n dividerAfter?: number;\n children: ReactNode;\n}\n\nexport const SelectOption = ({ option, index, dividerAfter, children }: SelectOptionProps) => {\n const selectOptionRef = useRef<HTMLLIElement>(null);\n const { isOpen, activeIndex, setActiveIndex, selectedValue, setSelectedValue, setIsOpen, options } = useSelect();\n\n const handleSelectOption = (aIndex: number) => {\n setSelectedValue(options[aIndex]);\n setIsOpen(false);\n };\n\n const onOptionKeyDown = (event: KeyboardEvent<HTMLLIElement>) => {\n switch (event.key) {\n case 'Tab':\n event.preventDefault();\n if (isOpen) {\n setIsOpen(false);\n }\n break;\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!isOpen) {\n return;\n }\n if (event.key === 'ArrowDown' && activeIndex < options.length - 1) {\n setActiveIndex(activeIndex + 1);\n }\n if (event.key === 'ArrowUp' && activeIndex > 0) {\n setActiveIndex(activeIndex - 1);\n }\n break;\n case 'Enter':\n event.preventDefault();\n if (options?.length && activeIndex > -1 && !options[activeIndex].disabled) {\n handleSelectOption(activeIndex);\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n if (index === activeIndex) {\n isOpen ? selectOptionRef.current?.focus() : selectOptionRef.current?.blur();\n }\n }, [activeIndex, index, isOpen]);\n\n useEffect(() => {\n if (selectedValue.value === option.value) {\n setActiveIndex(index);\n }\n }, [index, option.value, selectedValue.value, setActiveIndex]);\n\n return (\n <>\n <li\n className={clsx(styles['select-listbox-option'], {\n [styles['select-listbox-option--active']]: index === activeIndex,\n [styles['select-listbox-option--divider']]: index + 1 === dividerAfter,\n })}\n key={`${option.value}`}\n {...(!option.disabled && {\n onClick: () => setSelectedValue(option),\n onKeyDown: onOptionKeyDown,\n tabIndex: 0,\n role: 'option',\n 'aria-selected': selectedValue.value === option.value,\n })}\n ref={selectOptionRef}\n >\n {children}\n </li>\n {index + 1 === dividerAfter && <div className={styles['select-listbox-divider']} aria-hidden=\"true\" />}\n </>\n );\n};\n"],"names":["SelectOption","option","index","dividerAfter","children","selectOptionRef","useRef","isOpen","activeIndex","setActiveIndex","selectedValue","setSelectedValue","setIsOpen","options","useSelect","handleSelectOption","aIndex","onOptionKeyDown","event","useEffect","jsxs","Fragment","jsx","clsx","styles"],"mappings":";;;;;AAiBO,MAAMA,IAAe,CAAC,EAAE,QAAAC,GAAQ,OAAAC,GAAO,cAAAC,GAAc,UAAAC,QAAkC;AAC5F,QAAMC,IAAkBC,EAAsB,IAAI,GAC5C,EAAE,QAAAC,GAAQ,aAAAC,GAAa,gBAAAC,GAAgB,eAAAC,GAAe,kBAAAC,GAAkB,WAAAC,GAAW,SAAAC,EAAA,IAAYC,EAAA,GAE/FC,IAAqB,CAACC,MAAmB;AAC7C,IAAAL,EAAiBE,EAAQG,CAAM,CAAC,GAChCJ,EAAU,EAAK;AAAA,EAAA,GAGXK,IAAkB,CAACC,MAAwC;AAC/D,YAAQA,EAAM,KAAA;AAAA,MACZ,KAAK;AACH,QAAAA,EAAM,eAAA,GACFX,KACFK,EAAU,EAAK;AAEjB;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AAEH,YADAM,EAAM,eAAA,GACF,CAACX;AACH;AAEF,QAAIW,EAAM,QAAQ,eAAeV,IAAcK,EAAQ,SAAS,KAC9DJ,EAAeD,IAAc,CAAC,GAE5BU,EAAM,QAAQ,aAAaV,IAAc,KAC3CC,EAAeD,IAAc,CAAC;AAEhC;AAAA,MACF,KAAK;AACH,QAAAU,EAAM,eAAA,GACFL,GAAS,UAAUL,IAAc,MAAM,CAACK,EAAQL,CAAW,EAAE,YAC/DO,EAAmBP,CAAW;AAEhC;AAAA,MACF,KAAK;AACH,QAAID,MACFW,EAAM,gBAAA,GACNN,EAAU,EAAK;AAEjB;AAAA,IAAA;AAAA,EACJ;AAGF,
|
|
1
|
+
{"version":3,"file":"SelectOption.js","sources":["../../../../src/components/SelectListbox/components/SelectOption.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useEffect, useRef } from 'react';\n\nimport type { KeyboardEvent, ReactNode } from 'react';\nimport type { OptionValue } from 'components/SelectListbox/SelectProvider';\n\nimport { useSelect } from 'components/SelectListbox/SelectProvider';\nimport styles from 'components/SelectListbox/SelectListbox.module.css';\n\nexport interface SelectOptionProps {\n option: OptionValue;\n index: number;\n key: string | number;\n dividerAfter?: number;\n children: ReactNode;\n}\n\nexport const SelectOption = ({ option, index, dividerAfter, children }: SelectOptionProps) => {\n const selectOptionRef = useRef<HTMLLIElement>(null);\n const { isOpen, activeIndex, setActiveIndex, selectedValue, setSelectedValue, setIsOpen, options } = useSelect();\n\n const handleSelectOption = (aIndex: number) => {\n setSelectedValue(options[aIndex]);\n setIsOpen(false);\n };\n\n const onOptionKeyDown = (event: KeyboardEvent<HTMLLIElement>) => {\n if (event.key.length === 1) {\n const key = event.key.toLocaleLowerCase();\n const optionIndexStartsWithKey = options.findIndex(\n (option) => !option.disabled && option.label.toLocaleLowerCase().startsWith(key)\n );\n if (optionIndexStartsWithKey !== -1) {\n setActiveIndex(optionIndexStartsWithKey);\n event.preventDefault();\n return;\n }\n }\n\n switch (event.key) {\n case 'Tab':\n event.preventDefault();\n if (isOpen) {\n setIsOpen(false);\n }\n break;\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n if (!isOpen) {\n return;\n }\n if (event.key === 'ArrowDown' && activeIndex < options.length - 1) {\n setActiveIndex(activeIndex + 1);\n }\n if (event.key === 'ArrowUp' && activeIndex > 0) {\n setActiveIndex(activeIndex - 1);\n }\n break;\n case 'Enter':\n event.preventDefault();\n if (options?.length && activeIndex > -1 && !options[activeIndex].disabled) {\n handleSelectOption(activeIndex);\n }\n break;\n case 'Escape':\n if (isOpen) {\n event.stopPropagation();\n setIsOpen(false);\n }\n break;\n }\n };\n\n useEffect(() => {\n if (index === activeIndex) {\n isOpen ? selectOptionRef.current?.focus() : selectOptionRef.current?.blur();\n }\n }, [activeIndex, index, isOpen]);\n\n useEffect(() => {\n if (selectedValue.value === option.value) {\n setActiveIndex(index);\n }\n }, [index, option.value, selectedValue.value, setActiveIndex]);\n\n return (\n <>\n <li\n className={clsx(styles['select-listbox-option'], {\n [styles['select-listbox-option--active']]: index === activeIndex,\n [styles['select-listbox-option--divider']]: index + 1 === dividerAfter,\n })}\n key={`${option.value}`}\n {...(!option.disabled && {\n onClick: () => setSelectedValue(option),\n onKeyDown: onOptionKeyDown,\n tabIndex: 0,\n role: 'option',\n 'aria-selected': selectedValue.value === option.value,\n })}\n ref={selectOptionRef}\n >\n {children}\n </li>\n {index + 1 === dividerAfter && <div className={styles['select-listbox-divider']} aria-hidden=\"true\" />}\n </>\n );\n};\n"],"names":["SelectOption","option","index","dividerAfter","children","selectOptionRef","useRef","isOpen","activeIndex","setActiveIndex","selectedValue","setSelectedValue","setIsOpen","options","useSelect","handleSelectOption","aIndex","onOptionKeyDown","event","key","optionIndexStartsWithKey","useEffect","jsxs","Fragment","jsx","clsx","styles"],"mappings":";;;;;AAiBO,MAAMA,IAAe,CAAC,EAAE,QAAAC,GAAQ,OAAAC,GAAO,cAAAC,GAAc,UAAAC,QAAkC;AAC5F,QAAMC,IAAkBC,EAAsB,IAAI,GAC5C,EAAE,QAAAC,GAAQ,aAAAC,GAAa,gBAAAC,GAAgB,eAAAC,GAAe,kBAAAC,GAAkB,WAAAC,GAAW,SAAAC,EAAA,IAAYC,EAAA,GAE/FC,IAAqB,CAACC,MAAmB;AAC7C,IAAAL,EAAiBE,EAAQG,CAAM,CAAC,GAChCJ,EAAU,EAAK;AAAA,EAAA,GAGXK,IAAkB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MAAA;AAAA,QACC,WAAWC,EAAKC,EAAO,uBAAuB,GAAG;AAAA,UAC/C,CAACA,EAAO,+BAA+B,CAAC,GAAGxB,MAAUM;AAAA,UACrD,CAACkB,EAAO,gCAAgC,CAAC,GAAGxB,IAAQ,MAAMC;AAAA,QAAA,CAC3D;AAAA,QAEA,GAAI,CAACF,EAAO,YAAY;AAAA,UACvB,SAAS,MAAMU,EAAiBV,CAAM;AAAA,UACtC,WAAWgB;AAAA,UACX,UAAU;AAAA,UACV,MAAM;AAAA,UACN,iBAAiBP,EAAc,UAAUT,EAAO;AAAA,QAAA;AAAA,QAElD,KAAKI;AAAA,QAEJ,UAAAD;AAAA,MAAA;AAAA,MAVI,GAAGH,EAAO,KAAK;AAAA,IAAA;AAAA,IAYrBC,IAAQ,MAAMC,KAAgB,gBAAAqB,EAAC,OAAA,EAAI,WAAWE,EAAO,wBAAwB,GAAG,eAAY,OAAA,CAAO;AAAA,EAAA,GACtG;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@uva-glass/component-library",
|
|
3
3
|
"author": "Team Glass - Frontend vrienden",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.39.
|
|
5
|
+
"version": "3.39.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -61,20 +61,20 @@
|
|
|
61
61
|
"@testing-library/react": "^16.3.0",
|
|
62
62
|
"@types/jest": "^30.0.0",
|
|
63
63
|
"@types/node": "^22.18.0",
|
|
64
|
-
"@types/react": "^19.1.
|
|
65
|
-
"@types/react-dom": "^19.1.
|
|
64
|
+
"@types/react": "^19.1.12",
|
|
65
|
+
"@types/react-dom": "^19.1.8",
|
|
66
66
|
"@uva-glass/eslint-config": "^1.3.11",
|
|
67
67
|
"@uva-glass/stylelint-config": "^1.2.3",
|
|
68
|
-
"@vitejs/plugin-react": "^5.0.
|
|
69
|
-
"babel-jest": "^30.
|
|
68
|
+
"@vitejs/plugin-react": "^5.0.2",
|
|
69
|
+
"babel-jest": "^30.1.1",
|
|
70
70
|
"babel-plugin-transform-vite-meta-env": "^1.0.3",
|
|
71
71
|
"clsx": "^2.1.1",
|
|
72
72
|
"eslint-plugin-react-hooks": "^6.0.0",
|
|
73
73
|
"glob": "^11.0.3",
|
|
74
74
|
"husky": "^9.1.7",
|
|
75
75
|
"identity-obj-proxy": "^3.0.0",
|
|
76
|
-
"jest": "^30.
|
|
77
|
-
"jest-environment-jsdom": "^30.
|
|
76
|
+
"jest": "^30.1.1",
|
|
77
|
+
"jest-environment-jsdom": "^30.1.1",
|
|
78
78
|
"jest-junit": "^16.0.0",
|
|
79
79
|
"jsdom": "^26.1.0",
|
|
80
80
|
"npm-run-all2": "^8.0.4",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-router": "^7.8.2",
|
|
84
84
|
"semantic-release": "^24.2.7",
|
|
85
85
|
"storybook": "^9.1.3",
|
|
86
|
-
"style-dictionary": "^5.0.
|
|
86
|
+
"style-dictionary": "^5.0.3",
|
|
87
87
|
"stylelint": "^16.23.1",
|
|
88
88
|
"stylelint-config-recommended": "^17.0.0",
|
|
89
89
|
"stylelint-config-standard": "^39.0.0",
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
111
|
"@ast-grep/napi-linux-x64-gnu": "0.39.4",
|
|
112
|
-
"@rollup/rollup-linux-x64-gnu": "^4.
|
|
113
|
-
"@rspack/binding-darwin-arm64": "1.
|
|
114
|
-
"@rspack/binding-linux-x64-gnu": "1.
|
|
112
|
+
"@rollup/rollup-linux-x64-gnu": "^4.49.0",
|
|
113
|
+
"@rspack/binding-darwin-arm64": "1.5.0",
|
|
114
|
+
"@rspack/binding-linux-x64-gnu": "1.5.0"
|
|
115
115
|
}
|
|
116
116
|
}
|