UNPKG

1.64 kBPlain TextView Raw
1import { createComponent } from "reakit-system/createComponent";
2import { createHook } from "reakit-system/createHook";
3import { useWarning } from "reakit-warning";
4import { useCreateElement } from "reakit-system/useCreateElement";
5import { BoxOptions, BoxHTMLProps, useBox } from "../Box/Box";
6import { getMenuId } from "./__utils/getMenuId";
7import { unstable_ComboboxStateReturn } from "./ComboboxState";
8import { COMBOBOX_LIST_KEYS } from "./__keys";
9
10export 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
31export 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
44export type unstable_ComboboxListOptions = BoxOptions &
45 Pick<Partial<unstable_ComboboxStateReturn>, "menuRole"> &
46 Pick<unstable_ComboboxStateReturn, "baseId">;
47
48export type unstable_ComboboxListHTMLProps = BoxHTMLProps;
49
50export type unstable_ComboboxListProps = unstable_ComboboxListOptions &
51 unstable_ComboboxListHTMLProps;