@simplybusiness/mobius 5.4.0 → 5.6.0
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/CHANGELOG.md +22 -0
- package/dist/cjs/components/Checkbox/Checkbox.js +14 -5
- package/dist/cjs/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/cjs/components/Combobox/Combobox.js +152 -0
- package/dist/cjs/components/Combobox/Combobox.js.map +1 -0
- package/dist/cjs/components/Combobox/Listbox.js +58 -0
- package/dist/cjs/components/Combobox/Listbox.js.map +1 -0
- package/dist/cjs/components/Combobox/Option.js +44 -0
- package/dist/cjs/components/Combobox/Option.js.map +1 -0
- package/dist/cjs/components/Combobox/fixtures.js +359 -0
- package/dist/cjs/components/Combobox/fixtures.js.map +1 -0
- package/dist/cjs/components/Combobox/index.js +21 -0
- package/dist/cjs/components/Combobox/index.js.map +1 -0
- package/dist/cjs/components/Combobox/types.js +6 -0
- package/dist/cjs/components/Combobox/types.js.map +1 -0
- package/dist/cjs/components/Combobox/useComboboxHighlight.js +86 -0
- package/dist/cjs/components/Combobox/useComboboxHighlight.js.map +1 -0
- package/dist/cjs/components/Combobox/utils.js +46 -0
- package/dist/cjs/components/Combobox/utils.js.map +1 -0
- package/dist/cjs/components/TextArea/TextArea.js +4 -4
- package/dist/cjs/components/TextArea/TextArea.js.map +1 -1
- package/dist/cjs/components/TextAreaInput/TextAreaInput.js +6 -3
- package/dist/cjs/components/TextAreaInput/TextAreaInput.js.map +1 -1
- package/dist/cjs/components/TextField/TextField.js +4 -3
- package/dist/cjs/components/TextField/TextField.js.map +1 -1
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/hooks/useTextField/useTextField.js +1 -0
- package/dist/cjs/hooks/useTextField/useTextField.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +15 -6
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Combobox/Combobox.js +137 -0
- package/dist/esm/components/Combobox/Combobox.js.map +1 -0
- package/dist/esm/components/Combobox/Listbox.js +43 -0
- package/dist/esm/components/Combobox/Listbox.js.map +1 -0
- package/dist/esm/components/Combobox/Option.js +29 -0
- package/dist/esm/components/Combobox/Option.js.map +1 -0
- package/dist/esm/components/Combobox/fixtures.js +335 -0
- package/dist/esm/components/Combobox/fixtures.js.map +1 -0
- package/dist/esm/components/Combobox/index.js +4 -0
- package/dist/esm/components/Combobox/index.js.map +1 -0
- package/dist/esm/components/Combobox/types.js +3 -0
- package/dist/esm/components/Combobox/types.js.map +1 -0
- package/dist/esm/components/Combobox/useComboboxHighlight.js +76 -0
- package/dist/esm/components/Combobox/useComboboxHighlight.js.map +1 -0
- package/dist/esm/components/Combobox/utils.js +20 -0
- package/dist/esm/components/Combobox/utils.js.map +1 -0
- package/dist/esm/components/TextArea/TextArea.js +4 -4
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/esm/components/TextAreaInput/TextAreaInput.js +6 -3
- package/dist/esm/components/TextAreaInput/TextAreaInput.js.map +1 -1
- package/dist/esm/components/TextField/TextField.js +4 -3
- package/dist/esm/components/TextField/TextField.js.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/hooks/useTextField/types.js.map +1 -1
- package/dist/esm/hooks/useTextField/useTextField.js +1 -0
- package/dist/esm/hooks/useTextField/useTextField.js.map +1 -1
- package/dist/types/components/Combobox/Combobox.d.ts +3 -0
- package/dist/types/components/Combobox/Combobox.stories.d.ts +10 -0
- package/dist/types/components/Combobox/Combobox.test.d.ts +1 -0
- package/dist/types/components/Combobox/Listbox.d.ts +10 -0
- package/dist/types/components/Combobox/Option.d.ts +2 -0
- package/dist/types/components/Combobox/fixtures.d.ts +10 -0
- package/dist/types/components/Combobox/index.d.ts +2 -0
- package/dist/types/components/Combobox/types.d.ts +31 -0
- package/dist/types/components/Combobox/useComboboxHighlight.d.ts +10 -0
- package/dist/types/components/Combobox/useComboboxHighlight.test.d.ts +1 -0
- package/dist/types/components/Combobox/utils.d.ts +6 -0
- package/dist/types/components/Combobox/utils.test.d.ts +1 -0
- package/dist/types/components/TextArea/TextArea.d.ts +2 -2
- package/dist/types/components/TextAreaInput/TextAreaInput.d.ts +3 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/hooks/useTextField/types.d.ts +3 -2
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +1 -2
- package/src/components/Checkbox/Checkbox.tsx +21 -7
- package/src/components/Combobox/Combobox.css +77 -0
- package/src/components/Combobox/Combobox.mdx +147 -0
- package/src/components/Combobox/Combobox.stories.tsx +71 -0
- package/src/components/Combobox/Combobox.test.tsx +797 -0
- package/src/components/Combobox/Combobox.tsx +174 -0
- package/src/components/Combobox/Listbox.tsx +74 -0
- package/src/components/Combobox/Option.tsx +41 -0
- package/src/components/Combobox/fixtures.tsx +204 -0
- package/src/components/Combobox/index.tsx +2 -0
- package/src/components/Combobox/types.tsx +38 -0
- package/src/components/Combobox/useComboboxHighlight.test.tsx +242 -0
- package/src/components/Combobox/useComboboxHighlight.tsx +88 -0
- package/src/components/Combobox/utils.test.tsx +120 -0
- package/src/components/Combobox/utils.tsx +50 -0
- package/src/components/TextArea/TextArea.tsx +6 -6
- package/src/components/TextAreaInput/TextAreaInput.tsx +16 -4
- package/src/components/TextField/TextField.test.tsx +8 -0
- package/src/components/TextField/TextField.tsx +3 -1
- package/src/components/index.tsx +1 -0
- package/src/hooks/useTextField/types.tsx +7 -1
- package/src/hooks/useTextField/useTextField.test.tsx +1 -0
- package/src/hooks/useTextField/useTextField.tsx +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7352bc8: Support home/end key navigation in Combobox component
|
|
8
|
+
- b2d5b4b: Add support for group headings to `Combobox` component
|
|
9
|
+
- 3708724: Add props and docs to Combobox
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3da7d02: Fix leaking React props
|
|
14
|
+
|
|
15
|
+
## 5.5.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- af05836: Adds `role` attribute to `useTextfield` hook
|
|
20
|
+
- ec04e00: Fix `Checkbox` is not checked when clicked
|
|
21
|
+
- a0d927d: Add keyboard events to `useTextField` props
|
|
22
|
+
- cc9aad5: Add `Combobox` component
|
|
23
|
+
- d1b33b1: Add Rocket Lawyer theme
|
|
24
|
+
|
|
3
25
|
## 5.4.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
@@ -25,16 +25,26 @@ function _interop_require_default(obj) {
|
|
|
25
25
|
}
|
|
26
26
|
const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
27
27
|
const { id, label, isDisabled, isRequired, validationState, isInvalid, onChange, className, errorMessage, selected, defaultSelected = false, isReadOnly, isLastItem, name, value, ["aria-describedby"]: ariaDescribedBy, ...rest } = props;
|
|
28
|
+
const [checked, setChecked] = (0, _react.useState)(defaultSelected);
|
|
28
29
|
const fallbackRef = (0, _react.useRef)(null);
|
|
29
30
|
const refObj = ref || fallbackRef;
|
|
30
31
|
const inputId = (0, _react.useId)();
|
|
32
|
+
const isControlled = typeof selected === "boolean";
|
|
33
|
+
(0, _react.useEffect)(()=>{
|
|
34
|
+
if (isControlled) {
|
|
35
|
+
setChecked(selected);
|
|
36
|
+
}
|
|
37
|
+
}, [
|
|
38
|
+
selected,
|
|
39
|
+
isControlled
|
|
40
|
+
]);
|
|
31
41
|
const validationClasses = (0, _hooks.useValidationClasses)({
|
|
32
42
|
validationState,
|
|
33
43
|
isInvalid
|
|
34
44
|
});
|
|
35
45
|
const sharedClasses = (0, _dedupe.default)({
|
|
36
46
|
"--is-disabled": isDisabled,
|
|
37
|
-
"--is-selected":
|
|
47
|
+
"--is-selected": checked,
|
|
38
48
|
"--is-required": typeof isRequired === "boolean" && isRequired,
|
|
39
49
|
"--is-optional": typeof isRequired === "boolean" && !isRequired
|
|
40
50
|
}, validationClasses);
|
|
@@ -51,11 +61,11 @@ const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
51
61
|
]);
|
|
52
62
|
const labelId = (0, _react.useId)();
|
|
53
63
|
const handleChange = (event)=>{
|
|
64
|
+
setChecked(!checked);
|
|
54
65
|
if (onChange) {
|
|
55
66
|
onChange(event, isLastItem);
|
|
56
67
|
}
|
|
57
68
|
};
|
|
58
|
-
const isControlled = typeof props.selected === "boolean";
|
|
59
69
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_Stack.Stack, {
|
|
60
70
|
gap: "xs",
|
|
61
71
|
className: wrapperClasses,
|
|
@@ -74,8 +84,7 @@ const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
74
84
|
className: inputClasses,
|
|
75
85
|
onChange: handleChange,
|
|
76
86
|
type: "checkbox",
|
|
77
|
-
checked:
|
|
78
|
-
defaultChecked: isControlled ? undefined : defaultSelected,
|
|
87
|
+
checked: checked,
|
|
79
88
|
required: isRequired,
|
|
80
89
|
id: id || inputId,
|
|
81
90
|
name: name,
|
|
@@ -83,7 +92,7 @@ const Checkbox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
83
92
|
...rest
|
|
84
93
|
}),
|
|
85
94
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_Icon.Icon, {
|
|
86
|
-
icon:
|
|
95
|
+
icon: checked ? _icons.squareTick : _icons.square,
|
|
87
96
|
size: "md",
|
|
88
97
|
className: iconClasses
|
|
89
98
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ChangeEvent,\n forwardRef,\n useRef,\n useId,\n useState,\n useEffect,\n} from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { squareTick, square } from \"@simplybusiness/icons\";\nimport { ErrorMessage } from \"../ErrorMessage\";\nimport { ForwardedRefComponent } from \"../../types/components\";\nimport { CheckboxElementType, CheckboxProps, CheckboxRef } from \"./types\";\nimport { spaceDelimitedList } from \"../../utils/spaceDelimitedList\";\nimport { useValidationClasses } from \"../../hooks\";\nimport { Icon } from \"../Icon\";\nimport { Stack } from \"../Stack\";\n\nexport const Checkbox: ForwardedRefComponent<\n CheckboxProps,\n CheckboxElementType\n> = forwardRef((props: CheckboxProps, ref: CheckboxRef) => {\n const {\n id,\n label,\n isDisabled,\n isRequired,\n validationState,\n isInvalid,\n onChange,\n className,\n errorMessage,\n selected,\n defaultSelected = false,\n isReadOnly,\n isLastItem,\n name,\n value,\n [\"aria-describedby\"]: ariaDescribedBy,\n ...rest\n } = props;\n const [checked, setChecked] = useState<boolean>(defaultSelected);\n const fallbackRef = useRef<HTMLInputElement>(null);\n const refObj = ref || fallbackRef;\n const inputId = useId();\n\n const isControlled = typeof selected === \"boolean\";\n useEffect(() => {\n if (isControlled) {\n setChecked(selected);\n }\n }, [selected, isControlled]);\n\n const validationClasses = useValidationClasses({\n validationState,\n isInvalid,\n });\n const sharedClasses = classNames(\n {\n \"--is-disabled\": isDisabled,\n \"--is-selected\": checked,\n \"--is-required\": typeof isRequired === \"boolean\" && isRequired,\n \"--is-optional\": typeof isRequired === \"boolean\" && !isRequired,\n },\n validationClasses,\n );\n // Append an additional wrapper class name to differenitate from input\n const wrapperClasses = classNames(\n \"mobius\",\n \"mobius-checkbox\",\n sharedClasses,\n className,\n );\n const labelClasses = classNames(\"mobius-checkbox__label\", sharedClasses);\n const inputClasses = classNames(\"mobius-checkbox__input\", sharedClasses);\n const iconClasses = classNames(\"mobius-checkbox__icon\", sharedClasses);\n const errorMessageId = useId();\n const shouldErrorMessageShow = errorMessage ? errorMessageId : undefined;\n const describedBy = spaceDelimitedList([\n shouldErrorMessageShow,\n ariaDescribedBy,\n ]);\n const labelId = useId();\n\n const handleChange = (event: ChangeEvent<CheckboxElementType>) => {\n setChecked(!checked);\n if (onChange) {\n onChange(event, isLastItem);\n }\n };\n\n return (\n <Stack gap=\"xs\" className={wrapperClasses}>\n <label className={labelClasses}>\n <input\n aria-describedby={describedBy}\n aria-errormessage={shouldErrorMessageShow}\n aria-invalid={isInvalid}\n aria-labelledby={labelId}\n readOnly={isReadOnly}\n disabled={isDisabled}\n ref={refObj}\n className={inputClasses}\n onChange={handleChange}\n type=\"checkbox\"\n checked={checked}\n required={isRequired}\n id={id || inputId}\n name={name}\n value={value}\n {...rest}\n />\n <Icon\n icon={checked ? squareTick : square}\n size=\"md\"\n className={iconClasses}\n />\n <span id={labelId} className=\"mobius-checkbox__visible-label\">\n {label}\n </span>\n </label>\n <ErrorMessage id={errorMessageId} errorMessage={errorMessage} />\n </Stack>\n );\n});\n"],"names":["Checkbox","forwardRef","props","ref","id","label","isDisabled","isRequired","validationState","isInvalid","onChange","className","errorMessage","selected","defaultSelected","isReadOnly","isLastItem","name","value","ariaDescribedBy","rest","checked","setChecked","useState","fallbackRef","useRef","refObj","inputId","useId","isControlled","useEffect","validationClasses","useValidationClasses","sharedClasses","classNames","wrapperClasses","labelClasses","inputClasses","iconClasses","errorMessageId","shouldErrorMessageShow","undefined","describedBy","spaceDelimitedList","labelId","handleChange","event","Stack","gap","input","aria-describedby","aria-errormessage","aria-invalid","aria-labelledby","readOnly","disabled","type","required","Icon","icon","squareTick","square","size","span","ErrorMessage"],"mappings":"AAAA;;;;;+BAoBaA;;;eAAAA;;;;uBAXN;+DACgB;uBACY;8BACN;oCAGM;uBACE;sBAChB;uBACC;;;;;;AAEf,MAAMA,yBAGTC,IAAAA,iBAAU,EAAC,CAACC,OAAsBC;IACpC,MAAM,EACJC,EAAE,EACFC,KAAK,EACLC,UAAU,EACVC,UAAU,EACVC,eAAe,EACfC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,YAAY,EACZC,QAAQ,EACRC,kBAAkB,KAAK,EACvBC,UAAU,EACVC,UAAU,EACVC,IAAI,EACJC,KAAK,EACL,CAAC,mBAAmB,EAAEC,eAAe,EACrC,GAAGC,MACJ,GAAGlB;IACJ,MAAM,CAACmB,SAASC,WAAW,GAAGC,IAAAA,eAAQ,EAAUT;IAChD,MAAMU,cAAcC,IAAAA,aAAM,EAAmB;IAC7C,MAAMC,SAASvB,OAAOqB;IACtB,MAAMG,UAAUC,IAAAA,YAAK;IAErB,MAAMC,eAAe,OAAOhB,aAAa;IACzCiB,IAAAA,gBAAS,EAAC;QACR,IAAID,cAAc;YAChBP,WAAWT;QACb;IACF,GAAG;QAACA;QAAUgB;KAAa;IAE3B,MAAME,oBAAoBC,IAAAA,2BAAoB,EAAC;QAC7CxB;QACAC;IACF;IACA,MAAMwB,gBAAgBC,IAAAA,eAAU,EAC9B;QACE,iBAAiB5B;QACjB,iBAAiBe;QACjB,iBAAiB,OAAOd,eAAe,aAAaA;QACpD,iBAAiB,OAAOA,eAAe,aAAa,CAACA;IACvD,GACAwB;IAEF,sEAAsE;IACtE,MAAMI,iBAAiBD,IAAAA,eAAU,EAC/B,UACA,mBACAD,eACAtB;IAEF,MAAMyB,eAAeF,IAAAA,eAAU,EAAC,0BAA0BD;IAC1D,MAAMI,eAAeH,IAAAA,eAAU,EAAC,0BAA0BD;IAC1D,MAAMK,cAAcJ,IAAAA,eAAU,EAAC,yBAAyBD;IACxD,MAAMM,iBAAiBX,IAAAA,YAAK;IAC5B,MAAMY,yBAAyB5B,eAAe2B,iBAAiBE;IAC/D,MAAMC,cAAcC,IAAAA,sCAAkB,EAAC;QACrCH;QACArB;KACD;IACD,MAAMyB,UAAUhB,IAAAA,YAAK;IAErB,MAAMiB,eAAe,CAACC;QACpBxB,WAAW,CAACD;QACZ,IAAIX,UAAU;YACZA,SAASoC,OAAO9B;QAClB;IACF;IAEA,qBACE,sBAAC+B,YAAK;QAACC,KAAI;QAAKrC,WAAWwB;;0BACzB,sBAAC9B;gBAAMM,WAAWyB;;kCAChB,qBAACa;wBACCC,oBAAkBR;wBAClBS,qBAAmBX;wBACnBY,gBAAc3C;wBACd4C,mBAAiBT;wBACjBU,UAAUvC;wBACVwC,UAAUjD;wBACVH,KAAKuB;wBACLf,WAAW0B;wBACX3B,UAAUmC;wBACVW,MAAK;wBACLnC,SAASA;wBACToC,UAAUlD;wBACVH,IAAIA,MAAMuB;wBACVV,MAAMA;wBACNC,OAAOA;wBACN,GAAGE,IAAI;;kCAEV,qBAACsC,UAAI;wBACHC,MAAMtC,UAAUuC,iBAAU,GAAGC,aAAM;wBACnCC,MAAK;wBACLnD,WAAW2B;;kCAEb,qBAACyB;wBAAK3D,IAAIwC;wBAASjC,WAAU;kCAC1BN;;;;0BAGL,qBAAC2D,0BAAY;gBAAC5D,IAAImC;gBAAgB3B,cAAcA;;;;AAGtD"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Combobox", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Combobox;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
+
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
13
|
+
const _react = require("react");
|
|
14
|
+
const _TextField = require("../TextField");
|
|
15
|
+
const _Listbox = require("./Listbox");
|
|
16
|
+
const _useComboboxHighlight = require("./useComboboxHighlight");
|
|
17
|
+
const _utils = require("./utils");
|
|
18
|
+
function _interop_require_default(obj) {
|
|
19
|
+
return obj && obj.__esModule ? obj : {
|
|
20
|
+
default: obj
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const Combobox = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
24
|
+
const { defaultValue, options, onSelected, className, placeholder, icon } = props;
|
|
25
|
+
const fallbackRef = (0, _react.useRef)(null);
|
|
26
|
+
const [inputValue, setInputValue] = (0, _react.useState)(defaultValue || "");
|
|
27
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
28
|
+
const [filteredOptions, setFilteredOptions] = (0, _react.useState)([]);
|
|
29
|
+
const { highlightedIndex, highlightedGroupIndex, highlightNextOption, highlightPreviousOption, highlightFirstOption, highlightLastOption, clearHighlight } = (0, _useComboboxHighlight.useComboboxHighlight)(filteredOptions);
|
|
30
|
+
const inputRef = ref || fallbackRef;
|
|
31
|
+
const listboxId = (0, _react.useId)();
|
|
32
|
+
const blurTimeoutRef = (0, _react.useRef)(null);
|
|
33
|
+
(0, _react.useEffect)(()=>{
|
|
34
|
+
const fetchOptions = async ()=>{
|
|
35
|
+
if (typeof options === "function") {
|
|
36
|
+
const result = await options(inputValue);
|
|
37
|
+
setFilteredOptions(result);
|
|
38
|
+
} else {
|
|
39
|
+
setFilteredOptions((0, _utils.filterOptions)(options, inputValue));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
fetchOptions();
|
|
43
|
+
}, [
|
|
44
|
+
inputValue,
|
|
45
|
+
options
|
|
46
|
+
]);
|
|
47
|
+
const handleFocus = ()=>{
|
|
48
|
+
if (blurTimeoutRef.current) {
|
|
49
|
+
clearTimeout(blurTimeoutRef.current);
|
|
50
|
+
blurTimeoutRef.current = null;
|
|
51
|
+
}
|
|
52
|
+
setIsOpen(true);
|
|
53
|
+
};
|
|
54
|
+
const handleBlur = ()=>{
|
|
55
|
+
blurTimeoutRef.current = setTimeout(()=>{
|
|
56
|
+
setIsOpen(false);
|
|
57
|
+
}, 150);
|
|
58
|
+
};
|
|
59
|
+
const handleInputChange = (e)=>{
|
|
60
|
+
const newValue = e.target.value;
|
|
61
|
+
setInputValue(newValue);
|
|
62
|
+
setIsOpen(true);
|
|
63
|
+
clearHighlight();
|
|
64
|
+
};
|
|
65
|
+
const handleOptionSelect = (option)=>{
|
|
66
|
+
const value = (0, _utils.getOptionValue)(option);
|
|
67
|
+
if (!value) return;
|
|
68
|
+
setIsOpen(false);
|
|
69
|
+
setInputValue(value);
|
|
70
|
+
onSelected === null || onSelected === void 0 ? void 0 : onSelected(value);
|
|
71
|
+
};
|
|
72
|
+
function getHighlightedOption() {
|
|
73
|
+
if (highlightedIndex === -1) return undefined;
|
|
74
|
+
if ((0, _utils.isOptionGroup)(filteredOptions)) {
|
|
75
|
+
const group = filteredOptions[highlightedGroupIndex];
|
|
76
|
+
return group === null || group === void 0 ? void 0 : group.options[highlightedIndex];
|
|
77
|
+
}
|
|
78
|
+
return filteredOptions[highlightedIndex];
|
|
79
|
+
}
|
|
80
|
+
const handleKeyDown = (e)=>{
|
|
81
|
+
switch(e.key){
|
|
82
|
+
case "ArrowDown":
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
setIsOpen(true);
|
|
85
|
+
highlightNextOption();
|
|
86
|
+
break;
|
|
87
|
+
case "ArrowUp":
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
setIsOpen(true);
|
|
90
|
+
highlightPreviousOption();
|
|
91
|
+
break;
|
|
92
|
+
case "Home":
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
setIsOpen(true);
|
|
95
|
+
highlightFirstOption();
|
|
96
|
+
break;
|
|
97
|
+
case "End":
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
setIsOpen(true);
|
|
100
|
+
highlightLastOption();
|
|
101
|
+
break;
|
|
102
|
+
case "Enter":
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
if (isOpen) {
|
|
105
|
+
handleOptionSelect(getHighlightedOption());
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "Escape":
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
setIsOpen(false);
|
|
111
|
+
clearHighlight();
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const classes = (0, _dedupe.default)("mobius mobius-combobox", {
|
|
117
|
+
expanded: isOpen
|
|
118
|
+
}, className);
|
|
119
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
120
|
+
className: classes,
|
|
121
|
+
children: [
|
|
122
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_TextField.TextField, {
|
|
123
|
+
className: "mobius-combobox__input",
|
|
124
|
+
role: "combobox",
|
|
125
|
+
value: inputValue,
|
|
126
|
+
placeholder: placeholder,
|
|
127
|
+
onFocus: handleFocus,
|
|
128
|
+
onBlur: handleBlur,
|
|
129
|
+
onKeyDown: handleKeyDown,
|
|
130
|
+
onChange: handleInputChange,
|
|
131
|
+
autoComplete: "off",
|
|
132
|
+
"aria-autocomplete": "list",
|
|
133
|
+
"aria-haspopup": "listbox",
|
|
134
|
+
"aria-controls": listboxId,
|
|
135
|
+
"aria-expanded": isOpen,
|
|
136
|
+
"aria-activedescendant": highlightedIndex === -1 ? undefined : `${listboxId}-option-${highlightedGroupIndex}-${highlightedIndex}`,
|
|
137
|
+
prefixInside: icon,
|
|
138
|
+
ref: inputRef
|
|
139
|
+
}),
|
|
140
|
+
isOpen && /*#__PURE__*/ (0, _jsxruntime.jsx)(_Listbox.Listbox, {
|
|
141
|
+
id: listboxId,
|
|
142
|
+
options: filteredOptions,
|
|
143
|
+
highlightedIndex: highlightedIndex,
|
|
144
|
+
highlightedGroupIndex: highlightedGroupIndex,
|
|
145
|
+
onOptionSelect: handleOptionSelect,
|
|
146
|
+
expanded: isOpen
|
|
147
|
+
})
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=Combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import classNames from \"classnames/dedupe\";\nimport { forwardRef, useEffect, useId, useRef, useState } from \"react\";\nimport type { ForwardedRefComponent } from \"../../types\";\nimport { TextField } from \"../TextField\";\nimport { Listbox } from \"./Listbox\"; // Import Listbox component\nimport type {\n ComboboxElementType,\n ComboboxOption,\n ComboboxOptions,\n ComboboxProps,\n ComboboxRef,\n} from \"./types\";\nimport { useComboboxHighlight } from \"./useComboboxHighlight\";\nimport { filterOptions, getOptionValue, isOptionGroup } from \"./utils\";\n\nexport const Combobox: ForwardedRefComponent<\n ComboboxProps,\n ComboboxElementType\n> = forwardRef((props: ComboboxProps, ref: ComboboxRef) => {\n const { defaultValue, options, onSelected, className, placeholder, icon } =\n props;\n\n const fallbackRef = useRef<HTMLInputElement>(null);\n const [inputValue, setInputValue] = useState(defaultValue || \"\");\n const [isOpen, setIsOpen] = useState(false);\n const [filteredOptions, setFilteredOptions] = useState<ComboboxOptions>([]);\n const {\n highlightedIndex,\n highlightedGroupIndex,\n highlightNextOption,\n highlightPreviousOption,\n highlightFirstOption,\n highlightLastOption,\n clearHighlight,\n } = useComboboxHighlight(filteredOptions);\n\n const inputRef = ref || fallbackRef;\n const listboxId = useId();\n const blurTimeoutRef = useRef<NodeJS.Timeout | null>(null);\n\n useEffect(() => {\n const fetchOptions = async () => {\n if (typeof options === \"function\") {\n const result = await options(inputValue);\n setFilteredOptions(result);\n } else {\n setFilteredOptions(filterOptions(options, inputValue));\n }\n };\n\n fetchOptions();\n }, [inputValue, options]);\n\n const handleFocus = () => {\n if (blurTimeoutRef.current) {\n clearTimeout(blurTimeoutRef.current);\n blurTimeoutRef.current = null;\n }\n setIsOpen(true);\n };\n\n const handleBlur = () => {\n blurTimeoutRef.current = setTimeout(() => {\n setIsOpen(false);\n }, 150);\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = e.target.value;\n setInputValue(newValue);\n setIsOpen(true);\n clearHighlight();\n };\n\n const handleOptionSelect = (option: ComboboxOption) => {\n const value = getOptionValue(option);\n if (!value) return;\n setIsOpen(false);\n setInputValue(value);\n onSelected?.(value);\n };\n\n function getHighlightedOption() {\n if (highlightedIndex === -1) return undefined;\n\n if (isOptionGroup(filteredOptions)) {\n const group = filteredOptions[highlightedGroupIndex];\n return group?.options[highlightedIndex];\n }\n\n return filteredOptions[highlightedIndex];\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case \"ArrowDown\":\n e.preventDefault();\n setIsOpen(true);\n highlightNextOption();\n break;\n case \"ArrowUp\":\n e.preventDefault();\n setIsOpen(true);\n highlightPreviousOption();\n break;\n case \"Home\":\n e.preventDefault();\n setIsOpen(true);\n highlightFirstOption();\n break;\n case \"End\":\n e.preventDefault();\n setIsOpen(true);\n highlightLastOption();\n break;\n case \"Enter\":\n e.preventDefault();\n if (isOpen) {\n handleOptionSelect(getHighlightedOption()!);\n }\n break;\n case \"Escape\":\n e.preventDefault();\n setIsOpen(false);\n clearHighlight();\n break;\n default:\n // Do nothing\n }\n };\n\n const classes = classNames(\n \"mobius mobius-combobox\",\n { expanded: isOpen },\n className,\n );\n\n return (\n <div className={classes}>\n <TextField\n className=\"mobius-combobox__input\"\n role=\"combobox\"\n value={inputValue}\n placeholder={placeholder}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n onChange={handleInputChange}\n autoComplete=\"off\"\n aria-autocomplete=\"list\"\n aria-haspopup=\"listbox\"\n aria-controls={listboxId}\n aria-expanded={isOpen}\n aria-activedescendant={\n highlightedIndex === -1\n ? undefined\n : `${listboxId}-option-${highlightedGroupIndex}-${highlightedIndex}`\n }\n prefixInside={icon}\n ref={inputRef}\n />\n {isOpen && (\n <Listbox\n id={listboxId}\n options={filteredOptions}\n highlightedIndex={highlightedIndex}\n highlightedGroupIndex={highlightedGroupIndex}\n onOptionSelect={handleOptionSelect}\n expanded={isOpen}\n />\n )}\n </div>\n );\n});\n"],"names":["Combobox","forwardRef","props","ref","defaultValue","options","onSelected","className","placeholder","icon","fallbackRef","useRef","inputValue","setInputValue","useState","isOpen","setIsOpen","filteredOptions","setFilteredOptions","highlightedIndex","highlightedGroupIndex","highlightNextOption","highlightPreviousOption","highlightFirstOption","highlightLastOption","clearHighlight","useComboboxHighlight","inputRef","listboxId","useId","blurTimeoutRef","useEffect","fetchOptions","result","filterOptions","handleFocus","current","clearTimeout","handleBlur","setTimeout","handleInputChange","e","newValue","target","value","handleOptionSelect","option","getOptionValue","getHighlightedOption","undefined","isOptionGroup","group","handleKeyDown","key","preventDefault","classes","classNames","expanded","div","TextField","role","onFocus","onBlur","onKeyDown","onChange","autoComplete","aria-autocomplete","aria-haspopup","aria-controls","aria-expanded","aria-activedescendant","prefixInside","Listbox","id","onOptionSelect"],"mappings":";;;;+BAeaA;;;eAAAA;;;;+DAfU;uBACwC;2BAErC;yBACF;sCAQa;uBACwB;;;;;;AAEtD,MAAMA,yBAGTC,IAAAA,iBAAU,EAAC,CAACC,OAAsBC;IACpC,MAAM,EAAEC,YAAY,EAAEC,OAAO,EAAEC,UAAU,EAAEC,SAAS,EAAEC,WAAW,EAAEC,IAAI,EAAE,GACvEP;IAEF,MAAMQ,cAAcC,IAAAA,aAAM,EAAmB;IAC7C,MAAM,CAACC,YAAYC,cAAc,GAAGC,IAAAA,eAAQ,EAACV,gBAAgB;IAC7D,MAAM,CAACW,QAAQC,UAAU,GAAGF,IAAAA,eAAQ,EAAC;IACrC,MAAM,CAACG,iBAAiBC,mBAAmB,GAAGJ,IAAAA,eAAQ,EAAkB,EAAE;IAC1E,MAAM,EACJK,gBAAgB,EAChBC,qBAAqB,EACrBC,mBAAmB,EACnBC,uBAAuB,EACvBC,oBAAoB,EACpBC,mBAAmB,EACnBC,cAAc,EACf,GAAGC,IAAAA,0CAAoB,EAACT;IAEzB,MAAMU,WAAWxB,OAAOO;IACxB,MAAMkB,YAAYC,IAAAA,YAAK;IACvB,MAAMC,iBAAiBnB,IAAAA,aAAM,EAAwB;IAErDoB,IAAAA,gBAAS,EAAC;QACR,MAAMC,eAAe;YACnB,IAAI,OAAO3B,YAAY,YAAY;gBACjC,MAAM4B,SAAS,MAAM5B,QAAQO;gBAC7BM,mBAAmBe;YACrB,OAAO;gBACLf,mBAAmBgB,IAAAA,oBAAa,EAAC7B,SAASO;YAC5C;QACF;QAEAoB;IACF,GAAG;QAACpB;QAAYP;KAAQ;IAExB,MAAM8B,cAAc;QAClB,IAAIL,eAAeM,OAAO,EAAE;YAC1BC,aAAaP,eAAeM,OAAO;YACnCN,eAAeM,OAAO,GAAG;QAC3B;QACApB,UAAU;IACZ;IAEA,MAAMsB,aAAa;QACjBR,eAAeM,OAAO,GAAGG,WAAW;YAClCvB,UAAU;QACZ,GAAG;IACL;IAEA,MAAMwB,oBAAoB,CAACC;QACzB,MAAMC,WAAWD,EAAEE,MAAM,CAACC,KAAK;QAC/B/B,cAAc6B;QACd1B,UAAU;QACVS;IACF;IAEA,MAAMoB,qBAAqB,CAACC;QAC1B,MAAMF,QAAQG,IAAAA,qBAAc,EAACD;QAC7B,IAAI,CAACF,OAAO;QACZ5B,UAAU;QACVH,cAAc+B;QACdtC,uBAAAA,iCAAAA,WAAasC;IACf;IAEA,SAASI;QACP,IAAI7B,qBAAqB,CAAC,GAAG,OAAO8B;QAEpC,IAAIC,IAAAA,oBAAa,EAACjC,kBAAkB;YAClC,MAAMkC,QAAQlC,eAAe,CAACG,sBAAsB;YACpD,OAAO+B,kBAAAA,4BAAAA,MAAO9C,OAAO,CAACc,iBAAiB;QACzC;QAEA,OAAOF,eAAe,CAACE,iBAAiB;IAC1C;IAEA,MAAMiC,gBAAgB,CAACX;QACrB,OAAQA,EAAEY,GAAG;YACX,KAAK;gBACHZ,EAAEa,cAAc;gBAChBtC,UAAU;gBACVK;gBACA;YACF,KAAK;gBACHoB,EAAEa,cAAc;gBAChBtC,UAAU;gBACVM;gBACA;YACF,KAAK;gBACHmB,EAAEa,cAAc;gBAChBtC,UAAU;gBACVO;gBACA;YACF,KAAK;gBACHkB,EAAEa,cAAc;gBAChBtC,UAAU;gBACVQ;gBACA;YACF,KAAK;gBACHiB,EAAEa,cAAc;gBAChB,IAAIvC,QAAQ;oBACV8B,mBAAmBG;gBACrB;gBACA;YACF,KAAK;gBACHP,EAAEa,cAAc;gBAChBtC,UAAU;gBACVS;gBACA;YACF;QAEF;IACF;IAEA,MAAM8B,UAAUC,IAAAA,eAAU,EACxB,0BACA;QAAEC,UAAU1C;IAAO,GACnBR;IAGF,qBACE,sBAACmD;QAAInD,WAAWgD;;0BACd,qBAACI,oBAAS;gBACRpD,WAAU;gBACVqD,MAAK;gBACLhB,OAAOhC;gBACPJ,aAAaA;gBACbqD,SAAS1B;gBACT2B,QAAQxB;gBACRyB,WAAWX;gBACXY,UAAUxB;gBACVyB,cAAa;gBACbC,qBAAkB;gBAClBC,iBAAc;gBACdC,iBAAexC;gBACfyC,iBAAetD;gBACfuD,yBACEnD,qBAAqB,CAAC,IAClB8B,YACA,GAAGrB,UAAU,QAAQ,EAAER,sBAAsB,CAAC,EAAED,kBAAkB;gBAExEoD,cAAc9D;gBACdN,KAAKwB;;YAENZ,wBACC,qBAACyD,gBAAO;gBACNC,IAAI7C;gBACJvB,SAASY;gBACTE,kBAAkBA;gBAClBC,uBAAuBA;gBACvBsD,gBAAgB7B;gBAChBY,UAAU1C;;;;AAKpB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Listbox", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Listbox;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
+
const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
|
|
13
|
+
const _Option = require("./Option");
|
|
14
|
+
const _utils = require("./utils");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const Listbox = ({ id, options, highlightedIndex, highlightedGroupIndex, onOptionSelect, expanded = false })=>{
|
|
21
|
+
const classes = (0, _classnames.default)("mobius-combobox__list", {
|
|
22
|
+
expanded
|
|
23
|
+
});
|
|
24
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
25
|
+
role: "listbox",
|
|
26
|
+
id: id,
|
|
27
|
+
className: classes,
|
|
28
|
+
children: (0, _utils.isOptionGroup)(options) ? options.map((option, groupIndex)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("ul", {
|
|
29
|
+
role: "group",
|
|
30
|
+
"aria-labelledby": `${id}-group-${groupIndex}`,
|
|
31
|
+
className: "mobius-combobox__group",
|
|
32
|
+
children: [
|
|
33
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("li", {
|
|
34
|
+
role: "presentation",
|
|
35
|
+
id: `${id}-group-${groupIndex}`,
|
|
36
|
+
className: "mobius-combobox__group-label",
|
|
37
|
+
children: option.heading
|
|
38
|
+
}),
|
|
39
|
+
option.options.map((groupOption, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_Option.Option, {
|
|
40
|
+
option: groupOption,
|
|
41
|
+
index: index,
|
|
42
|
+
groupIndex: groupIndex,
|
|
43
|
+
isHighlighted: highlightedIndex === index && highlightedGroupIndex === groupIndex,
|
|
44
|
+
onOptionSelect: onOptionSelect,
|
|
45
|
+
id: id
|
|
46
|
+
}, `${id}-option-${groupIndex}-${index}`))
|
|
47
|
+
]
|
|
48
|
+
}, option.heading)) : options.map((option, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_Option.Option, {
|
|
49
|
+
option: option,
|
|
50
|
+
index: index,
|
|
51
|
+
isHighlighted: highlightedIndex === index,
|
|
52
|
+
onOptionSelect: onOptionSelect,
|
|
53
|
+
id: id
|
|
54
|
+
}, index))
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=Listbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/Listbox.tsx"],"sourcesContent":["import classNames from \"classnames\";\nimport { Option } from \"./Option\";\nimport type { ComboboxOption, ComboboxOptions } from \"./types\";\nimport { isOptionGroup } from \"./utils\";\n\nexport type ListboxProps = {\n id: string;\n options: ComboboxOptions;\n highlightedIndex: number;\n highlightedGroupIndex: number;\n onOptionSelect: (option: ComboboxOption) => void;\n expanded?: boolean;\n};\n\nexport const Listbox = ({\n id,\n options,\n highlightedIndex,\n highlightedGroupIndex,\n onOptionSelect,\n expanded = false,\n}: ListboxProps) => {\n const classes = classNames(\"mobius-combobox__list\", {\n expanded,\n });\n\n return (\n <div role=\"listbox\" id={id} className={classes}>\n {isOptionGroup(options)\n ? options.map((option, groupIndex) => (\n <ul\n role=\"group\"\n key={option.heading}\n aria-labelledby={`${id}-group-${groupIndex}`}\n className=\"mobius-combobox__group\"\n >\n <li\n role=\"presentation\"\n id={`${id}-group-${groupIndex}`}\n className=\"mobius-combobox__group-label\"\n >\n {option.heading}\n </li>\n {option.options.map((groupOption, index) => (\n <Option\n // eslint-disable-next-line react/no-array-index-key\n key={`${id}-option-${groupIndex}-${index}`}\n option={groupOption}\n index={index}\n groupIndex={groupIndex}\n isHighlighted={\n highlightedIndex === index &&\n highlightedGroupIndex === groupIndex\n }\n onOptionSelect={onOptionSelect}\n id={id}\n />\n ))}\n </ul>\n ))\n : options.map((option, index) => (\n <Option\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n option={option}\n index={index}\n isHighlighted={highlightedIndex === index}\n onOptionSelect={onOptionSelect}\n id={id}\n />\n ))}\n </div>\n );\n};\n"],"names":["Listbox","id","options","highlightedIndex","highlightedGroupIndex","onOptionSelect","expanded","classes","classNames","div","role","className","isOptionGroup","map","option","groupIndex","ul","aria-labelledby","li","heading","groupOption","index","Option","isHighlighted"],"mappings":";;;;+BAcaA;;;eAAAA;;;;mEAdU;wBACA;uBAEO;;;;;;AAWvB,MAAMA,UAAU,CAAC,EACtBC,EAAE,EACFC,OAAO,EACPC,gBAAgB,EAChBC,qBAAqB,EACrBC,cAAc,EACdC,WAAW,KAAK,EACH;IACb,MAAMC,UAAUC,IAAAA,mBAAU,EAAC,yBAAyB;QAClDF;IACF;IAEA,qBACE,qBAACG;QAAIC,MAAK;QAAUT,IAAIA;QAAIU,WAAWJ;kBACpCK,IAAAA,oBAAa,EAACV,WACXA,QAAQW,GAAG,CAAC,CAACC,QAAQC,2BACnB,sBAACC;gBACCN,MAAK;gBAELO,mBAAiB,GAAGhB,GAAG,OAAO,EAAEc,YAAY;gBAC5CJ,WAAU;;kCAEV,qBAACO;wBACCR,MAAK;wBACLT,IAAI,GAAGA,GAAG,OAAO,EAAEc,YAAY;wBAC/BJ,WAAU;kCAETG,OAAOK,OAAO;;oBAEhBL,OAAOZ,OAAO,CAACW,GAAG,CAAC,CAACO,aAAaC,sBAChC,qBAACC,cAAM;4BAGLR,QAAQM;4BACRC,OAAOA;4BACPN,YAAYA;4BACZQ,eACEpB,qBAAqBkB,SACrBjB,0BAA0BW;4BAE5BV,gBAAgBA;4BAChBJ,IAAIA;2BATC,GAAGA,GAAG,QAAQ,EAAEc,WAAW,CAAC,EAAEM,OAAO;;eAdzCP,OAAOK,OAAO,KA4BvBjB,QAAQW,GAAG,CAAC,CAACC,QAAQO,sBACnB,qBAACC,cAAM;gBAGLR,QAAQA;gBACRO,OAAOA;gBACPE,eAAepB,qBAAqBkB;gBACpChB,gBAAgBA;gBAChBJ,IAAIA;eALCoB;;AAUnB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Option", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Option;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
+
const _react = require("react");
|
|
13
|
+
const _dedupe = /*#__PURE__*/ _interop_require_default(require("classnames/dedupe"));
|
|
14
|
+
const _utils = require("./utils");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const Option = ({ option, index, groupIndex = 0, isHighlighted, onOptionSelect, id })=>{
|
|
21
|
+
const optionRef = (0, _react.useRef)(null);
|
|
22
|
+
(0, _react.useEffect)(()=>{
|
|
23
|
+
if (isHighlighted && optionRef.current && optionRef.current.scrollIntoView) {
|
|
24
|
+
optionRef.current.scrollIntoView({
|
|
25
|
+
block: "nearest"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, [
|
|
29
|
+
isHighlighted
|
|
30
|
+
]);
|
|
31
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)("li", {
|
|
32
|
+
ref: optionRef,
|
|
33
|
+
role: "option",
|
|
34
|
+
id: `${id}-option-${groupIndex}-${index}`,
|
|
35
|
+
"aria-selected": isHighlighted,
|
|
36
|
+
onMouseDown: ()=>onOptionSelect(option),
|
|
37
|
+
className: (0, _dedupe.default)("mobius-combobox__option", {
|
|
38
|
+
"mobius-combobox__option--is-highlighted": isHighlighted
|
|
39
|
+
}),
|
|
40
|
+
children: (0, _utils.getOptionLabel)(option)
|
|
41
|
+
}, (0, _utils.getOptionValue)(option));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=Option.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/Combobox/Option.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport classNames from \"classnames/dedupe\";\nimport { getOptionValue, getOptionLabel } from \"./utils\";\nimport type { ComboboxOptionProps } from \"./types\";\n\nexport const Option = ({\n option,\n index,\n groupIndex = 0,\n isHighlighted,\n onOptionSelect,\n id,\n}: ComboboxOptionProps) => {\n const optionRef = useRef<HTMLLIElement>(null);\n\n useEffect(() => {\n if (\n isHighlighted &&\n optionRef.current &&\n optionRef.current.scrollIntoView\n ) {\n optionRef.current.scrollIntoView({ block: \"nearest\" });\n }\n }, [isHighlighted]);\n\n return (\n <li\n ref={optionRef}\n role=\"option\"\n key={getOptionValue(option)}\n id={`${id}-option-${groupIndex}-${index}`}\n aria-selected={isHighlighted}\n onMouseDown={() => onOptionSelect(option)}\n className={classNames(\"mobius-combobox__option\", {\n \"mobius-combobox__option--is-highlighted\": isHighlighted,\n })}\n >\n {getOptionLabel(option)}\n </li>\n );\n};\n"],"names":["Option","option","index","groupIndex","isHighlighted","onOptionSelect","id","optionRef","useRef","useEffect","current","scrollIntoView","block","li","ref","role","aria-selected","onMouseDown","className","classNames","getOptionLabel","getOptionValue"],"mappings":";;;;+BAKaA;;;eAAAA;;;;uBALqB;+DACX;uBACwB;;;;;;AAGxC,MAAMA,SAAS,CAAC,EACrBC,MAAM,EACNC,KAAK,EACLC,aAAa,CAAC,EACdC,aAAa,EACbC,cAAc,EACdC,EAAE,EACkB;IACpB,MAAMC,YAAYC,IAAAA,aAAM,EAAgB;IAExCC,IAAAA,gBAAS,EAAC;QACR,IACEL,iBACAG,UAAUG,OAAO,IACjBH,UAAUG,OAAO,CAACC,cAAc,EAChC;YACAJ,UAAUG,OAAO,CAACC,cAAc,CAAC;gBAAEC,OAAO;YAAU;QACtD;IACF,GAAG;QAACR;KAAc;IAElB,qBACE,qBAACS;QACCC,KAAKP;QACLQ,MAAK;QAELT,IAAI,GAAGA,GAAG,QAAQ,EAAEH,WAAW,CAAC,EAAED,OAAO;QACzCc,iBAAeZ;QACfa,aAAa,IAAMZ,eAAeJ;QAClCiB,WAAWC,IAAAA,eAAU,EAAC,2BAA2B;YAC/C,2CAA2Cf;QAC7C;kBAECgB,IAAAA,qBAAc,EAACnB;OARXoB,IAAAA,qBAAc,EAACpB;AAW1B"}
|