import { MaybeRefOrGetter } from "vue"; //#region src/composables/useTypeahead/index.d.ts /** * Configuration for a typeahead lookup. * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * * const items = [{ title: 'Alabama' }, { title: 'Alaska' }] * * const lookup = useTypeahead(() => items, { * text: item => item.title, * duration: 1000, * }) * ``` */ interface TypeaheadOptions { /** * Text used for prefix matching. Read on every key. * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * * const items = [{ title: 'Alabama' }] * * useTypeahead(() => items, { * text: item => item.title, * }) * ``` */ text: (item: T) => string; /** * Inactivity window before the buffer clears, in milliseconds. * Accepts a plain number, ref, or getter — read fresh on each key. * * @default 1000 * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * import { shallowRef } from 'vue' * * const items = ['Alabama', 'Alaska'] * const duration = shallowRef(700) * * useTypeahead(() => items, { * text: item => item, * duration, * }) * ``` */ duration?: MaybeRefOrGetter; } /** * A matched item and its index in the list passed to `typeahead`. * * @example * ```ts * import type { TypeaheadMatch } from '@vuetify/v0' * * const match: TypeaheadMatch = { item: 'Alaska', index: 1 } * ``` */ interface TypeaheadMatch { /** The matched item. */ item: T; /** Index of `item` in the current list. */ index: number; } interface TypeaheadReturn { /** * Append `char` to the buffer and return the next prefix match. * Restarts the inactivity window on every call, hit or miss. * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * * const states = ['Alabama', 'Alaska', 'American Samoa'] * * const { typeahead } = useTypeahead(() => states, { * text: state => state, * }) * * const match = typeahead('a') * ``` */ typeahead: (char: string) => TypeaheadMatch | undefined; /** * Clear the buffer and stop the inactivity window. * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * * const states = ['Alabama', 'Alaska'] * * const { reset } = useTypeahead(() => states, { * text: state => state, * }) * * reset() * ``` */ reset: () => void; } /** * Match typed characters against a list. * * `items` is read on every key, in the order given. Matching is a * case-insensitive `startsWith` against `options.text`. Text is not trimmed. * Disabled items are not skipped — omit them from `items` to filter. * * @param items List to search, in match order. * @param options Text getter and inactivity window. * @returns `typeahead` and `reset`. * * @see https://0.vuetifyjs.com/composables/system/use-typeahead * * @example * ```ts * import { useTypeahead } from '@vuetify/v0' * import { shallowRef } from 'vue' * * const tickets = shallowRef([ * { label: 'Banana' }, * { label: 'Blueberry' }, * ]) * * const { typeahead, reset } = useTypeahead( * () => tickets.value, * { text: ticket => ticket.label, duration: 1000 }, * ) * * const match = typeahead('b') * reset() * ``` */ declare function useTypeahead(items: () => readonly T[], options: TypeaheadOptions): TypeaheadReturn; //#endregion export { TypeaheadMatch, TypeaheadOptions, TypeaheadReturn, useTypeahead };