"use client" import React from 'react' import { ToggleGroup, ToggleGroupItem } from '../ui' import { GridViewIcon, TableViewIcon } from '../icons' import { cn } from '../../utils/cn' type ViewMode = 'grid' | 'table' interface ViewToggleProps { /** * Current selected view mode */ value: ViewMode /** * Callback fired when view mode changes */ onValueChange: (value: ViewMode) => void /** * Whether the toggle is disabled */ disabled?: boolean /** * Additional CSS classes for the toggle group */ className?: string /** * Size of the toggle buttons */ size?: 'default' | 'sm' | 'lg' /** * Custom ARIA label for accessibility */ 'aria-label'?: string } /** * ViewToggle - A 2-state button component for switching between grid and table views * * Built on top of Radix UI ToggleGroup for accessibility and proper keyboard navigation. * Uses ODS design tokens for consistent theming across platforms. * * @example * ```tsx * const [viewMode, setViewMode] = useState<'grid' | 'table'>('table') * * * ``` */ export function ViewToggle({ value, onValueChange, disabled = false, className, size = 'default', 'aria-label': ariaLabel = 'Switch between grid and table view', }: ViewToggleProps) { return ( { // Only update if we have a valid value (user clicked a different option) if (newValue && newValue !== value) { onValueChange(newValue) } }} className={cn( "flex bg-ods-card border border-ods-border rounded-[6px] p-1", className )} disabled={disabled} aria-label={ariaLabel} > ) } // Type exports for consumers export type { ViewMode, ViewToggleProps }