// // Copyright 2026 DXOS.org // import { Switch as SwitchPrimitive } from '@ark-ui/react/switch'; import React, { type ReactNode, forwardRef } from 'react'; import { mx } from '@dxos/ui-theme'; import { type ThemedClassName } from '@dxos/ui-types'; import { recipes } from '../../recipes.ts'; import * as Fieldset from '../Fieldset/Fieldset.tsx'; import { useToolbarItem } from '../Toolbar/toolbar-context.ts'; export type SwitchProps = ThemedClassName> & { /** Visible label beside the track; without one pass `aria-label`. */ 'label'?: ReactNode; 'aria-label'?: string; /** Neither on nor off (e.g. several edited objects disagree): the track is dimmed until it is set. */ 'indeterminate'?: boolean; }; /** * Ark switch with an icon-tall track; the root is a block-tall row so it lines up with other controls. In a Toolbar its * input joins the roving focus. */ export const Switch = forwardRef( ({ classNames, label, 'aria-label': ariaLabel, indeterminate, disabled: disabledProp, ...props }, forwardedRef) => { const disabled = Fieldset.useFieldsetDisabled(disabledProp); const toolbarItem = useToolbarItem(disabled); return ( {label && {label}} {/* The zag machine implements the switch keyboard contract (Space toggles), so the role is earned (follow-up 21). */} ); }, ); Switch.displayName = 'Switch';