@pixum/combobox 5.10.5 → 5.10.7
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/lib/ComboBox.d.ts +32 -6
- package/lib/ComboBox.js +212 -77
- package/lib/ComboBox.js.map +1 -1
- package/lib/ComboBox.module.css +1 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useComboBox.d.ts +60 -0
- package/lib/hooks/useComboBox.js +226 -0
- package/lib/hooks/useComboBox.js.map +1 -0
- package/lib/hooks/useComboBoxFocus.d.ts +35 -0
- package/lib/hooks/useComboBoxFocus.js +49 -0
- package/lib/hooks/useComboBoxFocus.js.map +1 -0
- package/lib/hooks/useIsDesktopScreenWidth.d.ts +5 -0
- package/lib/hooks/useIsDesktopScreenWidth.js +34 -24
- package/lib/hooks/useIsDesktopScreenWidth.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/partials/ComboBoxNoResults.d.ts +14 -0
- package/lib/partials/ComboBoxNoResults.js +18 -0
- package/lib/partials/ComboBoxNoResults.js.map +1 -0
- package/lib/partials/ComboBoxOptions.d.ts +16 -5
- package/lib/partials/ComboBoxOptions.js +25 -21
- package/lib/partials/ComboBoxOptions.js.map +1 -1
- package/lib/partials/ComboBoxOptionsGroup.d.ts +15 -0
- package/lib/partials/ComboBoxOptionsGroup.js +31 -0
- package/lib/partials/ComboBoxOptionsGroup.js.map +1 -0
- package/lib/partials/ComboBoxOptionsItems.d.ts +32 -17
- package/lib/partials/ComboBoxOptionsItems.js +46 -14
- package/lib/partials/ComboBoxOptionsItems.js.map +1 -1
- package/lib/partials/ComboBoxOptionsSlot.d.ts +17 -16
- package/lib/partials/ComboBoxOptionsSlot.js +26 -11
- package/lib/partials/ComboBoxOptionsSlot.js.map +1 -1
- package/lib/partials/index.d.ts +2 -1
- package/lib/partials/index.js +2 -1
- package/lib/partials/index.js.map +1 -1
- package/lib/types.d.ts +183 -45
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +1 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/options.d.ts +77 -0
- package/lib/utils/options.js +145 -0
- package/lib/utils/options.js.map +1 -0
- package/package.json +8 -8
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
import { LeadingType } from '@pixum/menu-item';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/** Callback fired when an option is clicked */
|
|
12
|
-
onClick?: (value: string) => void;
|
|
13
|
-
/** Type of leading element to display (icon, avatar, etc.) */
|
|
2
|
+
import type { ComboBoxOption } from '../types';
|
|
3
|
+
export interface ComboBoxOptionsItemsProps {
|
|
4
|
+
/** Normalised options to render. */
|
|
5
|
+
options: ComboBoxOption[];
|
|
6
|
+
/** Values that are currently selected. */
|
|
7
|
+
selectedValues: string[];
|
|
8
|
+
/** DOM id of the active option (`aria-activedescendant`). */
|
|
9
|
+
activeOptionId?: string;
|
|
10
|
+
/** Type of the leading element, e.g. a checkbox for multi select. */
|
|
14
11
|
leadingType?: LeadingType;
|
|
12
|
+
/** Called with the value of the clicked option. */
|
|
13
|
+
onOptionClick: (value: string) => void;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Renders the individual options.
|
|
17
|
+
*
|
|
18
|
+
* The options are deliberately not focusable: the focus stays in the input
|
|
19
|
+
* field and the highlight is driven by `aria-activedescendant`. Checkbox
|
|
20
|
+
* options are ordinary options with `aria-selected` - inside a listbox that is
|
|
21
|
+
* the state screen readers announce, and it keeps mouse and keyboard selection
|
|
22
|
+
* on exactly the same code path.
|
|
23
|
+
*
|
|
24
|
+
* An option is a `MenuItemProps` object, so everything except the ComboBox
|
|
25
|
+
* specific `key` and `disabled` is spread onto the `MenuItem` unchanged.
|
|
26
|
+
* Consumers that pass further MenuItem props keep working without the ComboBox
|
|
27
|
+
* having to know about them; only `selected`, `tabIndex` and the keyboard
|
|
28
|
+
* handling are owned by the ComboBox and therefore not overridable.
|
|
29
|
+
*
|
|
30
|
+
* Styling hooks: every option carries its state as a data attribute
|
|
31
|
+
* (`data-selected`, `data-active`, `data-disabled`), so consumers can style
|
|
32
|
+
* options without knowing the hashed module class names. The selection state is
|
|
33
|
+
* left to `MenuItem` itself - the component does not add a `selected` class of
|
|
34
|
+
* its own, which would be impossible to override from the outside.
|
|
19
35
|
*
|
|
20
36
|
* @param props - The props for the ComboBoxOptionsItems component
|
|
21
|
-
* @returns A list of
|
|
37
|
+
* @returns A list of selectable options
|
|
22
38
|
*/
|
|
23
|
-
export declare function ComboBoxOptionsItems({
|
|
24
|
-
export {};
|
|
39
|
+
export declare function ComboBoxOptionsItems({ options, selectedValues, activeOptionId, leadingType, onOptionClick, }: ComboBoxOptionsItemsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import MenuItem from '@pixum/menu-item';
|
|
2
|
+
import MenuItem, { LeadingType } from '@pixum/menu-item';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
+
import { toMenuItemProps } from '../utils';
|
|
5
|
+
import styles from '../ComboBox.module.css';
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
+
* Renders the individual options.
|
|
8
|
+
*
|
|
9
|
+
* The options are deliberately not focusable: the focus stays in the input
|
|
10
|
+
* field and the highlight is driven by `aria-activedescendant`. Checkbox
|
|
11
|
+
* options are ordinary options with `aria-selected` - inside a listbox that is
|
|
12
|
+
* the state screen readers announce, and it keeps mouse and keyboard selection
|
|
13
|
+
* on exactly the same code path.
|
|
14
|
+
*
|
|
15
|
+
* An option is a `MenuItemProps` object, so everything except the ComboBox
|
|
16
|
+
* specific `key` and `disabled` is spread onto the `MenuItem` unchanged.
|
|
17
|
+
* Consumers that pass further MenuItem props keep working without the ComboBox
|
|
18
|
+
* having to know about them; only `selected`, `tabIndex` and the keyboard
|
|
19
|
+
* handling are owned by the ComboBox and therefore not overridable.
|
|
20
|
+
*
|
|
21
|
+
* Styling hooks: every option carries its state as a data attribute
|
|
22
|
+
* (`data-selected`, `data-active`, `data-disabled`), so consumers can style
|
|
23
|
+
* options without knowing the hashed module class names. The selection state is
|
|
24
|
+
* left to `MenuItem` itself - the component does not add a `selected` class of
|
|
25
|
+
* its own, which would be impossible to override from the outside.
|
|
7
26
|
*
|
|
8
27
|
* @param props - The props for the ComboBoxOptionsItems component
|
|
9
|
-
* @returns A list of
|
|
28
|
+
* @returns A list of selectable options
|
|
10
29
|
*/
|
|
11
|
-
export function ComboBoxOptionsItems({
|
|
12
|
-
|
|
30
|
+
export function ComboBoxOptionsItems({ options, selectedValues, activeOptionId, leadingType, onOptionClick, }) {
|
|
31
|
+
const isCheckbox = leadingType === LeadingType.CheckBox;
|
|
32
|
+
return (_jsx(_Fragment, { children: options.map(({ item, id, value, disabled }) => {
|
|
13
33
|
var _a;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
const isSelected = selectedValues.includes(value);
|
|
35
|
+
const isActive = id === activeOptionId;
|
|
36
|
+
const menuItemProps = toMenuItemProps(item);
|
|
37
|
+
return (_jsx("div", { id: id, className: clsx(styles.option, isCheckbox && styles.optionCheckbox, isActive && styles.optionActive), role: "option", "aria-selected": isSelected, "aria-disabled": disabled || undefined, "data-selected": isSelected, "data-active": isActive, "data-disabled": disabled || undefined, onMouseDown: event => {
|
|
38
|
+
// Keeps the focus in the input field ...
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
// ... and keeps the bottom sheet's drag handler out of it.
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
}, onPointerDown: event => event.stopPropagation(),
|
|
43
|
+
// No preventDefault on touchstart, scrolling in the sheet must work.
|
|
44
|
+
onTouchStart: event => event.stopPropagation(), onClickCapture: event => {
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
if (disabled)
|
|
47
|
+
return;
|
|
48
|
+
onOptionClick(value);
|
|
49
|
+
}, children: _jsx(MenuItem, Object.assign({}, menuItemProps, { tabIndex: -1, disableKeyboardNav: true,
|
|
50
|
+
// A leading type set on the ComboBox wins over the option's own
|
|
51
|
+
// one: it is what makes multi select look like a checkbox list.
|
|
52
|
+
leadingProps: leadingType
|
|
53
|
+
? Object.assign(Object.assign({}, menuItemProps.leadingProps), { name: value, type: leadingType }) : menuItemProps.leadingProps, selected: isSelected })) }, (_a = item.key) !== null && _a !== void 0 ? _a : `combobox-item-wrapper-${id}`));
|
|
22
54
|
}) }));
|
|
23
55
|
}
|
|
24
56
|
//# sourceMappingURL=ComboBoxOptionsItems.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBoxOptionsItems.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptionsItems.tsx"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComboBoxOptionsItems.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptionsItems.tsx"],"names":[],"mappings":";AAAA,OAAO,QAAQ,EAAE,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAgB3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,oBAAoB,CAAC,EACnC,OAAO,EACP,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,GACa;IAC1B,MAAM,UAAU,GAAG,WAAW,KAAK,WAAW,CAAC,QAAQ,CAAA;IAEvD,OAAO,CACL,4BACG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;;YAC7C,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YACjD,MAAM,QAAQ,GAAG,EAAE,KAAK,cAAc,CAAA;YACtC,MAAM,aAAa,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;YAE3C,OAAO,CACL,cAEE,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,IAAI,CACb,MAAM,CAAC,MAAM,EACb,UAAU,IAAI,MAAM,CAAC,cAAc,EACnC,QAAQ,IAAI,MAAM,CAAC,YAAY,CAChC,EACD,IAAI,EAAC,QAAQ,mBACE,UAAU,mBACV,QAAQ,IAAI,SAAS,mBACrB,UAAU,iBACZ,QAAQ,mBACN,QAAQ,IAAI,SAAS,EACpC,WAAW,EAAE,KAAK,CAAC,EAAE;oBACnB,yCAAyC;oBACzC,KAAK,CAAC,cAAc,EAAE,CAAA;oBACtB,2DAA2D;oBAC3D,KAAK,CAAC,eAAe,EAAE,CAAA;gBACzB,CAAC,EACD,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE;gBAC/C,qEAAqE;gBACrE,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE,EAC9C,cAAc,EAAE,KAAK,CAAC,EAAE;oBACtB,KAAK,CAAC,eAAe,EAAE,CAAA;oBAEvB,IAAI,QAAQ;wBAAE,OAAM;oBAEpB,aAAa,CAAC,KAAK,CAAC,CAAA;gBACtB,CAAC,YAED,KAAC,QAAQ,oBACH,aAAa,IACjB,QAAQ,EAAE,CAAC,CAAC,EACZ,kBAAkB;oBAClB,gEAAgE;oBAChE,gEAAgE;oBAChE,YAAY,EACV,WAAW;wBACT,CAAC,iCACM,aAAa,CAAC,YAAY,KAC7B,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,WAAW,IAErB,CAAC,CAAC,aAAa,CAAC,YAAY,EAEhC,QAAQ,EAAE,UAAU,IACpB,IA9CG,MAAA,IAAI,CAAC,GAAG,mCAAI,yBAAyB,EAAE,EAAE,CA+C1C,CACP,CAAA;QACH,CAAC,CAAC,GACD,CACJ,CAAA;AACH,CAAC"}
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/** The content to render inside the options slot */
|
|
1
|
+
import type { ElementType, HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export interface ComboBoxOptionsSlotProps extends HTMLAttributes<HTMLElement> {
|
|
3
|
+
/** The content to render inside the options slot. */
|
|
5
4
|
children: ReactNode;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tag?: 'div' | 'ul' | 'ol' | 'dl';
|
|
5
|
+
/** Element the slot renders as. */
|
|
6
|
+
tag?: Extract<ElementType, 'div' | 'ul' | 'ol' | 'dl'>;
|
|
9
7
|
}
|
|
10
8
|
/**
|
|
11
|
-
* Styled container for optionsSlot content.
|
|
9
|
+
* Styled container for `optionsSlot` content.
|
|
12
10
|
*
|
|
13
|
-
* Applies the standard ComboBox dropdown appearance
|
|
14
|
-
* border
|
|
15
|
-
*
|
|
11
|
+
* Applies the standard ComboBox dropdown appearance - background, border,
|
|
12
|
+
* border radius, box shadow and top margin - so consumers do not have to
|
|
13
|
+
* replicate it in every `optionsSlot` implementation. Every other prop
|
|
14
|
+
* (`role`, `aria-*`, ...) is forwarded, because the slot content owns its own
|
|
15
|
+
* accessibility semantics.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* A slot replaces the built-in options list and therefore also its keyboard
|
|
18
|
+
* navigation: content rendered here has to bring its own key handling.
|
|
18
19
|
*
|
|
19
20
|
* ```tsx
|
|
20
21
|
* import ComboBox, { ComboBoxOptionsSlot } from '@pixum/combobox'
|
|
21
22
|
*
|
|
22
23
|
* <ComboBox
|
|
23
24
|
* optionsSlot={
|
|
24
|
-
* <ComboBoxOptionsSlot>
|
|
25
|
+
* <ComboBoxOptionsSlot role="listbox" aria-label="Pickup points">
|
|
25
26
|
* <MyCustomOptionsList />
|
|
26
27
|
* </ComboBoxOptionsSlot>
|
|
27
28
|
* }
|
|
28
29
|
* />
|
|
29
30
|
* ```
|
|
30
31
|
*
|
|
31
|
-
* @param
|
|
32
|
-
* @returns A styled wrapper
|
|
32
|
+
* @param props - The props for the ComboBoxOptionsSlot component
|
|
33
|
+
* @returns A styled wrapper matching the ComboBox dropdown look
|
|
33
34
|
*/
|
|
34
|
-
export declare function ComboBoxOptionsSlot({ children, className,
|
|
35
|
+
export declare function ComboBoxOptionsSlot({ children, className, tag, ...rest }: ComboBoxOptionsSlotProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,32 +1,47 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import '../styles.css';
|
|
3
13
|
import Menu from '@pixum/menu';
|
|
4
14
|
import clsx from 'clsx';
|
|
15
|
+
import styles from '../ComboBox.module.css';
|
|
5
16
|
/**
|
|
6
|
-
* Styled container for optionsSlot content.
|
|
17
|
+
* Styled container for `optionsSlot` content.
|
|
7
18
|
*
|
|
8
|
-
* Applies the standard ComboBox dropdown appearance
|
|
9
|
-
* border
|
|
10
|
-
*
|
|
19
|
+
* Applies the standard ComboBox dropdown appearance - background, border,
|
|
20
|
+
* border radius, box shadow and top margin - so consumers do not have to
|
|
21
|
+
* replicate it in every `optionsSlot` implementation. Every other prop
|
|
22
|
+
* (`role`, `aria-*`, ...) is forwarded, because the slot content owns its own
|
|
23
|
+
* accessibility semantics.
|
|
11
24
|
*
|
|
12
|
-
*
|
|
25
|
+
* A slot replaces the built-in options list and therefore also its keyboard
|
|
26
|
+
* navigation: content rendered here has to bring its own key handling.
|
|
13
27
|
*
|
|
14
28
|
* ```tsx
|
|
15
29
|
* import ComboBox, { ComboBoxOptionsSlot } from '@pixum/combobox'
|
|
16
30
|
*
|
|
17
31
|
* <ComboBox
|
|
18
32
|
* optionsSlot={
|
|
19
|
-
* <ComboBoxOptionsSlot>
|
|
33
|
+
* <ComboBoxOptionsSlot role="listbox" aria-label="Pickup points">
|
|
20
34
|
* <MyCustomOptionsList />
|
|
21
35
|
* </ComboBoxOptionsSlot>
|
|
22
36
|
* }
|
|
23
37
|
* />
|
|
24
38
|
* ```
|
|
25
39
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @returns A styled wrapper
|
|
40
|
+
* @param props - The props for the ComboBoxOptionsSlot component
|
|
41
|
+
* @returns A styled wrapper matching the ComboBox dropdown look
|
|
28
42
|
*/
|
|
29
|
-
export function ComboBoxOptionsSlot(
|
|
30
|
-
|
|
43
|
+
export function ComboBoxOptionsSlot(_a) {
|
|
44
|
+
var { children, className, tag = 'ul' } = _a, rest = __rest(_a, ["children", "className", "tag"]);
|
|
45
|
+
return (_jsx(Menu, Object.assign({ tag: tag, className: clsx(styles.optionsSlot, className) }, rest, { children: children })));
|
|
31
46
|
}
|
|
32
47
|
//# sourceMappingURL=ComboBoxOptionsSlot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBoxOptionsSlot.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptionsSlot.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ComboBoxOptionsSlot.js","sourceRoot":"","sources":["../../src/partials/ComboBoxOptionsSlot.tsx"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,IAAI,MAAM,aAAa,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAU3C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAKT;QALS,EAClC,QAAQ,EACR,SAAS,EACT,GAAG,GAAG,IAAI,OAEe,EADtB,IAAI,cAJ2B,gCAKnC,CADQ;IAEP,OAAO,CACL,KAAC,IAAI,kBAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,IAAM,IAAI,cACrE,QAAQ,IACJ,CACR,CAAA;AACH,CAAC"}
|
package/lib/partials/index.d.ts
CHANGED
package/lib/partials/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './ComboBoxOptions';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './ComboBoxOptionsGroup';
|
|
3
3
|
export * from './ComboBoxOptionsItems';
|
|
4
4
|
export * from './ComboBoxOptionsSlot';
|
|
5
|
+
export * from './ComboBoxNoResults';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/partials/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/partials/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,78 +1,216 @@
|
|
|
1
|
-
import { LeadingType, MenuItemProps } from '@pixum/menu-item';
|
|
2
|
-
import { ThemeType } from '@pixum/theme-provider';
|
|
3
|
-
import { InputModesType } from '@pixum/web-input';
|
|
1
|
+
import type { LeadingType, MenuItemProps } from '@pixum/menu-item';
|
|
2
|
+
import type { ThemeType } from '@pixum/theme-provider';
|
|
3
|
+
import type { InputModesType } from '@pixum/web-input';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* An option as handed in by the consumer.
|
|
6
|
+
*
|
|
7
|
+
* Everything a `MenuItem` understands is accepted and forwarded unchanged -
|
|
8
|
+
* the ComboBox only adds `key` and `disabled` on top. That keeps existing
|
|
9
|
+
* consumers working: they pass their MenuItem props as they always did, and
|
|
10
|
+
* props the ComboBox does not know about still reach the `MenuItem`.
|
|
11
|
+
*/
|
|
12
|
+
export interface ComboBoxOptionItemProps extends MenuItemProps {
|
|
13
|
+
/** Unique key for the option item */
|
|
14
|
+
key?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Disabled options are rendered, but skipped by mouse and keyboard.
|
|
17
|
+
*
|
|
18
|
+
* Newly added. Consumer types that already carry a `disabled` field of a
|
|
19
|
+
* different type (e.g. `disabled: 'true' | 'false'`) are no longer
|
|
20
|
+
* assignable - widen it to `boolean` on the consumer side.
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Options are accepted either as a flat list or grouped by a group headline. */
|
|
25
|
+
export type ComboBoxOptionsInput = ComboBoxOptionItemProps[] | Record<string, ComboBoxOptionItemProps[]>;
|
|
26
|
+
/**
|
|
27
|
+
* An option after normalisation. Flat and grouped options are reduced to this
|
|
28
|
+
* shape once, so keyboard navigation, rendering and ARIA ids all work on the
|
|
29
|
+
* very same list in the very same order.
|
|
30
|
+
*/
|
|
31
|
+
export interface ComboBoxOption {
|
|
32
|
+
/** The original option as handed in by the consumer. */
|
|
33
|
+
item: ComboBoxOptionItemProps;
|
|
34
|
+
/**
|
|
35
|
+
* Stable value of the option, reported by `onOptionItemClick` and compared
|
|
36
|
+
* against `value`. Resolved by `resolveOptionValue`: the option's `text` when
|
|
37
|
+
* it is a string, otherwise `key`, otherwise the render index.
|
|
38
|
+
*/
|
|
39
|
+
value: string;
|
|
40
|
+
/** Position in render order. Drives the DOM id and the keyboard navigation. */
|
|
41
|
+
index: number;
|
|
42
|
+
/** DOM id, referenced by `aria-activedescendant`. */
|
|
43
|
+
id: string;
|
|
44
|
+
/** Group headline the option belongs to, `undefined` for flat lists. */
|
|
45
|
+
group?: string;
|
|
46
|
+
/** Whether the option can be activated. */
|
|
47
|
+
disabled: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Options of one render group, produced by `groupOptions`. */
|
|
50
|
+
export interface ComboBoxOptionGroup {
|
|
51
|
+
/** Group headline, `undefined` for flat lists. */
|
|
52
|
+
group?: string;
|
|
53
|
+
/** Options of this group, still carrying their global render index. */
|
|
54
|
+
options: ComboBoxOption[];
|
|
55
|
+
}
|
|
56
|
+
/** ARIA props for the element that owns the `combobox` role. */
|
|
57
|
+
export interface ComboBoxAriaProps {
|
|
58
|
+
role: 'combobox';
|
|
59
|
+
'aria-expanded': boolean;
|
|
60
|
+
'aria-haspopup': 'listbox';
|
|
61
|
+
'aria-controls': string | undefined;
|
|
62
|
+
'aria-activedescendant': string | undefined;
|
|
63
|
+
'aria-autocomplete': 'list' | 'none';
|
|
64
|
+
}
|
|
65
|
+
/** ARIA props for the element that owns the `listbox` role. */
|
|
66
|
+
export interface ListboxAriaProps {
|
|
67
|
+
role: 'listbox';
|
|
68
|
+
id: string;
|
|
69
|
+
/** Only set for multi select; single select listboxes omit it. */
|
|
70
|
+
'aria-multiselectable'?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Public options contract, kept for backwards compatibility.
|
|
74
|
+
*
|
|
75
|
+
* In the previous version this interface was the base of `ComboBoxProps` and
|
|
76
|
+
* the prop type of
|
|
77
|
+
* the exported options component. It describes the options as the *consumer*
|
|
78
|
+
* hands them in - not the normalised list the internal panel renders. The
|
|
79
|
+
* internal shape now lives in `ComboBoxOptionsPanelProps`.
|
|
80
|
+
*
|
|
81
|
+
* @deprecated Use `ComboBoxProps` (or `Pick<ComboBoxProps, 'options'>`)
|
|
82
|
+
* directly. Kept so existing imports do not silently change meaning; will be
|
|
83
|
+
* removed in the next major.
|
|
6
84
|
*/
|
|
7
85
|
export interface ComboBoxOptionsProps {
|
|
8
|
-
/** Options to display
|
|
9
|
-
options:
|
|
10
|
-
/**
|
|
86
|
+
/** Options to display, either flat or grouped. */
|
|
87
|
+
options: ComboBoxOptionsInput;
|
|
88
|
+
/**
|
|
89
|
+
* Currently selected option value.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Use `value`. When both are set, `value` wins.
|
|
92
|
+
*/
|
|
11
93
|
selectedOption?: string;
|
|
12
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Callback fired when an option is clicked.
|
|
96
|
+
*
|
|
97
|
+
* @deprecated Use `onOptionItemClick`. On `ComboBoxProps` this prop is
|
|
98
|
+
* narrowed to the trigger click handler `() => void`.
|
|
99
|
+
*/
|
|
13
100
|
onClick?: (value: string) => void;
|
|
14
|
-
/** Type of leading element to display (icon, avatar,
|
|
101
|
+
/** Type of leading element to display (icon, avatar, checkbox …). */
|
|
102
|
+
leadingType?: LeadingType;
|
|
103
|
+
/** Additional details rendered below the options. */
|
|
104
|
+
optionDetails?: React.ReactNode;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Props of the rendered options panel - the internal, normalised shape.
|
|
108
|
+
*
|
|
109
|
+
* This is what `ComboBoxOptions` consumes. It is exported so custom panels can
|
|
110
|
+
* be typed against it, but it is not part of the consumer-facing API and may
|
|
111
|
+
* change without a major bump.
|
|
112
|
+
*/
|
|
113
|
+
export interface ComboBoxOptionsPanelProps {
|
|
114
|
+
/** Normalised options in render order. */
|
|
115
|
+
options: ComboBoxOption[];
|
|
116
|
+
/** ARIA props of the listbox element. */
|
|
117
|
+
listboxAriaProps: ListboxAriaProps;
|
|
118
|
+
/** Values that are currently selected. */
|
|
119
|
+
selectedValues: string[];
|
|
120
|
+
/** DOM id of the active option (`aria-activedescendant`). */
|
|
121
|
+
activeOptionId?: string;
|
|
122
|
+
/** Type of the leading element, e.g. a checkbox for multi select. */
|
|
15
123
|
leadingType?: LeadingType;
|
|
16
|
-
/** Additional details
|
|
124
|
+
/** Additional details rendered as a sticky footer below the options. */
|
|
17
125
|
optionDetails?: React.ReactNode;
|
|
126
|
+
/** Called with the value of the clicked option. */
|
|
127
|
+
onOptionClick: (value: string) => void;
|
|
18
128
|
}
|
|
19
129
|
/**
|
|
20
|
-
* Props
|
|
130
|
+
* Props of the ComboBox component.
|
|
131
|
+
*
|
|
132
|
+
* Extends the deprecated `ComboBoxOptionsProps` so that consumers who built
|
|
133
|
+
* their own prop types on top of it keep compiling.
|
|
21
134
|
*/
|
|
22
135
|
export interface ComboBoxProps extends ComboBoxOptionsProps {
|
|
23
|
-
/** Additional CSS class name for the
|
|
136
|
+
/** Additional CSS class name for the trigger field. */
|
|
24
137
|
className?: string;
|
|
25
|
-
/** Name attribute for the input field */
|
|
138
|
+
/** Name attribute for the input field. */
|
|
26
139
|
name?: string;
|
|
27
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* ID attribute for the input field.
|
|
142
|
+
*
|
|
143
|
+
* @deprecated The trigger generates its own ids for the ARIA wiring; `id` is
|
|
144
|
+
* forwarded to the underlying input untouched and no longer used internally.
|
|
145
|
+
*/
|
|
146
|
+
id?: string;
|
|
147
|
+
/** Headline text displayed in the mobile bottom sheet. */
|
|
28
148
|
headline?: string;
|
|
29
|
-
/** Helper text displayed below the input */
|
|
149
|
+
/** Helper text displayed below the input field. */
|
|
30
150
|
helperText?: string;
|
|
31
|
-
/**
|
|
32
|
-
id?: string;
|
|
33
|
-
/** Label text for the input field */
|
|
151
|
+
/** Label text for the input field. */
|
|
34
152
|
label?: string;
|
|
35
|
-
/**
|
|
153
|
+
/** Options to display, either flat or grouped. */
|
|
154
|
+
options: ComboBoxOptionsInput;
|
|
155
|
+
/** Whether the popover / bottom sheet is currently open. */
|
|
36
156
|
isOpen: boolean;
|
|
37
|
-
/** State setter
|
|
157
|
+
/** State setter that controls the open state. */
|
|
38
158
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Selected value: a string for single select, an array of strings when
|
|
161
|
+
* `multiple` is set.
|
|
162
|
+
*
|
|
163
|
+
* The array member is new in this version. Code that *reads* this prop back
|
|
164
|
+
* out of
|
|
165
|
+
* a props object has to narrow it (`Array.isArray(value)`).
|
|
166
|
+
*/
|
|
167
|
+
value?: string | string[];
|
|
168
|
+
/** Allows selecting several options; combine with a checkbox `leadingType`. */
|
|
169
|
+
multiple?: boolean;
|
|
170
|
+
/** Called with the value of the selected (in multi select: toggled) option. */
|
|
42
171
|
onOptionItemClick?: (value: string) => void;
|
|
43
|
-
/**
|
|
172
|
+
/** Called when the search input value changes. */
|
|
173
|
+
onChange?: (value: string) => void;
|
|
174
|
+
/** Called when the user clicks outside of the component. */
|
|
44
175
|
onOutsideClick?: () => void;
|
|
45
|
-
/**
|
|
176
|
+
/** Called when the trigger field is clicked. */
|
|
46
177
|
onClick?: () => void;
|
|
47
|
-
/**
|
|
178
|
+
/** Called when the bottom sheet has been closed. */
|
|
48
179
|
onSheetClose?: () => void;
|
|
49
|
-
/** Placeholder text for the input field */
|
|
180
|
+
/** Placeholder text for the input field. */
|
|
50
181
|
placeholder?: string;
|
|
51
|
-
/** Search pattern
|
|
182
|
+
/** Search pattern for input validation. */
|
|
52
183
|
searchPattern?: string;
|
|
53
|
-
/**
|
|
54
|
-
value?: string;
|
|
55
|
-
/** Text to display when no results are found */
|
|
184
|
+
/** Text to display when there is no option to show. */
|
|
56
185
|
noResultsText?: string;
|
|
57
|
-
/** Input mode for mobile keyboards
|
|
186
|
+
/** Input mode for mobile keyboards. */
|
|
58
187
|
inputMode?: InputModesType;
|
|
59
|
-
/**
|
|
188
|
+
/** Renders a search input inside the popover / bottom sheet. */
|
|
60
189
|
withSearch?: boolean;
|
|
61
|
-
/**
|
|
190
|
+
/** Enter opens the closed list. Disable it inside forms with implicit submit. */
|
|
191
|
+
openOnEnter?: boolean;
|
|
192
|
+
/** Whether the combobox is disabled. */
|
|
62
193
|
disabled?: boolean;
|
|
63
|
-
/**
|
|
194
|
+
/** Disabled style plus shimmer animation while content is loading. */
|
|
64
195
|
loading?: boolean;
|
|
65
|
-
/**
|
|
196
|
+
/** Type of the leading element of an option (icon, avatar, checkbox …). */
|
|
197
|
+
leadingType?: LeadingType;
|
|
198
|
+
/** Additional details rendered below the options. */
|
|
199
|
+
optionDetails?: React.ReactNode;
|
|
200
|
+
/** Theme configuration for the component. */
|
|
66
201
|
theme?: ThemeType;
|
|
67
|
-
/** Custom slot that replaces the standard options/no-results block */
|
|
202
|
+
/** Custom slot that replaces the standard options / no-results block. */
|
|
68
203
|
optionsSlot?: React.ReactNode;
|
|
69
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Icon element displayed at the leading side of the trigger input.
|
|
206
|
+
*
|
|
207
|
+
* Deliberately `ReactNode`, not `ReactElement`: fragments, strings and
|
|
208
|
+
* conditional `false` have always been accepted here.
|
|
209
|
+
*/
|
|
70
210
|
leadingIcon?: React.ReactNode;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/** Unique key for the option item */
|
|
77
|
-
key?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Formats the selected values for the trigger field.
|
|
213
|
+
* Defaults to the labels of the selected options joined by a comma.
|
|
214
|
+
*/
|
|
215
|
+
renderValue?: (labels: string[]) => string;
|
|
78
216
|
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './scrollOptionToViewport';
|
|
1
|
+
export * from './options';
|
package/lib/utils/index.js
CHANGED
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|