@chayns-ui/core 0.9.2 → 0.9.4
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/combo-box.css
CHANGED
|
@@ -72,10 +72,9 @@
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
.chayns-combo-box__popup {
|
|
75
|
-
position:
|
|
76
|
-
inset-block-start: calc(100% + var(--k4));
|
|
77
|
-
inset-inline: 0;
|
|
75
|
+
position: fixed;
|
|
78
76
|
z-index: var(--z-popover);
|
|
77
|
+
box-sizing: border-box;
|
|
79
78
|
max-block-size: min(320px, 50vh);
|
|
80
79
|
overflow: auto;
|
|
81
80
|
padding: var(--k6);
|
|
@@ -83,6 +82,17 @@
|
|
|
83
82
|
border-radius: 12px;
|
|
84
83
|
background: var(--surface);
|
|
85
84
|
box-shadow: var(--shadow-pop);
|
|
85
|
+
opacity: 1;
|
|
86
|
+
transform: translateY(0);
|
|
87
|
+
transform-origin: top center;
|
|
88
|
+
transition:
|
|
89
|
+
opacity 0.18s ease,
|
|
90
|
+
transform 0.18s ease;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.chayns-combo-box__popup[data-state='closed'] {
|
|
94
|
+
opacity: 0;
|
|
95
|
+
transform: translateY(calc(-1 * var(--k4)));
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
.chayns-combo-box__option {
|
|
@@ -147,7 +157,8 @@
|
|
|
147
157
|
|
|
148
158
|
@media (prefers-reduced-motion: reduce) {
|
|
149
159
|
.chayns-combo-box__trigger,
|
|
150
|
-
.chayns-combo-box__chevron
|
|
160
|
+
.chayns-combo-box__chevron,
|
|
161
|
+
.chayns-combo-box__popup {
|
|
151
162
|
transition: none;
|
|
152
163
|
}
|
|
153
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.d.ts","sourceRoot":"","sources":["../../../src/components/combo-box/ComboBox.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ComboBox.d.ts","sourceRoot":"","sources":["../../../src/components/combo-box/ComboBox.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAiB,MAAM,qBAAqB,CAAC;AAua9E,QAAA,MAAM,QAAQ;;CAA0C,CAAC;AAEzD,eAAe,QAAQ,CAAC"}
|
|
@@ -2,6 +2,7 @@ import ButtonIcon from "../button/button-icon/ButtonIcon.js";
|
|
|
2
2
|
import { ComboBoxContext, getOptionLabel, useComboBoxContext } from "./ComboBoxContext.js";
|
|
3
3
|
import { Children, Fragment, forwardRef, isValidElement, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
5
6
|
//#region src/components/combo-box/ComboBox.tsx
|
|
6
7
|
function getOptionElements(children) {
|
|
7
8
|
const options = [];
|
|
@@ -66,7 +67,9 @@ var ComboBoxRoot = forwardRef(function ComboBoxRoot(props, ref) {
|
|
|
66
67
|
const listboxId = `${triggerId}-listbox`;
|
|
67
68
|
const labelId = `${triggerId}-label`;
|
|
68
69
|
const rootRef = useRef(null);
|
|
70
|
+
const popupRef = useRef(null);
|
|
69
71
|
const triggerRef = useRef(null);
|
|
72
|
+
const [popupStyle, setPopupStyle] = useState();
|
|
70
73
|
const optionElements = useMemo(() => getOptionElements(children), [children]);
|
|
71
74
|
const optionMap = useMemo(() => new Map(optionElements.map((option) => [option.props.value, option])), [optionElements]);
|
|
72
75
|
const focusableValues = optionElements.filter((option) => !option.props.disabled).map((option) => option.props.value);
|
|
@@ -75,6 +78,8 @@ var ComboBoxRoot = forwardRef(function ComboBoxRoot(props, ref) {
|
|
|
75
78
|
const [uncontrolledValue, setUncontrolledValue] = useState(multiple ? "" : defaultValue ?? "");
|
|
76
79
|
const [uncontrolledValues, setUncontrolledValues] = useState(defaultValues);
|
|
77
80
|
const [open, setOpen] = useState(false);
|
|
81
|
+
const [popupMounted, setPopupMounted] = useState(false);
|
|
82
|
+
const [popupClosing, setPopupClosing] = useState(false);
|
|
78
83
|
const [activeValue, setActiveValue] = useState();
|
|
79
84
|
const isControlled = value !== void 0;
|
|
80
85
|
const selectedValue = multiple ? "" : isControlled ? value : uncontrolledValue;
|
|
@@ -86,24 +91,59 @@ var ComboBoxRoot = forwardRef(function ComboBoxRoot(props, ref) {
|
|
|
86
91
|
const triggerClassName = ["chayns-combo-box__trigger", className].filter(Boolean).join(" ");
|
|
87
92
|
const accessibleName = ariaLabelledBy ?? (ariaLabel === void 0 && placeholder !== void 0 ? labelId : void 0);
|
|
88
93
|
if (ariaLabel === void 0 && ariaLabelledBy === void 0 && placeholder === void 0) throw new Error("ComboBox requires placeholder, aria-label or aria-labelledby.");
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (open) {
|
|
96
|
+
if (!popupMounted) {
|
|
97
|
+
setPopupMounted(true);
|
|
98
|
+
setPopupClosing(true);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (popupClosing) {
|
|
102
|
+
const frame = requestAnimationFrame(() => setPopupClosing(false));
|
|
103
|
+
return () => cancelAnimationFrame(frame);
|
|
104
|
+
}
|
|
105
|
+
} else if (popupMounted) setPopupClosing(true);
|
|
106
|
+
}, [
|
|
107
|
+
open,
|
|
108
|
+
popupClosing,
|
|
109
|
+
popupMounted
|
|
110
|
+
]);
|
|
89
111
|
useEffect(() => {
|
|
90
112
|
if (!open || activeValue === void 0) return;
|
|
91
113
|
document.getElementById(`${listboxId}-${activeValue.replace(/[^a-zA-Z0-9_-]/g, "-")}`)?.focus();
|
|
92
114
|
}, [
|
|
93
115
|
activeValue,
|
|
94
116
|
listboxId,
|
|
95
|
-
open
|
|
117
|
+
open,
|
|
118
|
+
popupMounted
|
|
96
119
|
]);
|
|
97
120
|
useEffect(() => {
|
|
98
121
|
if (!open) return;
|
|
122
|
+
function updatePopupPosition() {
|
|
123
|
+
const trigger = triggerRef.current;
|
|
124
|
+
if (!trigger) return;
|
|
125
|
+
const { bottom, left, width } = trigger.getBoundingClientRect();
|
|
126
|
+
setPopupStyle({
|
|
127
|
+
insetBlockStart: `calc(${bottom}px + var(--k4))`,
|
|
128
|
+
insetInlineStart: left,
|
|
129
|
+
inlineSize: width
|
|
130
|
+
});
|
|
131
|
+
}
|
|
99
132
|
function closeOnOutsidePress(event) {
|
|
100
|
-
if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {
|
|
133
|
+
if (event.target instanceof Node && !rootRef.current?.contains(event.target) && !popupRef.current?.contains(event.target)) {
|
|
101
134
|
setOpen(false);
|
|
102
135
|
setActiveValue(void 0);
|
|
103
136
|
}
|
|
104
137
|
}
|
|
138
|
+
updatePopupPosition();
|
|
139
|
+
window.addEventListener("resize", updatePopupPosition);
|
|
140
|
+
window.addEventListener("scroll", updatePopupPosition, true);
|
|
105
141
|
document.addEventListener("pointerdown", closeOnOutsidePress);
|
|
106
|
-
return () =>
|
|
142
|
+
return () => {
|
|
143
|
+
window.removeEventListener("resize", updatePopupPosition);
|
|
144
|
+
window.removeEventListener("scroll", updatePopupPosition, true);
|
|
145
|
+
document.removeEventListener("pointerdown", closeOnOutsidePress);
|
|
146
|
+
};
|
|
107
147
|
}, [open]);
|
|
108
148
|
function setTriggerElement(element) {
|
|
109
149
|
triggerRef.current = element;
|
|
@@ -217,15 +257,26 @@ var ComboBoxRoot = forwardRef(function ComboBoxRoot(props, ref) {
|
|
|
217
257
|
id: labelId,
|
|
218
258
|
children: placeholder
|
|
219
259
|
}) : null,
|
|
220
|
-
|
|
260
|
+
popupMounted && typeof document !== "undefined" ? createPortal(/* @__PURE__ */ jsx("div", {
|
|
261
|
+
"aria-hidden": !open && popupClosing ? true : void 0,
|
|
221
262
|
"aria-multiselectable": multiple || void 0,
|
|
222
263
|
className: "chayns-combo-box__popup",
|
|
264
|
+
"data-state": popupClosing ? "closed" : "open",
|
|
223
265
|
id: listboxId,
|
|
266
|
+
inert: !open && popupClosing,
|
|
224
267
|
onKeyDown: handleListboxKeyDown,
|
|
268
|
+
onTransitionEnd: (event) => {
|
|
269
|
+
if (popupClosing && event.propertyName === "opacity") {
|
|
270
|
+
setPopupMounted(false);
|
|
271
|
+
setPopupClosing(false);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
ref: popupRef,
|
|
225
275
|
role: "listbox",
|
|
276
|
+
style: popupStyle,
|
|
226
277
|
tabIndex: -1,
|
|
227
278
|
children
|
|
228
|
-
}) : null
|
|
279
|
+
}), document.body) : null
|
|
229
280
|
]
|
|
230
281
|
})
|
|
231
282
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.js","names":[],"sources":["../../../src/components/combo-box/ComboBox.tsx"],"sourcesContent":["import {\n Children,\n forwardRef,\n Fragment,\n isValidElement,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';\n\nimport ButtonIcon from '../button/button-icon/ButtonIcon.js';\nimport { ComboBoxContext, getOptionLabel, useComboBoxContext } from './ComboBoxContext.js';\nimport type { ComboBoxOptionProps, ComboBoxProps } from './ComboBox.types.js';\n\nfunction getOptionElements(children: ComboBoxProps['children']) {\n const options: ReactElement<ComboBoxOptionProps>[] = [];\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n return;\n }\n\n const element = child as ReactElement<{ children?: ReactNode; value?: string }>;\n\n if (element.type === Fragment) {\n options.push(...getOptionElements(element.props.children));\n } else if (typeof element.props.value === 'string') {\n options.push(element as ReactElement<ComboBoxOptionProps>);\n }\n });\n\n return options;\n}\n\nconst Option = forwardRef<HTMLDivElement, ComboBoxOptionProps>(function Option(\n { children, className, disabled = false, value, ...optionProps },\n ref,\n) {\n const comboBox = useComboBoxContext();\n const isSelected = comboBox.isSelected(value);\n const isActive = comboBox.activeValue === value;\n const resolvedClassName = [\n 'chayns-combo-box__option',\n isSelected ? 'chayns-combo-box__option--selected' : '',\n isActive ? 'chayns-combo-box__option--active' : '',\n disabled ? 'chayns-combo-box__option--disabled' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div\n {...optionProps}\n aria-disabled={disabled || undefined}\n aria-selected={isSelected}\n className={resolvedClassName}\n id={comboBox.optionId(value)}\n onClick={(event) => {\n optionProps.onClick?.(event);\n if (!event.defaultPrevented && !disabled) {\n comboBox.select(value);\n }\n }}\n onKeyDown={(event) => {\n optionProps.onKeyDown?.(event);\n if (!event.defaultPrevented && !disabled && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n comboBox.select(value);\n }\n }}\n ref={ref}\n role=\"option\"\n tabIndex={isActive && !disabled ? 0 : -1}\n >\n {comboBox.multiple ? (\n <span\n aria-hidden=\"true\"\n className=\"chayns-combo-box__checkbox\"\n data-checked={isSelected || undefined}\n />\n ) : null}\n {children}\n {!comboBox.multiple && isSelected ? (\n <span aria-hidden=\"true\" className=\"chayns-combo-box__checkmark\">\n <i className=\"fas fa-check\" />\n </span>\n ) : null}\n </div>\n );\n});\n\nconst ComboBoxRoot = forwardRef<HTMLButtonElement, ComboBoxProps>(function ComboBoxRoot(props, ref) {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n children,\n className,\n defaultValue,\n disabled,\n id,\n multiple = false,\n onClick,\n onKeyDown,\n onValueChange,\n placeholder,\n value,\n ...buttonProps\n } = props;\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n const listboxId = `${triggerId}-listbox`;\n const labelId = `${triggerId}-label`;\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const optionElements = useMemo(() => getOptionElements(children), [children]);\n const optionMap = useMemo(\n () => new Map(optionElements.map((option) => [option.props.value, option])),\n [optionElements],\n );\n const focusableValues = optionElements\n .filter((option) => !option.props.disabled)\n .map((option) => option.props.value);\n const defaultValues = multiple\n ? ((defaultValue as ReactElement<ComboBoxOptionProps>[] | undefined)?.map(\n (option) => option.props.value,\n ) ?? [])\n : [];\n const controlledValues = multiple\n ? ((value as ReactElement<ComboBoxOptionProps>[] | undefined)?.map(\n (option) => option.props.value,\n ) ?? [])\n : [];\n const [uncontrolledValue, setUncontrolledValue] = useState(\n multiple ? '' : ((defaultValue as string | undefined) ?? ''),\n );\n const [uncontrolledValues, setUncontrolledValues] = useState(defaultValues);\n const [open, setOpen] = useState(false);\n const [activeValue, setActiveValue] = useState<string>();\n const isControlled = value !== undefined;\n const selectedValue = multiple ? '' : isControlled ? (value as string) : uncontrolledValue;\n const selectedValues = multiple ? (isControlled ? controlledValues : uncontrolledValues) : [];\n const selectedOptions = selectedValues\n .map((selected) => optionMap.get(selected))\n .filter((option): option is ReactElement<ComboBoxOptionProps> => option !== undefined);\n const selectedOption = optionMap.get(selectedValue);\n const displayValue = multiple\n ? selectedOptions.map((option) => getOptionLabel(option.props.children)).join(', ')\n : selectedOption === undefined\n ? ''\n : getOptionLabel(selectedOption.props.children);\n const resolvedClassName = ['chayns-combo-box', open ? 'chayns-combo-box--open' : '']\n .filter(Boolean)\n .join(' ');\n const triggerClassName = ['chayns-combo-box__trigger', className].filter(Boolean).join(' ');\n const accessibleName = ariaLabelledBy ?? (ariaLabel === undefined && placeholder !== undefined ? labelId : undefined);\n\n if (ariaLabel === undefined && ariaLabelledBy === undefined && placeholder === undefined) {\n throw new Error('ComboBox requires placeholder, aria-label or aria-labelledby.');\n }\n\n useEffect(() => {\n if (!open || activeValue === undefined) {\n return;\n }\n\n document\n .getElementById(`${listboxId}-${activeValue.replace(/[^a-zA-Z0-9_-]/g, '-')}`)\n ?.focus();\n }, [activeValue, listboxId, open]);\n\n useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n function closeOnOutsidePress(event: PointerEvent) {\n if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {\n setOpen(false);\n setActiveValue(undefined);\n }\n }\n\n document.addEventListener('pointerdown', closeOnOutsidePress);\n return () => document.removeEventListener('pointerdown', closeOnOutsidePress);\n }, [open]);\n\n function setTriggerElement(element: HTMLButtonElement | null) {\n triggerRef.current = element;\n\n if (typeof ref === 'function') {\n ref(element);\n } else if (ref !== null) {\n ref.current = element;\n }\n }\n\n function emitValue(nextValue: string) {\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n }\n\n (onValueChange as ((next: string) => void) | undefined)?.(nextValue);\n }\n\n function emitValues(nextValues: string[]) {\n if (!isControlled) {\n setUncontrolledValues(nextValues);\n }\n\n const nextOptions = nextValues\n .map((nextValue) => optionMap.get(nextValue))\n .filter((option): option is ReactElement<ComboBoxOptionProps> => option !== undefined);\n (onValueChange as ((next: ReactElement<ComboBoxOptionProps>[]) => void) | undefined)?.(\n nextOptions,\n );\n }\n\n function closeAndFocusTrigger() {\n setOpen(false);\n setActiveValue(undefined);\n triggerRef.current?.focus();\n }\n\n function select(nextValue: string) {\n if (multiple) {\n const nextValues = selectedValues.includes(nextValue)\n ? selectedValues.filter((selected) => selected !== nextValue)\n : [...selectedValues, nextValue];\n emitValues(nextValues);\n } else {\n emitValue(nextValue);\n }\n\n closeAndFocusTrigger();\n }\n\n function openPopup() {\n if (disabled || focusableValues.length === 0) {\n return;\n }\n\n const selectedFocusableValue = focusableValues.find((optionValue) =>\n multiple ? selectedValues.includes(optionValue) : selectedValue === optionValue,\n );\n setActiveValue(selectedFocusableValue ?? focusableValues[0]);\n setOpen(true);\n }\n\n function moveActive(direction: 1 | -1) {\n if (focusableValues.length === 0) {\n return;\n }\n\n const currentIndex = activeValue === undefined ? -1 : focusableValues.indexOf(activeValue);\n const nextIndex =\n currentIndex === -1\n ? direction === 1\n ? 0\n : focusableValues.length - 1\n : (currentIndex + direction + focusableValues.length) % focusableValues.length;\n setActiveValue(focusableValues[nextIndex]);\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n if (!event.defaultPrevented) {\n if (open) {\n closeAndFocusTrigger();\n } else {\n openPopup();\n }\n }\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n if (event.defaultPrevented) {\n return;\n }\n\n if (\n event.key === 'Enter' ||\n event.key === ' ' ||\n event.key === 'ArrowDown' ||\n event.key === 'ArrowUp' ||\n (event.key === 'ArrowDown' && event.altKey)\n ) {\n event.preventDefault();\n openPopup();\n }\n }\n\n function handleListboxKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n if (event.key === 'ArrowDown') {\n event.preventDefault();\n moveActive(1);\n } else if (event.key === 'ArrowUp') {\n event.preventDefault();\n moveActive(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n setActiveValue(focusableValues[0]);\n } else if (event.key === 'End') {\n event.preventDefault();\n setActiveValue(focusableValues.at(-1));\n } else if (event.key === 'Escape') {\n event.preventDefault();\n closeAndFocusTrigger();\n } else if (event.key === 'Tab') {\n setOpen(false);\n setActiveValue(undefined);\n }\n }\n\n return (\n <ComboBoxContext.Provider\n value={{\n activeValue,\n isSelected: (optionValue) =>\n multiple ? selectedValues.includes(optionValue) : selectedValue === optionValue,\n multiple,\n optionId: (optionValue) => `${listboxId}-${optionValue.replace(/[^a-zA-Z0-9_-]/g, '-')}`,\n select,\n }}\n >\n <div className={resolvedClassName} ref={rootRef}>\n <button\n {...buttonProps}\n aria-controls={listboxId}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-label={ariaLabel}\n aria-labelledby={accessibleName}\n className={triggerClassName}\n disabled={disabled}\n id={triggerId}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n ref={setTriggerElement}\n type=\"button\"\n >\n <span className=\"chayns-combo-box__value\">{displayValue || placeholder}</span>\n <span aria-hidden=\"true\" className=\"chayns-combo-box__chevron\">\n <ButtonIcon icon=\"fa-chevron-down\" />\n </span>\n </button>\n {placeholder !== undefined ? (\n <span className=\"chayns-combo-box__label\" id={labelId}>\n {placeholder}\n </span>\n ) : null}\n {open ? (\n <div\n aria-multiselectable={multiple || undefined}\n className=\"chayns-combo-box__popup\"\n id={listboxId}\n onKeyDown={handleListboxKeyDown}\n role=\"listbox\"\n tabIndex={-1}\n >\n {children}\n </div>\n ) : null}\n </div>\n </ComboBoxContext.Provider>\n );\n});\n\nconst ComboBox = Object.assign(ComboBoxRoot, { Option });\n\nexport default ComboBox;\n"],"mappings":";;;;;AAiBA,SAAS,kBAAkB,UAAqC;CAC9D,MAAM,UAA+C,CAAC;CAEtD,SAAS,QAAQ,WAAW,UAAU;EACpC,IAAI,CAAC,eAAe,KAAK,GACvB;EAGF,MAAM,UAAU;EAEhB,IAAI,QAAQ,SAAS,UACnB,QAAQ,KAAK,GAAG,kBAAkB,QAAQ,MAAM,QAAQ,CAAC;OACpD,IAAI,OAAO,QAAQ,MAAM,UAAU,UACxC,QAAQ,KAAK,OAA4C;CAE7D,CAAC;CAED,OAAO;AACT;AAEA,IAAM,SAAS,WAAgD,SAAS,OACtE,EAAE,UAAU,WAAW,WAAW,OAAO,OAAO,GAAG,eACnD,KACA;CACA,MAAM,WAAW,mBAAmB;CACpC,MAAM,aAAa,SAAS,WAAW,KAAK;CAC5C,MAAM,WAAW,SAAS,gBAAgB;CAC1C,MAAM,oBAAoB;EACxB;EACA,aAAa,uCAAuC;EACpD,WAAW,qCAAqC;EAChD,WAAW,uCAAuC;EAClD;CACF,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;CAEX,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,iBAAe,YAAY,KAAA;EAC3B,iBAAe;EACf,WAAW;EACX,IAAI,SAAS,SAAS,KAAK;EAC3B,UAAU,UAAU;GAClB,YAAY,UAAU,KAAK;GAC3B,IAAI,CAAC,MAAM,oBAAoB,CAAC,UAC9B,SAAS,OAAO,KAAK;EAEzB;EACA,YAAY,UAAU;GACpB,YAAY,YAAY,KAAK;GAC7B,IAAI,CAAC,MAAM,oBAAoB,CAAC,aAAa,MAAM,QAAQ,WAAW,MAAM,QAAQ,MAAM;IACxF,MAAM,eAAe;IACrB,SAAS,OAAO,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UAAD;KACE,GAAI;KACJ,iBAAe;KACf,iBAAe;KACf,iBAAc;KACd,cAAY;KACZ,mBAAiB;KACjB,WAAW;KACD;KACV,IAAI;KACJ,SAAS;KACT,WAAW;KACX,KAAK;KACL,MAAK;KAbP,UAAA,CAeE,oBAAC,QAAD;MAAM,WAAU;MAA2B,UAAA,gBAAgB;KAAkB,CAAA,GAC7E,oBAAC,QAAD;MAAM,eAAY;MAAO,WAAU;MACjC,UAAA,oBAAC,YAAD,EAAY,MAAK,kBAAmB,CAAA;KAChC,CAAA,CACA;;IACP,gBAAgB,KAAA,IACf,oBAAC,QAAD;KAAM,WAAU;KAA0B,IAAI;KAC3C,UAAA;IACG,CAAA,IACJ;IACH,OACC,oBAAC,OAAD;KACE,wBAAsB,YAAY,KAAA;KAClC,WAAU;KACV,IAAI;KACJ,WAAW;KACX,MAAK;KACL,UAAU;KAET;IACE,CAAA,IACH;GACD;;CACmB,CAAA;AAE9B,CAAC;AAED,IAAM,WAAW,OAAO,OAAO,cAAc,EAAE,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"ComboBox.js","names":[],"sources":["../../../src/components/combo-box/ComboBox.tsx"],"sourcesContent":["import {\n Children,\n forwardRef,\n Fragment,\n isValidElement,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport type { CSSProperties, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';\n\nimport ButtonIcon from '../button/button-icon/ButtonIcon.js';\nimport { ComboBoxContext, getOptionLabel, useComboBoxContext } from './ComboBoxContext.js';\nimport type { ComboBoxOptionProps, ComboBoxProps } from './ComboBox.types.js';\n\nfunction getOptionElements(children: ComboBoxProps['children']) {\n const options: ReactElement<ComboBoxOptionProps>[] = [];\n\n Children.forEach(children, (child) => {\n if (!isValidElement(child)) {\n return;\n }\n\n const element = child as ReactElement<{ children?: ReactNode; value?: string }>;\n\n if (element.type === Fragment) {\n options.push(...getOptionElements(element.props.children));\n } else if (typeof element.props.value === 'string') {\n options.push(element as ReactElement<ComboBoxOptionProps>);\n }\n });\n\n return options;\n}\n\nconst Option = forwardRef<HTMLDivElement, ComboBoxOptionProps>(function Option(\n { children, className, disabled = false, value, ...optionProps },\n ref,\n) {\n const comboBox = useComboBoxContext();\n const isSelected = comboBox.isSelected(value);\n const isActive = comboBox.activeValue === value;\n const resolvedClassName = [\n 'chayns-combo-box__option',\n isSelected ? 'chayns-combo-box__option--selected' : '',\n isActive ? 'chayns-combo-box__option--active' : '',\n disabled ? 'chayns-combo-box__option--disabled' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ');\n\n return (\n <div\n {...optionProps}\n aria-disabled={disabled || undefined}\n aria-selected={isSelected}\n className={resolvedClassName}\n id={comboBox.optionId(value)}\n onClick={(event) => {\n optionProps.onClick?.(event);\n if (!event.defaultPrevented && !disabled) {\n comboBox.select(value);\n }\n }}\n onKeyDown={(event) => {\n optionProps.onKeyDown?.(event);\n if (!event.defaultPrevented && !disabled && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n comboBox.select(value);\n }\n }}\n ref={ref}\n role=\"option\"\n tabIndex={isActive && !disabled ? 0 : -1}\n >\n {comboBox.multiple ? (\n <span\n aria-hidden=\"true\"\n className=\"chayns-combo-box__checkbox\"\n data-checked={isSelected || undefined}\n />\n ) : null}\n {children}\n {!comboBox.multiple && isSelected ? (\n <span aria-hidden=\"true\" className=\"chayns-combo-box__checkmark\">\n <i className=\"fas fa-check\" />\n </span>\n ) : null}\n </div>\n );\n});\n\nconst ComboBoxRoot = forwardRef<HTMLButtonElement, ComboBoxProps>(\n function ComboBoxRoot(props, ref) {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n children,\n className,\n defaultValue,\n disabled,\n id,\n multiple = false,\n onClick,\n onKeyDown,\n onValueChange,\n placeholder,\n value,\n ...buttonProps\n } = props;\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n const listboxId = `${triggerId}-listbox`;\n const labelId = `${triggerId}-label`;\n const rootRef = useRef<HTMLDivElement>(null);\n const popupRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [popupStyle, setPopupStyle] = useState<CSSProperties>();\n const optionElements = useMemo(() => getOptionElements(children), [children]);\n const optionMap = useMemo(\n () => new Map(optionElements.map((option) => [option.props.value, option])),\n [optionElements],\n );\n const focusableValues = optionElements\n .filter((option) => !option.props.disabled)\n .map((option) => option.props.value);\n const defaultValues = multiple\n ? ((defaultValue as ReactElement<ComboBoxOptionProps>[] | undefined)?.map(\n (option) => option.props.value,\n ) ?? [])\n : [];\n const controlledValues = multiple\n ? ((value as ReactElement<ComboBoxOptionProps>[] | undefined)?.map(\n (option) => option.props.value,\n ) ?? [])\n : [];\n const [uncontrolledValue, setUncontrolledValue] = useState(\n multiple ? '' : ((defaultValue as string | undefined) ?? ''),\n );\n const [uncontrolledValues, setUncontrolledValues] = useState(defaultValues);\n const [open, setOpen] = useState(false);\n const [popupMounted, setPopupMounted] = useState(false);\n const [popupClosing, setPopupClosing] = useState(false);\n const [activeValue, setActiveValue] = useState<string>();\n const isControlled = value !== undefined;\n const selectedValue = multiple ? '' : isControlled ? (value as string) : uncontrolledValue;\n const selectedValues = multiple ? (isControlled ? controlledValues : uncontrolledValues) : [];\n const selectedOptions = selectedValues\n .map((selected) => optionMap.get(selected))\n .filter((option): option is ReactElement<ComboBoxOptionProps> => option !== undefined);\n const selectedOption = optionMap.get(selectedValue);\n const displayValue = multiple\n ? selectedOptions.map((option) => getOptionLabel(option.props.children)).join(', ')\n : selectedOption === undefined\n ? ''\n : getOptionLabel(selectedOption.props.children);\n const resolvedClassName = ['chayns-combo-box', open ? 'chayns-combo-box--open' : '']\n .filter(Boolean)\n .join(' ');\n const triggerClassName = ['chayns-combo-box__trigger', className].filter(Boolean).join(' ');\n const accessibleName =\n ariaLabelledBy ??\n (ariaLabel === undefined && placeholder !== undefined ? labelId : undefined);\n\n if (ariaLabel === undefined && ariaLabelledBy === undefined && placeholder === undefined) {\n throw new Error('ComboBox requires placeholder, aria-label or aria-labelledby.');\n }\n\n useEffect(() => {\n if (open) {\n if (!popupMounted) {\n setPopupMounted(true);\n setPopupClosing(true);\n return undefined;\n }\n\n if (popupClosing) {\n const frame = requestAnimationFrame(() => setPopupClosing(false));\n return () => cancelAnimationFrame(frame);\n }\n } else if (popupMounted) {\n setPopupClosing(true);\n }\n\n return undefined;\n }, [open, popupClosing, popupMounted]);\n\n useEffect(() => {\n if (!open || activeValue === undefined) {\n return;\n }\n\n document\n .getElementById(`${listboxId}-${activeValue.replace(/[^a-zA-Z0-9_-]/g, '-')}`)\n ?.focus();\n }, [activeValue, listboxId, open, popupMounted]);\n\n useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n function updatePopupPosition() {\n const trigger = triggerRef.current;\n if (!trigger) {\n return;\n }\n\n const { bottom, left, width } = trigger.getBoundingClientRect();\n setPopupStyle({\n insetBlockStart: `calc(${bottom}px + var(--k4))`,\n insetInlineStart: left,\n inlineSize: width,\n });\n }\n\n function closeOnOutsidePress(event: PointerEvent) {\n if (\n event.target instanceof Node &&\n !rootRef.current?.contains(event.target) &&\n !popupRef.current?.contains(event.target)\n ) {\n setOpen(false);\n setActiveValue(undefined);\n }\n }\n\n updatePopupPosition();\n window.addEventListener('resize', updatePopupPosition);\n window.addEventListener('scroll', updatePopupPosition, true);\n document.addEventListener('pointerdown', closeOnOutsidePress);\n return () => {\n window.removeEventListener('resize', updatePopupPosition);\n window.removeEventListener('scroll', updatePopupPosition, true);\n document.removeEventListener('pointerdown', closeOnOutsidePress);\n };\n }, [open]);\n\n function setTriggerElement(element: HTMLButtonElement | null) {\n triggerRef.current = element;\n\n if (typeof ref === 'function') {\n ref(element);\n } else if (ref !== null) {\n ref.current = element;\n }\n }\n\n function emitValue(nextValue: string) {\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n }\n\n (onValueChange as ((next: string) => void) | undefined)?.(nextValue);\n }\n\n function emitValues(nextValues: string[]) {\n if (!isControlled) {\n setUncontrolledValues(nextValues);\n }\n\n const nextOptions = nextValues\n .map((nextValue) => optionMap.get(nextValue))\n .filter((option): option is ReactElement<ComboBoxOptionProps> => option !== undefined);\n (onValueChange as ((next: ReactElement<ComboBoxOptionProps>[]) => void) | undefined)?.(\n nextOptions,\n );\n }\n\n function closeAndFocusTrigger() {\n setOpen(false);\n setActiveValue(undefined);\n triggerRef.current?.focus();\n }\n\n function select(nextValue: string) {\n if (multiple) {\n const nextValues = selectedValues.includes(nextValue)\n ? selectedValues.filter((selected) => selected !== nextValue)\n : [...selectedValues, nextValue];\n emitValues(nextValues);\n } else {\n emitValue(nextValue);\n }\n\n closeAndFocusTrigger();\n }\n\n function openPopup() {\n if (disabled || focusableValues.length === 0) {\n return;\n }\n\n const selectedFocusableValue = focusableValues.find((optionValue) =>\n multiple ? selectedValues.includes(optionValue) : selectedValue === optionValue,\n );\n setActiveValue(selectedFocusableValue ?? focusableValues[0]);\n setOpen(true);\n }\n\n function moveActive(direction: 1 | -1) {\n if (focusableValues.length === 0) {\n return;\n }\n\n const currentIndex = activeValue === undefined ? -1 : focusableValues.indexOf(activeValue);\n const nextIndex =\n currentIndex === -1\n ? direction === 1\n ? 0\n : focusableValues.length - 1\n : (currentIndex + direction + focusableValues.length) % focusableValues.length;\n setActiveValue(focusableValues[nextIndex]);\n }\n\n function handleTriggerClick(event: MouseEvent<HTMLButtonElement>) {\n onClick?.(event);\n if (!event.defaultPrevented) {\n if (open) {\n closeAndFocusTrigger();\n } else {\n openPopup();\n }\n }\n }\n\n function handleTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {\n onKeyDown?.(event);\n if (event.defaultPrevented) {\n return;\n }\n\n if (\n event.key === 'Enter' ||\n event.key === ' ' ||\n event.key === 'ArrowDown' ||\n event.key === 'ArrowUp' ||\n (event.key === 'ArrowDown' && event.altKey)\n ) {\n event.preventDefault();\n openPopup();\n }\n }\n\n function handleListboxKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n if (event.key === 'ArrowDown') {\n event.preventDefault();\n moveActive(1);\n } else if (event.key === 'ArrowUp') {\n event.preventDefault();\n moveActive(-1);\n } else if (event.key === 'Home') {\n event.preventDefault();\n setActiveValue(focusableValues[0]);\n } else if (event.key === 'End') {\n event.preventDefault();\n setActiveValue(focusableValues.at(-1));\n } else if (event.key === 'Escape') {\n event.preventDefault();\n closeAndFocusTrigger();\n } else if (event.key === 'Tab') {\n setOpen(false);\n setActiveValue(undefined);\n }\n }\n\n return (\n <ComboBoxContext.Provider\n value={{\n activeValue,\n isSelected: (optionValue) =>\n multiple ? selectedValues.includes(optionValue) : selectedValue === optionValue,\n multiple,\n optionId: (optionValue) => `${listboxId}-${optionValue.replace(/[^a-zA-Z0-9_-]/g, '-')}`,\n select,\n }}\n >\n <div className={resolvedClassName} ref={rootRef}>\n <button\n {...buttonProps}\n aria-controls={listboxId}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-label={ariaLabel}\n aria-labelledby={accessibleName}\n className={triggerClassName}\n disabled={disabled}\n id={triggerId}\n onClick={handleTriggerClick}\n onKeyDown={handleTriggerKeyDown}\n ref={setTriggerElement}\n type=\"button\"\n >\n <span className=\"chayns-combo-box__value\">{displayValue || placeholder}</span>\n <span aria-hidden=\"true\" className=\"chayns-combo-box__chevron\">\n <ButtonIcon icon=\"fa-chevron-down\" />\n </span>\n </button>\n {placeholder !== undefined ? (\n <span className=\"chayns-combo-box__label\" id={labelId}>\n {placeholder}\n </span>\n ) : null}\n {popupMounted && typeof document !== 'undefined'\n ? createPortal(\n <div\n aria-hidden={!open && popupClosing ? true : undefined}\n aria-multiselectable={multiple || undefined}\n className=\"chayns-combo-box__popup\"\n data-state={popupClosing ? 'closed' : 'open'}\n id={listboxId}\n inert={!open && popupClosing}\n onKeyDown={handleListboxKeyDown}\n onTransitionEnd={(event) => {\n if (popupClosing && event.propertyName === 'opacity') {\n setPopupMounted(false);\n setPopupClosing(false);\n }\n }}\n ref={popupRef}\n role=\"listbox\"\n style={popupStyle}\n tabIndex={-1}\n >\n {children}\n </div>,\n document.body,\n )\n : null}\n </div>\n </ComboBoxContext.Provider>\n );\n },\n);\n\nconst ComboBox = Object.assign(ComboBoxRoot, { Option });\n\nexport default ComboBox;\n"],"mappings":";;;;;;AAkBA,SAAS,kBAAkB,UAAqC;CAC9D,MAAM,UAA+C,CAAC;CAEtD,SAAS,QAAQ,WAAW,UAAU;EACpC,IAAI,CAAC,eAAe,KAAK,GACvB;EAGF,MAAM,UAAU;EAEhB,IAAI,QAAQ,SAAS,UACnB,QAAQ,KAAK,GAAG,kBAAkB,QAAQ,MAAM,QAAQ,CAAC;OACpD,IAAI,OAAO,QAAQ,MAAM,UAAU,UACxC,QAAQ,KAAK,OAA4C;CAE7D,CAAC;CAED,OAAO;AACT;AAEA,IAAM,SAAS,WAAgD,SAAS,OACtE,EAAE,UAAU,WAAW,WAAW,OAAO,OAAO,GAAG,eACnD,KACA;CACA,MAAM,WAAW,mBAAmB;CACpC,MAAM,aAAa,SAAS,WAAW,KAAK;CAC5C,MAAM,WAAW,SAAS,gBAAgB;CAC1C,MAAM,oBAAoB;EACxB;EACA,aAAa,uCAAuC;EACpD,WAAW,qCAAqC;EAChD,WAAW,uCAAuC;EAClD;CACF,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;CAEX,OACE,qBAAC,OAAD;EACE,GAAI;EACJ,iBAAe,YAAY,KAAA;EAC3B,iBAAe;EACf,WAAW;EACX,IAAI,SAAS,SAAS,KAAK;EAC3B,UAAU,UAAU;GAClB,YAAY,UAAU,KAAK;GAC3B,IAAI,CAAC,MAAM,oBAAoB,CAAC,UAC9B,SAAS,OAAO,KAAK;EAEzB;EACA,YAAY,UAAU;GACpB,YAAY,YAAY,KAAK;GAC7B,IAAI,CAAC,MAAM,oBAAoB,CAAC,aAAa,MAAM,QAAQ,WAAW,MAAM,QAAQ,MAAM;IACxF,MAAM,eAAe;IACrB,SAAS,OAAO,KAAK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