import { ID } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { SelectionContext, SelectionContextOptions, SelectionOptions, SelectionTicket, SelectionTicketInput } from "../createSelection/index.mjs"; import { Ref } from "vue"; //#region src/composables/createSingle/index.d.ts /** * Input type for single selection tickets. * Extend this interface to add custom properties. */ interface SingleTicketInput extends SelectionTicketInput {} /** * Output type for single selection tickets. * Includes all input properties plus selection methods. */ type SingleTicket = SelectionTicket; /** * Context returned by createSingle. * * @template Z The input ticket type. * @template E The output ticket type. */ interface SingleContext = SingleTicket> extends Omit, 'register' | 'onboard'> { selectedId: Readonly>; selectedIndex: Readonly>; selectedItem: Readonly>; selectedValue: Readonly>; /** Register a new ticket (accepts input type, returns output type) */ register: (ticket?: Partial) => E; /** Onboard multiple tickets at once */ onboard: (registrations: Partial[]) => E[]; } interface SingleOptions extends SelectionOptions {} interface SingleContextOptions extends SelectionContextOptions {} /** * Creates a new single selection instance that enforces only one selected item at a time. * * Extends `createSelection` by automatically clearing previous selections when a new item is selected. * Adds computed singular properties: `selectedId`, `selectedItem`, `selectedIndex`, `selectedValue`. * * @param options The options for the single selection instance. * @template Z The input ticket type - what users provide to register(). * @template E The output ticket type - what users receive from get(). * @template R The context type. * @returns A new single selection instance with single-selection enforcement. * * @remarks * **Key Differences from `createSelection`:** * - Automatically clears `selectedIds` before selecting a new item (enforces single selection) * - Provides singular computed properties instead of plural sets * - Perfect for tabs, radio buttons, theme selectors, and other single-choice UI components * * **Computed Properties:** * - `selectedId`: The ID of the selected item (undefined if none selected) * - `selectedItem`: The selected ticket object (undefined if none selected) * - `selectedIndex`: The index of the selected item (-1 if none selected) * - `selectedValue`: The value of the selected item (undefined if none selected) * * **Inheritance Chain:** * `createRegistry` → `createSelection` → `createSingle` → `createStep` * * @see https://0.vuetifyjs.com/composables/selection/create-single * * @example * ```ts * import { createSingle } from '@vuetify/v0' * * const tabs = createSingle({ mandatory: true }) * * tabs.onboard([ * { id: 'home', value: 'Home' }, * { id: 'about', value: 'About' }, * { id: 'contact', value: 'Contact' }, * ]) * * tabs.first() // Select first tab * * console.log(tabs.selectedId.value) // 'home' * console.log(tabs.selectedIndex.value) // 0 * * tabs.select('about') // Switch to about tab * console.log(tabs.selectedId.value) // 'about' * console.log(tabs.selectedIds.size) // 1 (always enforces single selection) * ``` * * @example * ```ts * // With custom ticket type * interface TabTicket extends SingleTicketInput { * label: string * icon?: string * } * * const tabs = createSingle() * tabs.register({ label: 'Home', icon: 'mdi-home' }) * ``` */ declare function createSingle = SingleTicket, R extends SingleContext = SingleContext>(_options?: SingleOptions): R; /** * Creates a new single selection context. * * @param options The options for the single selection context. * @template Z The input ticket type. * @template E The output ticket type. * @template R The context type. * @returns A new single selection context. * * @see https://0.vuetifyjs.com/composables/selection/create-single * * @example * ```ts * import { createSingleContext } from '@vuetify/v0' * * // With default namespace 'v0:single' * export const [useSingle, provideSingle, context] = createSingleContext() * * // In a parent component: * provideSingle() * * // In a child component: * const single = useSingle() * single.select('tab-1') * ``` */ declare function createSingleContext = SingleTicket, R extends SingleContext = SingleContext>(_options?: SingleContextOptions): ContextTrinity; /** * Returns the current single selection instance. * * @param namespace The namespace for the single selection context. Defaults to `'v0:single'`. * @template Z The input ticket type. * @template E The output ticket type. * @template R The context type. * @returns The current single selection instance. * * @see https://0.vuetifyjs.com/composables/selection/create-single * * @example * ```vue * * * * ``` */ declare function useSingle = SingleTicket, R extends SingleContext = SingleContext>(namespace?: string): R; //#endregion export { SingleContext, SingleContextOptions, SingleOptions, SingleTicket, SingleTicketInput, createSingle, createSingleContext, useSingle };