import type * as React from 'react'; import type { PrimitivePropsWithRef } from '../utils/primitive.cjs'; import type { SelectionChangeDetail, SelectionChangeReason } from '../utils/useSelection.cjs'; /** * One entry of {@link ToolbarProps.items}: a discriminated union narrowed with `'type' in item`, whose plain-button variant carries no `type`. */ export type ToolbarItem = { /** Text rendered inside the derived `ToolbarButton`. */ label: string; /** * Called when the derived button is activated. * @default undefined — no-op if omitted. */ onClick?: (() => void) | undefined; /** * Disables the button and takes it out of the roving-tabindex ring. * @default false */ disabled?: boolean | undefined; } | { /** Renders a `ToolbarLink` instead of a `ToolbarButton`. */ type: 'link'; /** Text rendered inside the derived `ToolbarLink`. */ label: string; /** Destination of the derived `ToolbarLink`. */ href: string; /** * Marks the link `aria-disabled` — an `` has no `disabled` attribute, * so it stays in the roving ring and announces as unavailable. * @default false */ disabled?: boolean | undefined; } | { /** Renders a `ToolbarSeparator` between groups of controls. */ type: 'separator'; } | { /** Renders a `ToolbarToggleGroup` of `ToolbarToggleItem`s. */ type: 'toggle-group'; /** * Whether at most one item may be pressed (`'single'`) or any number * (`'multiple'`), mapped to the `ToolbarToggleGroup` part's `type`. * @default 'single' */ mode?: 'single' | 'multiple' | undefined; /** * Pressed item's value(s), for controlled usage. * @default undefined — uncontrolled. */ value?: string | string[] | undefined; /** * Fires with the pressed value(s) — a bare string under `'single'`, the * whole array under `'multiple'`. * @default undefined — no-op if omitted. */ onValueChange?: ((value: string | string[]) => void) | undefined; /** * Disables every item in the group. * @default false */ disabled?: boolean | undefined; /** The group's toggle options. */ items: { /** Identifier tracked in the group's pressed value(s). */ value: string; /** Text rendered inside the derived `ToolbarToggleItem`. */ label: string; /** * Disables this option alone, on top of the group's own `disabled`. * @default false */ disabled?: boolean | undefined; }[]; }; /** Layout axis of a {@link Toolbar}, driving `aria-orientation` and the arrow keys used for roving-tabindex navigation. */ export type ToolbarOrientation = 'horizontal' | 'vertical'; /** @internal Shared state distributed from {@link Toolbar} to its parts via context. */ export interface ToolbarContextValue { orientation: ToolbarOrientation; currentTabStopId: string | null; setCurrentTabStopId: (id: string) => void; } /** Props for the {@link Toolbar} root. */ export interface ToolbarProps extends PrimitivePropsWithRef<'div'> { /** * The toolbar's controls, rendered into the derived anatomy. Ignored when * `children` is given, which switches to full manual composition. * @default undefined — an empty toolbar. */ items?: ToolbarItem[] | undefined; /** * Renders the *contents* of a derived control, in place of its label. The * control itself — its role, `data-*`, roving `tabIndex` and disabled state * — stays the library's. Not called for separators, which render no label. * @default undefined — the entry's `label` is rendered. */ renderItem?: ((item: ToolbarItem) => React.ReactNode) | undefined; /** * Layout axis, exposed as `aria-orientation`/`data-orientation` and used to * pick Arrow Left/Right vs. Arrow Up/Down for roving-tabindex navigation. * @default 'horizontal' */ orientation?: ToolbarOrientation | undefined; /** * Whether arrow-key navigation wraps from the last item back to the first * (and vice versa). * @default true */ loop?: boolean | undefined; } /** Props for {@link ToolbarButton}, a plain action button in the toolbar. */ export interface ToolbarButtonProps extends PrimitivePropsWithRef<'button'> { /** * Disables this button and removes it from the roving-tabindex ring. * @default false */ disabled?: boolean | undefined; } /** Props for {@link ToolbarLink}, a plain navigable link in the toolbar. */ export interface ToolbarLinkProps extends PrimitivePropsWithRef<'a'> { } /** Props for {@link ToolbarSeparator}, a visual divider between toolbar controls. */ export interface ToolbarSeparatorProps extends PrimitivePropsWithRef<'div'> { } /** Whether a {@link ToolbarToggleGroup} allows one pressed item (`'single'`) or several (`'multiple'`). */ export type ToolbarToggleGroupType = 'single' | 'multiple'; /** @internal Shared state distributed from {@link ToolbarToggleGroup} to its `ToolbarToggleItem`s via context. */ export interface ToolbarToggleGroupContextValue { type: ToolbarToggleGroupType; value: string[]; disabled: boolean; /** Commits one item: presses it, or unpresses it when the group's cardinality allows. */ onItemToggle: (value: string, reason?: SelectionChangeReason) => void; } /** Props for the {@link ToolbarToggleGroup} root; `type` picks single- or multiple-item selection. */ export interface ToolbarToggleGroupProps extends PrimitivePropsWithRef<'div'> { /** * Disables every `ToolbarToggleItem` in the group. * @default false */ disabled?: boolean | undefined; /** * Whether at most one item may be pressed at a time (`'single'`) or any number (`'multiple'`), deciding whether `value` takes a `string` or `string[]`. */ type: ToolbarToggleGroupType; /** * Pressed item's value(s), for controlled usage — a `string` or `string[]`; pair with `onValueChange`. * @default undefined — uncontrolled, tracks its own pressed items internally. */ value?: string | string[] | undefined; /** * Initially pressed item's value(s), for uncontrolled usage — the same bare * `string` or `string[]` shapes `value` accepts, under either cardinality. * @default undefined — starts with no item pressed. */ defaultValue?: string | string[] | undefined; /** * Fires whenever the pressed items change, carrying the whole selection as a `string[]` alongside `selectedValue`, `previousValue` and `reason`. * @default undefined — no-op if omitted. */ onValueChange?: ((detail: SelectionChangeDetail) => void) | undefined; } /** Props for a single {@link ToolbarToggleItem} within a `ToolbarToggleGroup`. */ export interface ToolbarToggleItemProps extends PrimitivePropsWithRef<'button'> { /** Unique identifier tracked in the group's pressed value(s). */ value: string; /** * Disables this item alone, on top of the group's `disabled` — OR-ed so * group-level disabled cannot be re-enabled from here. Reflected as * `data-disabled` in addition to `disabled`. * @default false */ disabled?: boolean | undefined; }