1 | import { createComponent } from "reakit-system/createComponent";
|
2 | import { createHook } from "reakit-system/createHook";
|
3 | import { useWarning } from "reakit-warning";
|
4 | import { useCreateElement } from "reakit-system/useCreateElement";
|
5 | import { BoxOptions, BoxHTMLProps, useBox } from "../Box/Box";
|
6 | import { getMenuId } from "./__utils/getMenuId";
|
7 | import { unstable_ComboboxStateReturn } from "./ComboboxState";
|
8 | import { COMBOBOX_LIST_KEYS } from "./__keys";
|
9 |
|
10 | export const unstable_useComboboxList = createHook<
|
11 | unstable_ComboboxListOptions,
|
12 | unstable_ComboboxListHTMLProps
|
13 | >({
|
14 | name: "ComboboxList",
|
15 | compose: useBox,
|
16 | keys: COMBOBOX_LIST_KEYS,
|
17 |
|
18 | useOptions({ menuRole = "listbox", ...options }) {
|
19 | return { menuRole, ...options };
|
20 | },
|
21 |
|
22 | useProps(options, htmlProps) {
|
23 | return {
|
24 | role: options.menuRole,
|
25 | id: getMenuId(options.baseId),
|
26 | ...htmlProps,
|
27 | };
|
28 | },
|
29 | });
|
30 |
|
31 | export const unstable_ComboboxList = createComponent({
|
32 | as: "div",
|
33 | useHook: unstable_useComboboxList,
|
34 | useCreateElement: (type, props, children) => {
|
35 | useWarning(
|
36 | !props["aria-label"] && !props["aria-labelledby"],
|
37 | "You should provide either `aria-label` or `aria-labelledby` props.",
|
38 | "See https://reakit.io/docs/combobox"
|
39 | );
|
40 | return useCreateElement(type, props, children);
|
41 | },
|
42 | });
|
43 |
|
44 | export type unstable_ComboboxListOptions = BoxOptions &
|
45 | Pick<Partial<unstable_ComboboxStateReturn>, "menuRole"> &
|
46 | Pick<unstable_ComboboxStateReturn, "baseId">;
|
47 |
|
48 | export type unstable_ComboboxListHTMLProps = BoxHTMLProps;
|
49 |
|
50 | export type unstable_ComboboxListProps = unstable_ComboboxListOptions &
|
51 | unstable_ComboboxListHTMLProps;
|