@hebium-ui/react 0.1.0-alpha.2 → 0.1.0-alpha.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/components/alert/alert.d.ts +3 -6
- package/dist/components/alert/alert.js +6 -14
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/anchor/anchor.d.ts +1 -4
- package/dist/components/anchor/anchor.js +4 -5
- package/dist/components/anchor/anchor.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +1 -4
- package/dist/components/avatar/avatar.js +4 -5
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/blockquote/blockquote.d.ts +1 -4
- package/dist/components/blockquote/blockquote.js +4 -5
- package/dist/components/blockquote/blockquote.js.map +1 -1
- package/dist/components/button/button.d.ts +12 -4
- package/dist/components/button/button.js +30 -11
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/checkbox/checkbox.d.ts +2 -5
- package/dist/components/checkbox/checkbox.js +29 -16
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/code/code.d.ts +1 -4
- package/dist/components/code/code.js +4 -5
- package/dist/components/code/code.js.map +1 -1
- package/dist/components/combobox/combobox-option.js +33 -0
- package/dist/components/combobox/combobox-option.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +61 -0
- package/dist/components/combobox/combobox.js +208 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/combobox/index.d.ts +2 -0
- package/dist/components/combobox/use-combobox-form.js +33 -0
- package/dist/components/combobox/use-combobox-form.js.map +1 -0
- package/dist/components/combobox/use-combobox-popover.js +66 -0
- package/dist/components/combobox/use-combobox-popover.js.map +1 -0
- package/dist/components/combobox/use-combobox-state.js +96 -0
- package/dist/components/combobox/use-combobox-state.js.map +1 -0
- package/dist/components/details/details.d.ts +1 -4
- package/dist/components/details/details.js +4 -5
- package/dist/components/details/details.js.map +1 -1
- package/dist/components/dialog/dialog.context.js +1 -2
- package/dist/components/dialog/dialog.d.ts +4 -7
- package/dist/components/dialog/dialog.js +29 -9
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/dialog/index.d.ts +1 -2
- package/dist/components/dl/dl.d.ts +1 -4
- package/dist/components/dl/dl.js +10 -11
- package/dist/components/dl/dl.js.map +1 -1
- package/dist/components/drawer/drawer.context.js +1 -2
- package/dist/components/drawer/drawer.d.ts +4 -7
- package/dist/components/drawer/drawer.js +29 -9
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/drawer/index.d.ts +1 -2
- package/dist/components/fieldset/fieldset.d.ts +1 -4
- package/dist/components/fieldset/fieldset.js +4 -5
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/heading/heading.d.ts +1 -4
- package/dist/components/heading/heading.js +4 -5
- package/dist/components/heading/heading.js.map +1 -1
- package/dist/components/hr/hr.d.ts +1 -4
- package/dist/components/hr/hr.js +4 -5
- package/dist/components/hr/hr.js.map +1 -1
- package/dist/components/index.d.ts +35 -26
- package/dist/components/inline-feedback/index.d.ts +2 -0
- package/dist/components/inline-feedback/inline-feedback.d.ts +33 -0
- package/dist/components/inline-feedback/inline-feedback.js +30 -0
- package/dist/components/inline-feedback/inline-feedback.js.map +1 -0
- package/dist/components/input/input.d.ts +1 -4
- package/dist/components/input/input.js +4 -5
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/label/label.d.ts +1 -4
- package/dist/components/label/label.js +6 -7
- package/dist/components/label/label.js.map +1 -1
- package/dist/components/menu/index.d.ts +1 -2
- package/dist/components/menu/menu.context.js +1 -2
- package/dist/components/menu/menu.d.ts +3 -6
- package/dist/components/menu/menu.js +23 -9
- package/dist/components/menu/menu.js.map +1 -1
- package/dist/components/multi-combobox/index.d.ts +2 -0
- package/dist/components/multi-combobox/multi-combobox-option.js +42 -0
- package/dist/components/multi-combobox/multi-combobox-option.js.map +1 -0
- package/dist/components/multi-combobox/multi-combobox-tag.js +54 -0
- package/dist/components/multi-combobox/multi-combobox-tag.js.map +1 -0
- package/dist/components/multi-combobox/multi-combobox.d.ts +72 -0
- package/dist/components/multi-combobox/multi-combobox.js +249 -0
- package/dist/components/multi-combobox/multi-combobox.js.map +1 -0
- package/dist/components/multi-combobox/use-multi-combobox-state.js +91 -0
- package/dist/components/multi-combobox/use-multi-combobox-state.js.map +1 -0
- package/dist/components/paragraph/paragraph.d.ts +1 -4
- package/dist/components/paragraph/paragraph.js +4 -5
- package/dist/components/paragraph/paragraph.js.map +1 -1
- package/dist/components/popover/index.d.ts +1 -2
- package/dist/components/popover/popover.context.js +1 -2
- package/dist/components/popover/popover.d.ts +3 -6
- package/dist/components/popover/popover.js +20 -6
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/progress/progress.d.ts +1 -4
- package/dist/components/progress/progress.js +4 -5
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.d.ts +1 -4
- package/dist/components/radio/radio.js +4 -5
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radiogroup/radiogroup.d.ts +1 -4
- package/dist/components/radiogroup/radiogroup.js +6 -6
- package/dist/components/radiogroup/radiogroup.js.map +1 -1
- package/dist/components/section/section.d.ts +1 -4
- package/dist/components/section/section.js +4 -5
- package/dist/components/section/section.js.map +1 -1
- package/dist/components/segmented-control/segmented-control.context.js +1 -2
- package/dist/components/segmented-control/segmented-control.d.ts +2 -5
- package/dist/components/segmented-control/segmented-control.js +13 -9
- package/dist/components/segmented-control/segmented-control.js.map +1 -1
- package/dist/components/select/select.d.ts +1 -4
- package/dist/components/select/select.js +4 -5
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/skip-link/index.d.ts +2 -0
- package/dist/components/skip-link/skip-link.d.ts +6 -0
- package/dist/components/skip-link/skip-link.js +20 -0
- package/dist/components/skip-link/skip-link.js.map +1 -0
- package/dist/components/status-icon/index.d.ts +2 -0
- package/dist/components/status-icon/status-icon.d.ts +19 -0
- package/dist/components/status-icon/status-icon.js +22 -0
- package/dist/components/status-icon/status-icon.js.map +1 -0
- package/dist/components/table/table.d.ts +4 -7
- package/dist/components/table/table.js +25 -26
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.context.d.ts +1 -4
- package/dist/components/tabs/tabs.context.js +1 -2
- package/dist/components/tabs/tabs.d.ts +2 -5
- package/dist/components/tabs/tabs.js +13 -14
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tag/index.d.ts +2 -0
- package/dist/components/tag/tag.d.ts +39 -0
- package/dist/components/tag/tag.js +41 -0
- package/dist/components/tag/tag.js.map +1 -0
- package/dist/components/text/index.d.ts +2 -0
- package/dist/components/text/text.d.ts +22 -0
- package/dist/components/text/text.js +23 -0
- package/dist/components/text/text.js.map +1 -0
- package/dist/components/textarea/textarea.d.ts +1 -4
- package/dist/components/textarea/textarea.js +4 -5
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/tooltip/index.d.ts +1 -2
- package/dist/components/tooltip/tooltip.context.js +1 -2
- package/dist/components/tooltip/tooltip.d.ts +3 -6
- package/dist/components/tooltip/tooltip.js +19 -5
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/visually-hidden/visually-hidden.d.ts +3 -6
- package/dist/components/visually-hidden/visually-hidden.js +4 -5
- package/dist/components/visually-hidden/visually-hidden.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +9 -7
- package/dist/provider/hui-provider.context.d.ts +34 -10
- package/dist/provider/hui-provider.context.js +23 -16
- package/dist/provider/hui-provider.context.js.map +1 -1
- package/dist/provider/hui-provider.d.ts +1 -4
- package/dist/provider/hui-provider.js +1 -2
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/merge-props.js +1 -2
- package/dist/types/distributive.d.ts +1 -0
- package/dist/types/hui-component.d.ts +11 -7
- package/dist/types/index.d.ts +3 -2
- package/dist/types/polymorphic.d.ts +4 -11
- package/dist/utils/attributes/normalize-attributes.js +1 -2
- package/package.json +9 -9
- package/dist/components/dialog/dialog.context.d.ts +0 -4
- package/dist/components/drawer/drawer.context.d.ts +0 -4
- package/dist/components/menu/menu.context.d.ts +0 -4
- package/dist/components/popover/popover.context.d.ts +0 -4
- package/dist/components/tooltip/tooltip.context.d.ts +0 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Tag } from "../tag/tag.js";
|
|
2
|
+
import { multiComboboxControl } from "@hebium-ui/core";
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/multi-combobox/multi-combobox-tag.tsx
|
|
6
|
+
const EMPTY_BUTTON_PROPS = {};
|
|
7
|
+
function MultiComboboxTag({ value, label, option, tagProps, disabled, remove }) {
|
|
8
|
+
const props = tagProps?.({
|
|
9
|
+
value,
|
|
10
|
+
label,
|
|
11
|
+
option
|
|
12
|
+
}) ?? {};
|
|
13
|
+
const buttonProps = props.removeButtonProps ?? EMPTY_BUTTON_PROPS;
|
|
14
|
+
const onClick = buttonProps.onClick;
|
|
15
|
+
const handleClick = useCallback((event) => {
|
|
16
|
+
onClick?.(event);
|
|
17
|
+
if (!event.defaultPrevented) remove(value, event.currentTarget);
|
|
18
|
+
}, [
|
|
19
|
+
onClick,
|
|
20
|
+
remove,
|
|
21
|
+
value
|
|
22
|
+
]);
|
|
23
|
+
const onKeyDown = buttonProps.onKeyDown;
|
|
24
|
+
const handleKeyDown = useCallback((event) => {
|
|
25
|
+
onKeyDown?.(event);
|
|
26
|
+
if (event.defaultPrevented) return;
|
|
27
|
+
if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;
|
|
28
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
29
|
+
if (event.key !== "Backspace" || event.repeat) return;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
event.currentTarget.click();
|
|
32
|
+
}, [onKeyDown]);
|
|
33
|
+
const resolvedButtonProps = useMemo(() => ({
|
|
34
|
+
...buttonProps,
|
|
35
|
+
...multiComboboxControl.getTagRemoveButtonAttributes(value),
|
|
36
|
+
disabled: disabled || buttonProps.disabled,
|
|
37
|
+
onClick: handleClick,
|
|
38
|
+
onKeyDown: handleKeyDown
|
|
39
|
+
}), [
|
|
40
|
+
buttonProps,
|
|
41
|
+
value,
|
|
42
|
+
disabled,
|
|
43
|
+
handleClick,
|
|
44
|
+
handleKeyDown
|
|
45
|
+
]);
|
|
46
|
+
return /* @__PURE__ */ jsx(Tag, {
|
|
47
|
+
...props,
|
|
48
|
+
label,
|
|
49
|
+
removeButtonProps: resolvedButtonProps
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { MultiComboboxTag };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=multi-combobox-tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-combobox-tag.js","names":[],"sources":["../../../src/components/multi-combobox/multi-combobox-tag.tsx"],"sourcesContent":["import { type ComboboxSelectOption, multiComboboxControl } from \"@hebium-ui/core\";\nimport { type KeyboardEvent, type MouseEvent, type ReactElement, useCallback, useMemo } from \"react\";\nimport { Tag } from \"../tag\";\nimport { type MultiComboboxTagContext, type MultiComboboxTagProps } from \"./multi-combobox\";\n\nconst EMPTY_BUTTON_PROPS: NonNullable<MultiComboboxTagProps[\"removeButtonProps\"]> = {};\n\ninterface MultiComboboxTagOwnProps<O extends ComboboxSelectOption> {\n value: string;\n label: string;\n option: O | undefined;\n tagProps: ((context: MultiComboboxTagContext<O>) => MultiComboboxTagProps) | undefined;\n disabled: boolean;\n remove: (value: string, button: HTMLButtonElement) => void;\n}\n\nexport function MultiComboboxTag<O extends ComboboxSelectOption>({\n value,\n label,\n option,\n tagProps,\n disabled,\n remove,\n}: MultiComboboxTagOwnProps<O>): ReactElement {\n const props = tagProps?.({ value, label, option }) ?? {};\n const buttonProps = props.removeButtonProps ?? EMPTY_BUTTON_PROPS;\n\n const onClick = buttonProps.onClick;\n const handleClick = useCallback((event: MouseEvent<HTMLButtonElement>): void => {\n onClick?.(event);\n if (!event.defaultPrevented) remove(value, event.currentTarget);\n }, [onClick, remove, value]);\n\n const onKeyDown = buttonProps.onKeyDown;\n const handleKeyDown = useCallback((event: KeyboardEvent<HTMLButtonElement>): void => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return;\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;\n if (event.key !== \"Backspace\" || event.repeat) return;\n event.preventDefault();\n event.currentTarget.click();\n }, [onKeyDown]);\n\n const resolvedButtonProps = useMemo(() => ({\n ...buttonProps,\n ...multiComboboxControl.getTagRemoveButtonAttributes(value),\n disabled: disabled || buttonProps.disabled,\n onClick: handleClick,\n onKeyDown: handleKeyDown,\n }), [\n buttonProps,\n value,\n disabled,\n handleClick,\n handleKeyDown,\n ]);\n\n return (\n <Tag\n {...props}\n label={label}\n removeButtonProps={resolvedButtonProps}\n />\n );\n}\n"],"mappings":";;;;;AAKA,MAAM,qBAA8E,CAAC;AAWrF,SAAgB,iBAAiD,EAC/D,OACA,OACA,QACA,UACA,UACA,UAC4C;CAC5C,MAAM,QAAQ,WAAW;EAAE;EAAO;EAAO;CAAO,CAAC,KAAK,CAAC;CACvD,MAAM,cAAc,MAAM,qBAAqB;CAE/C,MAAM,UAAU,YAAY;CAC5B,MAAM,cAAc,aAAa,UAA+C;EAC9E,UAAU,KAAK;EACf,IAAI,CAAC,MAAM,kBAAkB,OAAO,OAAO,MAAM,aAAa;CAChE,GAAG;EAAC;EAAS;EAAQ;CAAK,CAAC;CAE3B,MAAM,YAAY,YAAY;CAC9B,MAAM,gBAAgB,aAAa,UAAkD;EACnF,YAAY,KAAK;EACjB,IAAI,MAAM,kBAAkB;EAC5B,IAAI,MAAM,YAAY,eAAe,MAAM,YAAY,YAAY,KAAK;EACxE,IAAI,MAAM,UAAU,MAAM,WAAW,MAAM,WAAW,MAAM,UAAU;EACtE,IAAI,MAAM,QAAQ,eAAe,MAAM,QAAQ;EAC/C,MAAM,eAAe;EACrB,MAAM,cAAc,MAAM;CAC5B,GAAG,CAAC,SAAS,CAAC;CAEd,MAAM,sBAAsB,eAAe;EACzC,GAAG;EACH,GAAG,qBAAqB,6BAA6B,KAAK;EAC1D,UAAU,YAAY,YAAY;EAClC,SAAS;EACT,WAAW;CACb,IAAI;EACF;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,OACE,oBAAC,KAAD;EACE,GAAI;EACG;EACP,mBAAmB;CACpB,CAAA;AAEL"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { LabelProps } from "../label/label.js";
|
|
4
|
+
import "../label/index.js";
|
|
5
|
+
import { TagProps } from "../tag/tag.js";
|
|
6
|
+
import "../tag/index.js";
|
|
7
|
+
import { ComboboxSelectOption as ComboboxSelectOption$1, ComboboxTextOption as ComboboxTextOption$1, MultiComboboxFormValueProps, MultiComboboxFormValueProps as MultiComboboxFormValueProps$1, MultiComboboxItemState, MultiComboboxItemState as MultiComboboxItemState$1, MultiComboboxSlots, MultiComboboxVariants } from "@hebium-ui/core";
|
|
8
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
9
|
+
export interface MultiComboboxTagContext<O extends ComboboxSelectOption$1 = ComboboxSelectOption$1> {
|
|
10
|
+
value: string;
|
|
11
|
+
/** Standard display text. In text mode this is the committed value itself. */
|
|
12
|
+
label: string;
|
|
13
|
+
/** The matching candidate, if one exists. */
|
|
14
|
+
option: O | undefined;
|
|
15
|
+
}
|
|
16
|
+
export type MultiComboboxTagProps = Omit<TagProps, "label" | "onRemove">;
|
|
17
|
+
interface MultiComboboxOwnProps<O extends ComboboxSelectOption$1> {
|
|
18
|
+
/** Available options. Values must be unique. */
|
|
19
|
+
options: readonly O[];
|
|
20
|
+
/** The controlled values. Values must be unique. */
|
|
21
|
+
value?: readonly string[] | undefined;
|
|
22
|
+
/** The initial uncontrolled values. @default [] */
|
|
23
|
+
defaultValue?: readonly string[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Called with the next values. In controlled mode, call the optional focus callback when accepting a Tag removal.
|
|
26
|
+
*/
|
|
27
|
+
onChange?: ((value: string[], moveFocus?: () => void) => void) | undefined;
|
|
28
|
+
/** The input's semantic color. @default "accent" */
|
|
29
|
+
color?: MultiComboboxVariants["color"] | undefined;
|
|
30
|
+
/** The label displayed above the input. */
|
|
31
|
+
label?: ReactNode | undefined;
|
|
32
|
+
/** Additional props passed to the label. */
|
|
33
|
+
labelProps?: LabelProps | undefined;
|
|
34
|
+
/** Help text displayed below the label. */
|
|
35
|
+
description?: ReactNode | undefined;
|
|
36
|
+
/** Inline validation feedback. */
|
|
37
|
+
error?: ReactNode | undefined;
|
|
38
|
+
/** The name used for form submission. */
|
|
39
|
+
name?: string | undefined;
|
|
40
|
+
/** The id of the associated form. */
|
|
41
|
+
form?: string | undefined;
|
|
42
|
+
/** Prevents interaction and excludes values from form submission. */
|
|
43
|
+
disabled?: boolean | undefined;
|
|
44
|
+
/** Prevents editing and opening the list. Values are still submitted. */
|
|
45
|
+
readOnly?: boolean | undefined;
|
|
46
|
+
/** Requires at least one selected value. */
|
|
47
|
+
required?: boolean | undefined;
|
|
48
|
+
/** Native validation message. @default "Please fill out this field." */
|
|
49
|
+
requiredMessage?: string | undefined;
|
|
50
|
+
/** Props passed to the input element. */
|
|
51
|
+
inputProps?: Omit<ComponentProps<"input">, "children"> | undefined;
|
|
52
|
+
/** Props passed to the listbox element. */
|
|
53
|
+
listProps?: Omit<ComponentProps<"div">, "children"> | undefined;
|
|
54
|
+
/** Props for each option wrapper. */
|
|
55
|
+
itemProps?: ((option: O, state: MultiComboboxItemState$1) => Omit<ComponentProps<"div">, "children">) | undefined;
|
|
56
|
+
/** Custom option content, including the check mark. */
|
|
57
|
+
renderItem?: ((option: O, state: MultiComboboxItemState$1) => ReactNode) | undefined;
|
|
58
|
+
/** Props for each selected Tag. */
|
|
59
|
+
tagProps?: ((context: MultiComboboxTagContext<O>) => MultiComboboxTagProps) | undefined;
|
|
60
|
+
/** Renders custom form submission elements for all selected values. */
|
|
61
|
+
renderFormValue?: ((props: MultiComboboxFormValueProps$1) => ReactNode) | undefined;
|
|
62
|
+
}
|
|
63
|
+
type MultiComboboxModeProps<O extends ComboboxSelectOption$1> = {
|
|
64
|
+
/** Select from options or allow free text. @default "select" */
|
|
65
|
+
mode?: "select" | undefined;
|
|
66
|
+
} | {
|
|
67
|
+
mode: "text";
|
|
68
|
+
options: readonly (O & ComboboxTextOption$1)[];
|
|
69
|
+
};
|
|
70
|
+
export type MultiComboboxProps<O extends ComboboxSelectOption$1 = ComboboxSelectOption$1> = HuiComponentProps<MultiComboboxOwnProps<O>, MultiComboboxSlots> & MultiComboboxModeProps<O>;
|
|
71
|
+
export declare function MultiCombobox<O extends ComboboxSelectOption$1>(rawProps: MultiComboboxProps<O>): ReactElement;
|
|
72
|
+
export type { MultiComboboxFormValueProps, MultiComboboxItemState };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { useComboboxForm } from "../combobox/use-combobox-form.js";
|
|
4
|
+
import { useComboboxPopover } from "../combobox/use-combobox-popover.js";
|
|
5
|
+
import { Label } from "../label/label.js";
|
|
6
|
+
import { MultiComboboxOption } from "./multi-combobox-option.js";
|
|
7
|
+
import { MultiComboboxTag } from "./multi-combobox-tag.js";
|
|
8
|
+
import { useMultiComboboxState } from "./use-multi-combobox-state.js";
|
|
9
|
+
import { cc, comboboxControl, inputControl, moveComboboxActiveValue, multiComboboxControl, multiComboboxRecipe, popoverControl, toStrbool } from "@hebium-ui/core";
|
|
10
|
+
import { useCallback, useId, useMemo, useRef } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
// src/components/multi-combobox/multi-combobox.tsx
|
|
13
|
+
function MultiCombobox(rawProps) {
|
|
14
|
+
const props = useHuiProps("MultiCombobox", rawProps);
|
|
15
|
+
const { options, color, label, labelProps, description, error, required = false, requiredMessage, name, form, inputProps = {}, listProps = {}, itemProps, renderItem, tagProps, renderFormValue } = props;
|
|
16
|
+
const generatedId = useId();
|
|
17
|
+
const inputId = inputProps.id ?? `${generatedId}-input`;
|
|
18
|
+
const listId = listProps.id ?? `${generatedId}-list`;
|
|
19
|
+
const labelId = labelProps?.id ?? `${generatedId}-label`;
|
|
20
|
+
const hasLabel = !!label || !!description || !!error;
|
|
21
|
+
const { state, filteredOptions, activeOption, setActiveValue, clearActiveValue, edit, toggle: toggleValue, remove: removeValue, finishQuery, reset } = useMultiComboboxState(props);
|
|
22
|
+
const inputRef = useRef(null);
|
|
23
|
+
const rootRef = useRef(null);
|
|
24
|
+
const composingRef = useRef(false);
|
|
25
|
+
const attachInput = useComboboxForm({
|
|
26
|
+
inputRef,
|
|
27
|
+
externalRef: inputProps.ref,
|
|
28
|
+
associatedFormId: inputProps.form ?? form,
|
|
29
|
+
validationMessage: multiComboboxControl.getValidationMessage({
|
|
30
|
+
value: state.value,
|
|
31
|
+
required,
|
|
32
|
+
disabled: state.disabled,
|
|
33
|
+
readOnly: state.readOnly,
|
|
34
|
+
requiredMessage
|
|
35
|
+
}),
|
|
36
|
+
onReset: reset
|
|
37
|
+
});
|
|
38
|
+
const { opened, listRef, attachList, showList, closeList, handleToggle } = useComboboxPopover({
|
|
39
|
+
state,
|
|
40
|
+
filteredOptions,
|
|
41
|
+
inputRef,
|
|
42
|
+
externalRef: listProps.ref,
|
|
43
|
+
onClose: clearActiveValue,
|
|
44
|
+
onToggle: listProps.onToggle
|
|
45
|
+
});
|
|
46
|
+
const remove = useCallback((value, button) => {
|
|
47
|
+
const moveFocus = multiComboboxControl.createTagRemovalFocus({
|
|
48
|
+
root: rootRef.current,
|
|
49
|
+
input: inputRef.current,
|
|
50
|
+
button,
|
|
51
|
+
value: state.value,
|
|
52
|
+
removedValue: value
|
|
53
|
+
});
|
|
54
|
+
removeValue(value, moveFocus);
|
|
55
|
+
}, [state.value, removeValue]);
|
|
56
|
+
const toggle = useCallback((value) => {
|
|
57
|
+
if (toggleValue(value)) inputRef.current?.focus({ preventScroll: true });
|
|
58
|
+
}, [toggleValue]);
|
|
59
|
+
const handleChange = useCallback((event) => {
|
|
60
|
+
inputProps.onChange?.(event);
|
|
61
|
+
if (event.defaultPrevented) return;
|
|
62
|
+
edit(event.currentTarget.value);
|
|
63
|
+
showList();
|
|
64
|
+
}, [
|
|
65
|
+
inputProps,
|
|
66
|
+
edit,
|
|
67
|
+
showList
|
|
68
|
+
]);
|
|
69
|
+
const handleKeyDown = useCallback((event) => {
|
|
70
|
+
inputProps.onKeyDown?.(event);
|
|
71
|
+
if (event.defaultPrevented || composingRef.current) return;
|
|
72
|
+
const visible = popoverControl.isOpened(listRef.current);
|
|
73
|
+
const action = multiComboboxControl.getKeyAction(event.nativeEvent, {
|
|
74
|
+
...state,
|
|
75
|
+
opened: visible
|
|
76
|
+
}, visible ? activeOption : void 0);
|
|
77
|
+
switch (action) {
|
|
78
|
+
case "next":
|
|
79
|
+
case "previous":
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
if (showList()) setActiveValue(moveComboboxActiveValue(filteredOptions, visible ? state.activeValue : null, action));
|
|
82
|
+
return;
|
|
83
|
+
case "commit":
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
if (activeOption) toggle(activeOption.value);
|
|
86
|
+
return;
|
|
87
|
+
case "blocked":
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
return;
|
|
90
|
+
case "add":
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
finishQuery();
|
|
93
|
+
showList();
|
|
94
|
+
return;
|
|
95
|
+
case "focus-tag":
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
multiComboboxControl.focusLastTag(rootRef.current, state.value);
|
|
98
|
+
return;
|
|
99
|
+
case "submit":
|
|
100
|
+
closeList();
|
|
101
|
+
return;
|
|
102
|
+
case "none": return;
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
inputProps,
|
|
106
|
+
listRef,
|
|
107
|
+
state,
|
|
108
|
+
activeOption,
|
|
109
|
+
showList,
|
|
110
|
+
setActiveValue,
|
|
111
|
+
filteredOptions,
|
|
112
|
+
toggle,
|
|
113
|
+
finishQuery,
|
|
114
|
+
closeList
|
|
115
|
+
]);
|
|
116
|
+
const handleInputClick = useCallback((event) => {
|
|
117
|
+
inputProps.onClick?.(event);
|
|
118
|
+
if (!event.defaultPrevented) showList();
|
|
119
|
+
}, [inputProps, showList]);
|
|
120
|
+
const handleBlur = useCallback((event) => {
|
|
121
|
+
if (event.defaultPrevented || !(event.relatedTarget instanceof Node) || event.currentTarget.contains(event.relatedTarget)) return;
|
|
122
|
+
finishQuery();
|
|
123
|
+
closeList();
|
|
124
|
+
}, [finishQuery, closeList]);
|
|
125
|
+
const handleCompositionStart = useCallback((event) => {
|
|
126
|
+
inputProps.onCompositionStart?.(event);
|
|
127
|
+
composingRef.current = true;
|
|
128
|
+
}, [inputProps]);
|
|
129
|
+
const handleCompositionEnd = useCallback((event) => {
|
|
130
|
+
inputProps.onCompositionEnd?.(event);
|
|
131
|
+
composingRef.current = false;
|
|
132
|
+
}, [inputProps]);
|
|
133
|
+
const optionsByValue = useMemo(() => new Map(options.map((option) => [option.value, option])), [options]);
|
|
134
|
+
const itemIds = useMemo(() => new Map(options.map((option, index) => [option.value, `${listId}-option-${index}`])), [options, listId]);
|
|
135
|
+
const inputAttributes = normalizeAttributes(comboboxControl.getInputAttributes({
|
|
136
|
+
inputId,
|
|
137
|
+
listId,
|
|
138
|
+
opened,
|
|
139
|
+
required,
|
|
140
|
+
activeId: activeOption ? itemIds.get(activeOption.value) : void 0
|
|
141
|
+
}));
|
|
142
|
+
const labelAttributes = normalizeAttributes(inputControl.getLabelAttributes({
|
|
143
|
+
id: inputId,
|
|
144
|
+
invalid: !!error,
|
|
145
|
+
required,
|
|
146
|
+
disabled: state.disabled,
|
|
147
|
+
readOnly: state.readOnly
|
|
148
|
+
}));
|
|
149
|
+
const formValueProps = multiComboboxControl.getFormValueProps({
|
|
150
|
+
name,
|
|
151
|
+
value: state.value,
|
|
152
|
+
form
|
|
153
|
+
});
|
|
154
|
+
const recipe = multiComboboxRecipe({
|
|
155
|
+
color,
|
|
156
|
+
error: toStrbool(!!error)
|
|
157
|
+
});
|
|
158
|
+
const cls = useHuiClassNames("MultiCombobox", recipe, rawProps);
|
|
159
|
+
const sls = useHuiStyles("MultiCombobox", rawProps);
|
|
160
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
161
|
+
ref: rootRef,
|
|
162
|
+
disabled: state.disabled,
|
|
163
|
+
"aria-labelledby": hasLabel ? labelId : void 0,
|
|
164
|
+
className: cls.root,
|
|
165
|
+
style: sls.root,
|
|
166
|
+
onBlur: handleBlur,
|
|
167
|
+
children: [
|
|
168
|
+
hasLabel && /* @__PURE__ */ jsx(Label, {
|
|
169
|
+
...labelAttributes,
|
|
170
|
+
description,
|
|
171
|
+
error,
|
|
172
|
+
...labelProps,
|
|
173
|
+
id: labelId,
|
|
174
|
+
children: label
|
|
175
|
+
}),
|
|
176
|
+
state.value.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
177
|
+
className: cls.tags,
|
|
178
|
+
style: sls.tags,
|
|
179
|
+
children: state.value.map((value) => {
|
|
180
|
+
const option = optionsByValue.get(value);
|
|
181
|
+
return /* @__PURE__ */ jsx(MultiComboboxTag, {
|
|
182
|
+
value,
|
|
183
|
+
label: multiComboboxControl.getTagLabel(state.mode, value, option),
|
|
184
|
+
option,
|
|
185
|
+
tagProps,
|
|
186
|
+
disabled: state.readOnly,
|
|
187
|
+
remove
|
|
188
|
+
}, value);
|
|
189
|
+
})
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ jsx("input", {
|
|
192
|
+
...inputAttributes,
|
|
193
|
+
"aria-invalid": !!error,
|
|
194
|
+
form,
|
|
195
|
+
value: state.query,
|
|
196
|
+
...inputProps,
|
|
197
|
+
readOnly: state.readOnly || inputProps.readOnly,
|
|
198
|
+
className: cc(cls.input, inputProps.className),
|
|
199
|
+
style: {
|
|
200
|
+
...sls.input,
|
|
201
|
+
...inputProps.style
|
|
202
|
+
},
|
|
203
|
+
ref: attachInput,
|
|
204
|
+
onChange: handleChange,
|
|
205
|
+
onKeyDown: handleKeyDown,
|
|
206
|
+
onClick: handleInputClick,
|
|
207
|
+
onCompositionStart: handleCompositionStart,
|
|
208
|
+
onCompositionEnd: handleCompositionEnd
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx("div", {
|
|
211
|
+
...normalizeAttributes(multiComboboxControl.getListAttributes(listId, inputId, state)),
|
|
212
|
+
...listProps,
|
|
213
|
+
className: cc(cls.list, listProps.className),
|
|
214
|
+
style: {
|
|
215
|
+
...sls.list,
|
|
216
|
+
...listProps.style
|
|
217
|
+
},
|
|
218
|
+
ref: attachList,
|
|
219
|
+
onToggle: handleToggle,
|
|
220
|
+
children: filteredOptions.map((option) => {
|
|
221
|
+
const id = itemIds.get(option.value);
|
|
222
|
+
if (id === void 0) return null;
|
|
223
|
+
return /* @__PURE__ */ jsx(MultiComboboxOption, {
|
|
224
|
+
option,
|
|
225
|
+
id,
|
|
226
|
+
mode: state.mode,
|
|
227
|
+
selected: state.value.includes(option.value),
|
|
228
|
+
active: opened && activeOption?.value === option.value,
|
|
229
|
+
className: cls.item,
|
|
230
|
+
style: sls.item,
|
|
231
|
+
indicatorClassName: cls.itemIndicator,
|
|
232
|
+
indicatorStyle: sls.itemIndicator,
|
|
233
|
+
itemProps,
|
|
234
|
+
renderItem,
|
|
235
|
+
toggle
|
|
236
|
+
}, option.value);
|
|
237
|
+
})
|
|
238
|
+
}),
|
|
239
|
+
formValueProps && (renderFormValue ? renderFormValue(formValueProps) : formValueProps.value.map((value) => /* @__PURE__ */ jsx("input", {
|
|
240
|
+
type: "hidden",
|
|
241
|
+
...formValueProps,
|
|
242
|
+
value
|
|
243
|
+
}, value)))
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
export { MultiCombobox };
|
|
248
|
+
|
|
249
|
+
//# sourceMappingURL=multi-combobox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-combobox.js","names":[],"sources":["../../../src/components/multi-combobox/multi-combobox.tsx"],"sourcesContent":["import {\n cc,\n comboboxControl,\n type ComboboxSelectOption,\n type ComboboxTextOption,\n inputControl,\n moveComboboxActiveValue,\n multiComboboxControl,\n type MultiComboboxFormValueProps,\n type MultiComboboxItemState,\n multiComboboxRecipe,\n type MultiComboboxSlots,\n type MultiComboboxVariants,\n popoverControl,\n toStrbool,\n} from \"@hebium-ui/core\";\nimport {\n type ChangeEvent,\n type ComponentProps,\n type CompositionEvent,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n useCallback,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport { useComboboxForm } from \"../combobox/use-combobox-form\";\nimport { useComboboxPopover } from \"../combobox/use-combobox-popover\";\nimport { Label, type LabelProps } from \"../label\";\nimport { type TagProps } from \"../tag\";\nimport { MultiComboboxOption } from \"./multi-combobox-option\";\nimport { MultiComboboxTag } from \"./multi-combobox-tag\";\nimport { useMultiComboboxState } from \"./use-multi-combobox-state\";\n\nexport interface MultiComboboxTagContext<O extends ComboboxSelectOption = ComboboxSelectOption> {\n value: string;\n /** Standard display text. In text mode this is the committed value itself. */\n label: string;\n /** The matching candidate, if one exists. */\n option: O | undefined;\n}\n\nexport type MultiComboboxTagProps = Omit<TagProps, \"label\" | \"onRemove\">;\n\ninterface MultiComboboxOwnProps<O extends ComboboxSelectOption> {\n /** Available options. Values must be unique. */\n options: readonly O[];\n /** The controlled values. Values must be unique. */\n value?: readonly string[] | undefined;\n /** The initial uncontrolled values. @default [] */\n defaultValue?: readonly string[] | undefined;\n /**\n * Called with the next values. In controlled mode, call the optional focus callback when accepting a Tag removal.\n */\n onChange?: ((value: string[], moveFocus?: () => void) => void) | undefined;\n /** The input's semantic color. @default \"accent\" */\n color?: MultiComboboxVariants[\"color\"] | undefined;\n /** The label displayed above the input. */\n label?: ReactNode | undefined;\n /** Additional props passed to the label. */\n labelProps?: LabelProps | undefined;\n /** Help text displayed below the label. */\n description?: ReactNode | undefined;\n /** Inline validation feedback. */\n error?: ReactNode | undefined;\n /** The name used for form submission. */\n name?: string | undefined;\n /** The id of the associated form. */\n form?: string | undefined;\n /** Prevents interaction and excludes values from form submission. */\n disabled?: boolean | undefined;\n /** Prevents editing and opening the list. Values are still submitted. */\n readOnly?: boolean | undefined;\n /** Requires at least one selected value. */\n required?: boolean | undefined;\n /** Native validation message. @default \"Please fill out this field.\" */\n requiredMessage?: string | undefined;\n /** Props passed to the input element. */\n inputProps?: Omit<ComponentProps<\"input\">, \"children\"> | undefined;\n /** Props passed to the listbox element. */\n listProps?: Omit<ComponentProps<\"div\">, \"children\"> | undefined;\n /** Props for each option wrapper. */\n itemProps?: ((option: O, state: MultiComboboxItemState) => Omit<ComponentProps<\"div\">, \"children\">) | undefined;\n /** Custom option content, including the check mark. */\n renderItem?: ((option: O, state: MultiComboboxItemState) => ReactNode) | undefined;\n /** Props for each selected Tag. */\n tagProps?: ((context: MultiComboboxTagContext<O>) => MultiComboboxTagProps) | undefined;\n /** Renders custom form submission elements for all selected values. */\n renderFormValue?: ((props: MultiComboboxFormValueProps) => ReactNode) | undefined;\n}\n\ntype MultiComboboxModeProps<O extends ComboboxSelectOption> =\n | {\n /** Select from options or allow free text. @default \"select\" */\n mode?: \"select\" | undefined;\n }\n | {\n mode: \"text\";\n options: readonly (O & ComboboxTextOption)[];\n };\n\nexport type MultiComboboxProps<O extends ComboboxSelectOption = ComboboxSelectOption> =\n & HuiComponentProps<MultiComboboxOwnProps<O>, MultiComboboxSlots>\n & MultiComboboxModeProps<O>;\n\nexport function MultiCombobox<O extends ComboboxSelectOption>(rawProps: MultiComboboxProps<O>): ReactElement {\n const props = useHuiProps(\"MultiCombobox\", rawProps);\n const {\n options,\n color,\n label,\n labelProps,\n description,\n error,\n required = false,\n requiredMessage,\n name,\n form,\n inputProps = {},\n listProps = {},\n itemProps,\n renderItem,\n tagProps,\n renderFormValue,\n } = props;\n const generatedId = useId();\n const inputId = inputProps.id ?? `${generatedId}-input`;\n const listId = listProps.id ?? `${generatedId}-list`;\n const labelId = labelProps?.id ?? `${generatedId}-label`;\n const hasLabel = !!label || !!description || !!error;\n\n const {\n state,\n filteredOptions,\n activeOption,\n setActiveValue,\n clearActiveValue,\n edit,\n toggle: toggleValue,\n remove: removeValue,\n finishQuery,\n reset,\n } = useMultiComboboxState<O>(props);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const rootRef = useRef<HTMLFieldSetElement | null>(null);\n const composingRef = useRef(false);\n const attachInput = useComboboxForm({\n inputRef,\n externalRef: inputProps.ref,\n associatedFormId: inputProps.form ?? form,\n validationMessage: multiComboboxControl.getValidationMessage({\n value: state.value,\n required,\n disabled: state.disabled,\n readOnly: state.readOnly,\n requiredMessage,\n }),\n onReset: reset,\n });\n\n const {\n opened,\n listRef,\n attachList,\n showList,\n closeList,\n handleToggle,\n } = useComboboxPopover({\n state,\n filteredOptions,\n inputRef,\n externalRef: listProps.ref,\n onClose: clearActiveValue,\n onToggle: listProps.onToggle,\n });\n\n const remove = useCallback((value: string, button: HTMLButtonElement): void => {\n const moveFocus = multiComboboxControl.createTagRemovalFocus({\n root: rootRef.current,\n input: inputRef.current,\n button,\n value: state.value,\n removedValue: value,\n });\n removeValue(value, moveFocus);\n }, [state.value, removeValue]);\n const toggle = useCallback((value: string): void => {\n if (toggleValue(value)) inputRef.current?.focus({ preventScroll: true });\n }, [toggleValue]);\n\n const handleChange = useCallback((event: ChangeEvent<HTMLInputElement>): void => {\n inputProps.onChange?.(event);\n if (event.defaultPrevented) return;\n edit(event.currentTarget.value);\n showList();\n }, [inputProps, edit, showList]);\n\n const handleKeyDown = useCallback((event: KeyboardEvent<HTMLInputElement>): void => {\n inputProps.onKeyDown?.(event);\n if (event.defaultPrevented || composingRef.current) return;\n const visible = popoverControl.isOpened(listRef.current);\n const action = multiComboboxControl.getKeyAction(\n event.nativeEvent,\n { ...state, opened: visible },\n visible ? activeOption : undefined,\n );\n switch (action) {\n case \"next\":\n case \"previous\":\n event.preventDefault();\n if (showList()) {\n setActiveValue(moveComboboxActiveValue(filteredOptions, visible ? state.activeValue : null, action));\n }\n return;\n case \"commit\":\n event.preventDefault();\n if (activeOption) toggle(activeOption.value);\n return;\n case \"blocked\":\n event.preventDefault();\n return;\n case \"add\":\n event.preventDefault();\n finishQuery();\n showList();\n return;\n case \"focus-tag\":\n event.preventDefault();\n multiComboboxControl.focusLastTag(rootRef.current, state.value);\n return;\n case \"submit\":\n closeList();\n return;\n case \"none\":\n return;\n }\n }, [\n inputProps,\n listRef,\n state,\n activeOption,\n showList,\n setActiveValue,\n filteredOptions,\n toggle,\n finishQuery,\n closeList,\n ]);\n\n const handleInputClick = useCallback((event: MouseEvent<HTMLInputElement>): void => {\n inputProps.onClick?.(event);\n if (!event.defaultPrevented) showList();\n }, [inputProps, showList]);\n\n const handleBlur = useCallback((event: FocusEvent<HTMLFieldSetElement>): void => {\n if (\n event.defaultPrevented\n || !(event.relatedTarget instanceof Node)\n || event.currentTarget.contains(event.relatedTarget)\n ) return;\n finishQuery();\n closeList();\n }, [finishQuery, closeList]);\n\n const handleCompositionStart = useCallback((event: CompositionEvent<HTMLInputElement>): void => {\n inputProps.onCompositionStart?.(event);\n composingRef.current = true;\n }, [inputProps]);\n const handleCompositionEnd = useCallback((event: CompositionEvent<HTMLInputElement>): void => {\n inputProps.onCompositionEnd?.(event);\n composingRef.current = false;\n }, [inputProps]);\n\n const optionsByValue = useMemo(() => new Map(options.map((option) => [option.value, option])), [options]);\n const itemIds = useMemo(\n () => new Map(options.map((option, index) => [option.value, `${listId}-option-${index}`])),\n [options, listId],\n );\n const inputAttributes = normalizeAttributes(comboboxControl.getInputAttributes({\n inputId,\n listId,\n opened,\n required,\n activeId: activeOption ? itemIds.get(activeOption.value) : undefined,\n }));\n const labelAttributes = normalizeAttributes(inputControl.getLabelAttributes({\n id: inputId,\n invalid: !!error,\n required,\n disabled: state.disabled,\n readOnly: state.readOnly,\n }));\n const formValueProps = multiComboboxControl.getFormValueProps({\n name,\n value: state.value,\n form,\n });\n const recipe = multiComboboxRecipe({ color, error: toStrbool(!!error) });\n const cls = useHuiClassNames(\"MultiCombobox\", recipe, rawProps);\n const sls = useHuiStyles(\"MultiCombobox\", rawProps);\n\n return (\n // Blur only observes focus leaving the composite field; the fieldset itself is not interactive.\n // oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n <fieldset\n ref={rootRef}\n disabled={state.disabled}\n aria-labelledby={hasLabel ? labelId : undefined}\n className={cls.root}\n style={sls.root}\n onBlur={handleBlur}\n >\n {hasLabel && (\n <Label\n {...labelAttributes}\n description={description}\n error={error}\n {...labelProps}\n id={labelId}\n >\n {label}\n </Label>\n )}\n {state.value.length > 0 && (\n <div\n className={cls.tags}\n style={sls.tags}\n >\n {state.value.map((value) => {\n const option = optionsByValue.get(value);\n return (\n <MultiComboboxTag\n key={value}\n value={value}\n label={multiComboboxControl.getTagLabel(state.mode, value, option)}\n option={option}\n tagProps={tagProps}\n disabled={state.readOnly}\n remove={remove}\n />\n );\n })}\n </div>\n )}\n <input\n {...inputAttributes}\n aria-invalid={!!error}\n form={form}\n value={state.query}\n {...inputProps}\n readOnly={state.readOnly || inputProps.readOnly}\n className={cc(cls.input, inputProps.className)}\n style={{ ...sls.input, ...inputProps.style }}\n ref={attachInput}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onClick={handleInputClick}\n onCompositionStart={handleCompositionStart}\n onCompositionEnd={handleCompositionEnd}\n />\n <div\n {...normalizeAttributes(multiComboboxControl.getListAttributes(listId, inputId, state))}\n {...listProps}\n className={cc(cls.list, listProps.className)}\n style={{ ...sls.list, ...listProps.style }}\n ref={attachList}\n onToggle={handleToggle}\n >\n {filteredOptions.map((option) => {\n const id = itemIds.get(option.value);\n if (id === undefined) return null;\n return (\n <MultiComboboxOption\n key={option.value}\n option={option}\n id={id}\n mode={state.mode}\n selected={state.value.includes(option.value)}\n active={opened && activeOption?.value === option.value}\n className={cls.item}\n style={sls.item}\n indicatorClassName={cls.itemIndicator}\n indicatorStyle={sls.itemIndicator}\n itemProps={itemProps}\n renderItem={renderItem}\n toggle={toggle}\n />\n );\n })}\n </div>\n {formValueProps && (renderFormValue\n ? renderFormValue(formValueProps)\n : formValueProps.value.map((value) => (\n <input\n key={value}\n type=\"hidden\"\n {...formValueProps}\n value={value}\n />\n )))}\n </fieldset>\n );\n}\n\nexport type {\n ComboboxSelectOption,\n ComboboxTextOption,\n MultiComboboxFormValueProps,\n MultiComboboxItemState,\n} from \"@hebium-ui/core\";\n"],"mappings":";;;;;;;;;;;;AAgHA,SAAgB,cAA8C,UAA+C;CAC3G,MAAM,QAAQ,YAAY,iBAAiB,QAAQ;CACnD,MAAM,EACJ,SACA,OACA,OACA,YACA,aACA,OACA,WAAW,OACX,iBACA,MACA,MACA,aAAa,CAAC,GACd,YAAY,CAAC,GACb,WACA,YACA,UACA,oBACE;CACJ,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,WAAW,MAAM,GAAG,YAAY;CAChD,MAAM,SAAS,UAAU,MAAM,GAAG,YAAY;CAC9C,MAAM,UAAU,YAAY,MAAM,GAAG,YAAY;CACjD,MAAM,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;CAE/C,MAAM,EACJ,OACA,iBACA,cACA,gBACA,kBACA,MACA,QAAQ,aACR,QAAQ,aACR,aACA,UACE,sBAAyB,KAAK;CAClC,M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AO,WAAW,SAAS;IAC7C,OAAO;KAAE,GAAG,IAAI;KAAO,GAAG,WAAW;IAAM;IAC3C,KAAK;IACL,UAAU;IACV,WAAW;IACX,SAAS;IACT,oBAAoB;IACpB,kBAAkB;GACnB,CAAA;GACD,oBAAC,OAAD;IACE,GAAI,oBAAoB,qBAAqB,kBAAkB,QAAQ,SAAS,KAAK,CAAC;IACtF,GAAI;IACJ,WAAW,GAAG,IAAI,MAAM,UAAU,SAAS;IAC3C,OAAO;KAAE,GAAG,IAAI;KAAM,GAAG,UAAU;IAAM;IACzC,KAAK;IACL,UAAU;IAET,UAAA,gBAAgB,KAAK,WAAW;KAC/B,MAAM,KAAK,QAAQ,IAAI,OAAO,KAAK;KACnC,IAAI,OAAO,KAAA,GAAW,OAAO;KAC7B,OACE,oBAAC,qBAAD;MAEU;MACJ;MACJ,MAAM,MAAM;MACZ,UAAU,MAAM,MAAM,SAAS,OAAO,KAAK;MAC3C,QAAQ,UAAU,cAAc,UAAU,OAAO;MACjD,WAAW,IAAI;MACf,OAAO,IAAI;MACX,oBAAoB,IAAI;MACxB,gBAAgB,IAAI;MACT;MACC;MACJ;KACT,GAbM,OAAO,KAab;IAEL,CAAC;GACE,CAAA;GACJ,mBAAmB,kBAChB,gBAAgB,cAAc,IAC9B,eAAe,MAAM,KAAK,UAC1B,oBAAC,SAAD;IAEE,MAAK;IACL,GAAI;IACG;GACR,GAJM,KAIN,CACF;EACK;;AAEd"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { comboboxControl, filterComboboxOptions, multiComboboxControl } from "@hebium-ui/core";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
// src/components/multi-combobox/use-multi-combobox-state.ts
|
|
4
|
+
const EMPTY_VALUE = [];
|
|
5
|
+
function useMultiComboboxState(props) {
|
|
6
|
+
const { options, mode = "select", value, defaultValue, onChange, disabled = false, readOnly = false } = props;
|
|
7
|
+
const isControlled = value !== void 0;
|
|
8
|
+
const initialValue = defaultValue ?? EMPTY_VALUE;
|
|
9
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
|
|
10
|
+
const [query, setQuery] = useState("");
|
|
11
|
+
const [activeValue, setActiveValue] = useState(null);
|
|
12
|
+
const currentValue = isControlled ? value : uncontrolledValue;
|
|
13
|
+
const state = useMemo(() => ({
|
|
14
|
+
mode,
|
|
15
|
+
value: currentValue,
|
|
16
|
+
query,
|
|
17
|
+
activeValue,
|
|
18
|
+
disabled,
|
|
19
|
+
readOnly
|
|
20
|
+
}), [
|
|
21
|
+
mode,
|
|
22
|
+
currentValue,
|
|
23
|
+
query,
|
|
24
|
+
activeValue,
|
|
25
|
+
disabled,
|
|
26
|
+
readOnly
|
|
27
|
+
]);
|
|
28
|
+
const filteredOptions = useMemo(() => filterComboboxOptions(mode, options, query), [
|
|
29
|
+
mode,
|
|
30
|
+
options,
|
|
31
|
+
query
|
|
32
|
+
]);
|
|
33
|
+
const activeOption = filteredOptions.find((option) => option.value === activeValue);
|
|
34
|
+
const changeValue = useCallback((nextValue, moveFocus) => {
|
|
35
|
+
if (!isControlled) {
|
|
36
|
+
setUncontrolledValue(nextValue);
|
|
37
|
+
moveFocus?.();
|
|
38
|
+
}
|
|
39
|
+
if (isControlled && moveFocus) onChange?.(nextValue, moveFocus);
|
|
40
|
+
else onChange?.(nextValue);
|
|
41
|
+
}, [isControlled, onChange]);
|
|
42
|
+
const edit = useCallback((text) => {
|
|
43
|
+
if (!comboboxControl.canEdit(state)) return;
|
|
44
|
+
setActiveValue(null);
|
|
45
|
+
setQuery(text);
|
|
46
|
+
}, [state]);
|
|
47
|
+
const toggle = useCallback((candidateValue) => {
|
|
48
|
+
const option = options.find((candidate) => candidate.value === candidateValue);
|
|
49
|
+
if (!option) return false;
|
|
50
|
+
const nextValue = multiComboboxControl.toggle(state, option);
|
|
51
|
+
if (!nextValue) return false;
|
|
52
|
+
setQuery("");
|
|
53
|
+
setActiveValue(null);
|
|
54
|
+
changeValue(nextValue);
|
|
55
|
+
return true;
|
|
56
|
+
}, [
|
|
57
|
+
state,
|
|
58
|
+
options,
|
|
59
|
+
changeValue
|
|
60
|
+
]);
|
|
61
|
+
const remove = useCallback((selectedValue, moveFocus) => {
|
|
62
|
+
const nextValue = multiComboboxControl.remove(state, selectedValue);
|
|
63
|
+
if (nextValue) changeValue(nextValue, moveFocus);
|
|
64
|
+
}, [state, changeValue]);
|
|
65
|
+
const finishQuery = useCallback(() => {
|
|
66
|
+
if (!comboboxControl.canEdit(state)) return;
|
|
67
|
+
const nextValue = multiComboboxControl.addText(state);
|
|
68
|
+
setQuery("");
|
|
69
|
+
if (nextValue) changeValue(nextValue);
|
|
70
|
+
}, [state, changeValue]);
|
|
71
|
+
return {
|
|
72
|
+
state,
|
|
73
|
+
filteredOptions,
|
|
74
|
+
activeOption,
|
|
75
|
+
setActiveValue,
|
|
76
|
+
clearActiveValue: useCallback(() => {
|
|
77
|
+
setActiveValue(null);
|
|
78
|
+
}, []),
|
|
79
|
+
edit,
|
|
80
|
+
toggle,
|
|
81
|
+
remove,
|
|
82
|
+
finishQuery,
|
|
83
|
+
reset: useCallback(() => {
|
|
84
|
+
setQuery("");
|
|
85
|
+
if (!isControlled) setUncontrolledValue(initialValue);
|
|
86
|
+
}, [isControlled, initialValue])
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export { useMultiComboboxState };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=use-multi-combobox-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-combobox-state.js","names":[],"sources":["../../../src/components/multi-combobox/use-multi-combobox-state.ts"],"sourcesContent":["import {\n comboboxControl,\n type ComboboxSelectOption,\n filterComboboxOptions,\n multiComboboxControl,\n type MultiComboboxState,\n} from \"@hebium-ui/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport { type MultiComboboxProps } from \"./multi-combobox\";\n\nconst EMPTY_VALUE: readonly string[] = [];\n\ntype UseMultiComboboxStateOptions<O extends ComboboxSelectOption> = Pick<\n MultiComboboxProps<O>,\n \"options\" | \"mode\" | \"value\" | \"defaultValue\" | \"onChange\" | \"disabled\" | \"readOnly\"\n>;\n\ninterface MultiComboboxStateController<O extends ComboboxSelectOption> {\n state: MultiComboboxState;\n filteredOptions: readonly O[];\n activeOption: O | undefined;\n setActiveValue: (value: string | null) => void;\n clearActiveValue: () => void;\n edit: (text: string) => void;\n toggle: (value: string) => boolean;\n remove: (value: string, moveFocus?: () => void) => void;\n finishQuery: () => void;\n reset: () => void;\n}\n\nexport function useMultiComboboxState<O extends ComboboxSelectOption>(\n props: UseMultiComboboxStateOptions<O>,\n): MultiComboboxStateController<O> {\n const {\n options,\n mode = \"select\",\n value,\n defaultValue,\n onChange,\n disabled = false,\n readOnly = false,\n } = props;\n const isControlled = value !== undefined;\n const initialValue = defaultValue ?? EMPTY_VALUE;\n const [uncontrolledValue, setUncontrolledValue] = useState<readonly string[]>(initialValue);\n const [query, setQuery] = useState(\"\");\n const [activeValue, setActiveValue] = useState<string | null>(null);\n const currentValue = isControlled ? value : uncontrolledValue;\n const state = useMemo<MultiComboboxState>(\n () => ({ mode, value: currentValue, query, activeValue, disabled, readOnly }),\n [mode, currentValue, query, activeValue, disabled, readOnly],\n );\n const filteredOptions = useMemo(() => filterComboboxOptions(mode, options, query), [mode, options, query]);\n const activeOption = filteredOptions.find((option) => option.value === activeValue);\n\n const changeValue = useCallback((nextValue: string[], moveFocus?: () => void): void => {\n if (!isControlled) {\n setUncontrolledValue(nextValue);\n moveFocus?.();\n }\n if (isControlled && moveFocus) onChange?.(nextValue, moveFocus);\n else onChange?.(nextValue);\n }, [isControlled, onChange]);\n\n const edit = useCallback((text: string): void => {\n if (!comboboxControl.canEdit(state)) return;\n setActiveValue(null);\n setQuery(text);\n }, [state]);\n\n const toggle = useCallback((candidateValue: string): boolean => {\n const option = options.find((candidate) => candidate.value === candidateValue);\n if (!option) return false;\n const nextValue = multiComboboxControl.toggle(state, option);\n if (!nextValue) return false;\n setQuery(\"\");\n setActiveValue(null);\n changeValue(nextValue);\n return true;\n }, [state, options, changeValue]);\n\n const remove = useCallback((selectedValue: string, moveFocus?: () => void): void => {\n const nextValue = multiComboboxControl.remove(state, selectedValue);\n if (nextValue) changeValue(nextValue, moveFocus);\n }, [state, changeValue]);\n\n const finishQuery = useCallback((): void => {\n if (!comboboxControl.canEdit(state)) return;\n const nextValue = multiComboboxControl.addText(state);\n setQuery(\"\");\n if (nextValue) changeValue(nextValue);\n }, [state, changeValue]);\n\n const clearActiveValue = useCallback((): void => {\n setActiveValue(null);\n }, []);\n\n const reset = useCallback((): void => {\n setQuery(\"\");\n if (!isControlled) setUncontrolledValue(initialValue);\n }, [isControlled, initialValue]);\n\n return {\n state,\n filteredOptions,\n activeOption,\n setActiveValue,\n clearActiveValue,\n edit,\n toggle,\n remove,\n finishQuery,\n reset,\n };\n}\n"],"mappings":";;;AAUA,MAAM,cAAiC,CAAC;AAoBxC,SAAgB,sBACd,OACiC;CACjC,MAAM,EACJ,SACA,OAAO,UACP,OACA,cACA,UACA,WAAW,OACX,WAAW,UACT;CACJ,MAAM,eAAe,UAAU,KAAA;CAC/B,MAAM,eAAe,gBAAgB;CACrC,MAAM,CAAC,mBAAmB,wBAAwB,SAA4B,YAAY;CAC1F,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,CAAC,aAAa,kBAAkB,SAAwB,IAAI;CAClE,MAAM,eAAe,eAAe,QAAQ;CAC5C,MAAM,QAAQ,eACL;EAAE;EAAM,OAAO;EAAc;EAAO;EAAa;EAAU;CAAS,IAC3E;EAAC;EAAM;EAAc;EAAO;EAAa;EAAU;CAAQ,CAC7D;CACA,MAAM,kBAAkB,cAAc,sBAAsB,MAAM,SAAS,KAAK,GAAG;EAAC;EAAM;EAAS;CAAK,CAAC;CACzG,MAAM,eAAe,gBAAgB,MAAM,WAAW,OAAO,UAAU,WAAW;CAElF,MAAM,cAAc,aAAa,WAAqB,cAAiC;EACrF,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phicProps } from "../../types/polymorphic.js";
|
|
|
2
2
|
import "../../types/index.js";
|
|
3
3
|
import { ParagraphSlots, ParagraphVariants } from "@hebium-ui/core";
|
|
4
4
|
import { ElementType, ReactElement } from "react";
|
|
5
|
-
//#region src/components/paragraph/paragraph.d.ts
|
|
6
5
|
interface ParagraphOwnProps {
|
|
7
6
|
/**
|
|
8
7
|
* The semantic color of the paragraph.
|
|
@@ -19,6 +18,4 @@ interface ParagraphOwnProps {
|
|
|
19
18
|
}
|
|
20
19
|
export type ParagraphProps<E extends ElementType = "p"> = HuiPolymorphicProps<E, ParagraphOwnProps, ParagraphSlots>;
|
|
21
20
|
export declare function Paragraph<E extends ElementType = "p">(rawProps: ParagraphProps<E>): ReactElement;
|
|
22
|
-
|
|
23
|
-
export {};
|
|
24
|
-
//# sourceMappingURL=paragraph.d.ts.map
|
|
21
|
+
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
2
|
import { paragraphRecipe } from "@hebium-ui/core";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
4
|
+
// src/components/paragraph/paragraph.tsx
|
|
5
5
|
function Paragraph(rawProps) {
|
|
6
|
-
const { as, color, margin,
|
|
6
|
+
const { as, color, margin, children, ...restProps } = useHuiProps("Paragraph", rawProps);
|
|
7
7
|
const Component = as ?? "p";
|
|
8
8
|
const recipe = paragraphRecipe({
|
|
9
9
|
color,
|
|
10
10
|
margin
|
|
11
11
|
});
|
|
12
|
-
const cls = useHuiClassNames("Paragraph", recipe,
|
|
13
|
-
const sls = useHuiStyles("Paragraph",
|
|
12
|
+
const cls = useHuiClassNames("Paragraph", recipe, rawProps);
|
|
13
|
+
const sls = useHuiStyles("Paragraph", rawProps);
|
|
14
14
|
return /* @__PURE__ */ jsx(Component, {
|
|
15
15
|
className: cls.root,
|
|
16
16
|
style: sls.root,
|
|
@@ -18,7 +18,6 @@ function Paragraph(rawProps) {
|
|
|
18
18
|
children
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { Paragraph };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=paragraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.js","names":[],"sources":["../../../src/components/paragraph/paragraph.tsx"],"sourcesContent":["import { paragraphRecipe, type ParagraphSlots, type ParagraphVariants } from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\n\ninterface ParagraphOwnProps {\n /**\n * The semantic color of the paragraph.\n *\n * @default \"text\"\n */\n color?: ParagraphVariants[\"color\"] | undefined;\n /**\n * The block margin applied to the paragraph.\n *\n * @default \"block\"\n */\n margin?: ParagraphVariants[\"margin\"] | undefined;\n}\n\nexport type ParagraphProps<E extends ElementType = \"p\"> = HuiPolymorphicProps<\n E,\n ParagraphOwnProps,\n ParagraphSlots\n>;\n\nexport function Paragraph<E extends ElementType = \"p\">(rawProps: ParagraphProps<E>): ReactElement {\n const {\n as,\n color,\n margin,\n
|
|
1
|
+
{"version":3,"file":"paragraph.js","names":[],"sources":["../../../src/components/paragraph/paragraph.tsx"],"sourcesContent":["import { paragraphRecipe, type ParagraphSlots, type ParagraphVariants } from \"@hebium-ui/core\";\nimport { type ElementType, type ReactElement } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiPolymorphicProps } from \"~/types\";\n\ninterface ParagraphOwnProps {\n /**\n * The semantic color of the paragraph.\n *\n * @default \"text\"\n */\n color?: ParagraphVariants[\"color\"] | undefined;\n /**\n * The block margin applied to the paragraph.\n *\n * @default \"block\"\n */\n margin?: ParagraphVariants[\"margin\"] | undefined;\n}\n\nexport type ParagraphProps<E extends ElementType = \"p\"> = HuiPolymorphicProps<\n E,\n ParagraphOwnProps,\n ParagraphSlots\n>;\n\nexport function Paragraph<E extends ElementType = \"p\">(rawProps: ParagraphProps<E>): ReactElement {\n const {\n as,\n color,\n margin,\n children,\n ...restProps\n } = useHuiProps(\"Paragraph\", rawProps);\n\n const Component = as ?? \"p\";\n const recipe = paragraphRecipe({\n color,\n margin,\n });\n const cls = useHuiClassNames(\"Paragraph\", recipe, rawProps);\n const sls = useHuiStyles(\"Paragraph\", rawProps);\n\n return (\n <Component\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </Component>\n );\n}\n"],"mappings":";;;;AA0BA,SAAgB,UAAuC,UAA2C;CAChG,MAAM,EACJ,IACA,OACA,QACA,UACA,GAAG,cACD,YAAY,aAAa,QAAQ;CAErC,MAAM,YAAY,MAAM;CACxB,MAAM,SAAS,gBAAgB;EAC7B;EACA;CACF,CAAC;CACD,MAAM,MAAM,iBAAiB,aAAa,QAAQ,QAAQ;CAC1D,MAAM,MAAM,aAAa,aAAa,QAAQ;CAE9C,OACE,oBAAC,WAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EAEH;CACQ,CAAA;AAEf"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps } from "./popover.js";
|
|
2
|
-
|
|
3
|
-
export { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps, usePopoverId };
|
|
2
|
+
export { Popover, PopoverContentProps, PopoverProps, PopoverTriggerProps };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
-
|
|
2
|
+
// src/components/popover/popover.context.ts
|
|
3
3
|
const PopoverContext = createContext(null);
|
|
4
4
|
function usePopoverContext() {
|
|
5
5
|
const context = useContext(PopoverContext);
|
|
@@ -9,7 +9,6 @@ function usePopoverContext() {
|
|
|
9
9
|
function usePopoverId() {
|
|
10
10
|
return usePopoverContext().popoverId;
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { PopoverContext, usePopoverContext, usePopoverId };
|
|
14
13
|
|
|
15
14
|
//# sourceMappingURL=popover.context.js.map
|
|
@@ -4,7 +4,6 @@ import { Button } from "../button/button.js";
|
|
|
4
4
|
import "../button/index.js";
|
|
5
5
|
import { ButtonSlots, PopoverSlots, PopoverVariants } from "@hebium-ui/core";
|
|
6
6
|
import { ElementType, ReactElement, ReactNode } from "react";
|
|
7
|
-
//#region src/components/popover/popover.d.ts
|
|
8
7
|
export interface PopoverProps {
|
|
9
8
|
/**
|
|
10
9
|
* The id of the popover content element.
|
|
@@ -13,8 +12,8 @@ export interface PopoverProps {
|
|
|
13
12
|
children?: ReactNode | undefined;
|
|
14
13
|
}
|
|
15
14
|
declare function PopoverRoot(rawProps: PopoverProps): ReactElement;
|
|
16
|
-
export type PopoverTriggerProps<E extends ElementType = typeof Button
|
|
17
|
-
declare function Trigger<E extends ElementType = typeof Button
|
|
15
|
+
export type PopoverTriggerProps<E extends ElementType = typeof Button<"button">> = HuiPolymorphicProps<E, {}, ButtonSlots>;
|
|
16
|
+
declare function Trigger<E extends ElementType = typeof Button<"button">>(rawProps: PopoverTriggerProps<E>): ReactNode;
|
|
18
17
|
interface PopoverContentOwnProps {
|
|
19
18
|
/**
|
|
20
19
|
* The preferred anchor position of the popover.
|
|
@@ -48,6 +47,4 @@ export declare const Popover: typeof PopoverRoot & {
|
|
|
48
47
|
Trigger: typeof Trigger;
|
|
49
48
|
Content: typeof Content;
|
|
50
49
|
};
|
|
51
|
-
|
|
52
|
-
export {};
|
|
53
|
-
//# sourceMappingURL=popover.d.ts.map
|
|
50
|
+
export {};
|