UNPKG

@chakra-ui/react

Version:

Responsive and accessible React UI components built with React and Emotion

67 lines (66 loc) • 2.69 kB
import type { ListCollection } from "@ark-ui/react/collection"; import { type Combobox as ArkCombobox, type UseComboboxReturn } from "@ark-ui/react/combobox"; import type { CommandItem, CommandSelectionDetails } from "./command"; import type { UseCommandCollectionReturn } from "./use-command-collection"; declare const comboboxPropKeys: readonly ["defaultHighlightedValue", "defaultInputValue", "highlightedValue", "id", "ids", "inputValue", "navigate", "onHighlightChange", "onInputValueChange", "onSelect", "scrollToIndexFn"]; type ComboboxOnlyProps<T extends CommandItem> = Pick<ArkCombobox.RootBaseProps<T>, (typeof comboboxPropKeys)[number]>; /** * What `Command.Root` reads from the `command` prop. */ export interface CommandSource<T extends CommandItem = CommandItem> extends UseCommandCollectionReturn<T> { } export interface UseCommandProps<T extends CommandItem = CommandItem> extends ComboboxOnlyProps<T> { /** * The items to show. Not needed when `command` is passed. */ collection?: ListCollection<T> | undefined; /** * The value of `useCommandCollection`. */ command?: CommandSource<T> | undefined; /** * Whether results are loading. Defaults to `command.loading`. */ loading?: boolean | undefined; /** * Whether selecting an item calls `onClose`. * @default true */ closeOnSelect?: boolean | undefined; /** * Called when a selection should close the command. */ onClose?: VoidFunction | undefined; } type CommandModifierKeys = CommandSelectionDetails["modifiers"]; export interface CommandSelectItemOptions { /** * The modifier keys of the triggering event. Any of them keeps the command * open. */ modifiers?: CommandModifierKeys | undefined; } export interface UseCommandReturn<T extends CommandItem = CommandItem> { /** * Whether results are loading. */ loading: boolean | undefined; /** * The value of `useCommandCollection`, if any. */ command: CommandSource<T> | undefined; /** * The underlying combobox API, e.g. `highlightedValue` and `focus`. */ combobox: UseComboboxReturn<T>; /** * Selects an item as if the user picked it. */ selectItem: (item: T, options?: CommandSelectItemOptions) => void; } export declare function useCommand<T extends CommandItem = CommandItem>(props: UseCommandProps<T>): UseCommandReturn<T>; /** * Splits `useCommand` props from the ones for the root element. */ export declare const splitCommandProps: <Props extends Partial<UseCommandProps<any>>>(props: Props) => [UseCommandProps<any>, Omit<Props, keyof UseCommandProps<any>>]; export {};