import { type Accessor, type JSX, createContext, useContext } from "solid-js"; import type { ListState } from "../list"; import type { CollectionNode } from "../primitives"; import type { FocusStrategy, KeyboardDelegate } from "../selection"; import type { ComboboxTriggerMode } from "./types"; export interface ComboboxDataSet { "data-expanded": string | undefined; "data-closed": string | undefined; } export interface ComboboxContextValue { dataset: Accessor; isOpen: Accessor; isDisabled: Accessor; isMultiple: Accessor; isVirtualized: Accessor; isModal: Accessor; preventScroll: Accessor; isInputFocused: Accessor; allowsEmptyCollection: Accessor; shouldFocusWrap: Accessor; removeOnBackspace: Accessor; selectedOptions: Accessor; contentPresent: Accessor; autoFocus: Accessor; activeDescendant: Accessor; inputValue: Accessor; triggerMode: Accessor; controlRef: Accessor; inputRef: Accessor; triggerRef: Accessor; contentRef: Accessor; listboxId: Accessor; triggerAriaLabel: Accessor; listboxAriaLabel: Accessor; listState: Accessor; keyboardDelegate: Accessor; resetInputValue: (selectedKeys: Set) => void; setIsInputFocused: (isFocused: boolean) => void; setInputValue: (value: string) => void; setControlRef: (el: HTMLElement) => void; setInputRef: (el: HTMLInputElement) => void; setTriggerRef: (el: HTMLElement) => void; setContentRef: (el: HTMLElement) => void; setListboxRef: (el: HTMLElement) => void; open: ( focusStrategy: FocusStrategy | boolean, triggerMode?: ComboboxTriggerMode, ) => void; close: () => void; toggle: ( focusStrategy: FocusStrategy | boolean, triggerMode?: ComboboxTriggerMode, ) => void; placeholder: Accessor; renderItem: (item: CollectionNode) => JSX.Element; renderSection: (section: CollectionNode) => JSX.Element; removeOptionFromSelection: (option: any) => void; onInputKeyDown: JSX.EventHandlerUnion; generateId: (part: string) => string; registerListboxId: (id: string) => () => void; } export const ComboboxContext = createContext(); export function useComboboxContext() { const context = useContext(ComboboxContext); if (context === undefined) { throw new Error( "[kobalte]: `useComboboxContext` must be used within a `Combobox` component", ); } return context; }