UNPKG

instantsearch-ui-components

Version:

Common UI components for InstantSearch.

65 lines (64 loc) 2.3 kB
import type { ComponentProps, MutableRef } from '../../types'; type BaseHit = Record<string, unknown>; export type AutocompleteIndexConfig<TItem extends BaseHit> = { indexName: string; getQuery?: (item: TItem) => string; getURL?: (item: TItem) => string; onSelect?: (params: { item: TItem; query: string; setQuery: (query: string) => void; url?: string; }) => void; }; type GetInputProps = () => ComponentProps<'input'>; type ValidAriaRole = 'combobox' | 'row' | 'grid'; type GetItemProps = (item: { __indexName: string; } & Record<string, unknown>, index: number) => { id?: string; role?: ValidAriaRole; 'aria-selected'?: boolean; } & { onSelect: () => void; onApply: () => void; }; type GetPanelProps = () => { id?: string; hidden?: boolean; role?: ValidAriaRole; 'aria-labelledby'?: string; }; type GetRootProps = () => { ref?: MutableRef<HTMLDivElement | null>; }; type CreateAutocompletePropGettersParams = { useEffect: (effect: () => void, inputs?: readonly unknown[]) => void; useId: () => string; useMemo: <TType>(factory: () => TType, inputs: readonly unknown[]) => TType; useRef: <TType>(initialValue: TType | null) => { current: TType | null; }; useState: <TType>(initialState: TType) => [TType, (newState: TType) => unknown]; }; export type UsePropGetters<TItem extends BaseHit> = (params: { indices: Array<{ indexName: string; indexId: string; hits: Array<{ [key: string]: unknown; }>; }>; indicesConfig: Array<AutocompleteIndexConfig<TItem>>; onRefine: (query: string) => void; onSelect: NonNullable<AutocompleteIndexConfig<TItem>['onSelect']>; onApply: (query: string) => void; placeholder?: string; }) => { getInputProps: GetInputProps; getItemProps: GetItemProps; getPanelProps: GetPanelProps; getRootProps: GetRootProps; }; export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, onApply, placeholder, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>; export {};