/** * AgnosticUI v2 Toggle - Canonical Implementation * * 🔒 IMMUTABLE CANONICAL VERSION 🔒 * * This file contains the canonical, upgrade-safe implementation of the Toggle component. * It should NEVER be modified directly by users or AI assistants. * * Version: 2.0.0-dev * Last Updated: 2025-09-24 * API Compatibility: 2.x * * Stability Guarantees: * - All public APIs remain backward compatible within major versions * - All ARIA attributes and accessibility features are preserved * - All CSS functional styling remains consistent * - Component behavior is identical across patch and minor updates * - Full WAI-ARIA Switch pattern compliance maintained * * For customization, use: * - Toggle.ts: Experimental/AI-modifiable version * - styled/: Production styling tiers * - experiments/: Experimental styling variations * - extensions/: AI-safe behavioral extensions */ import { LitElement, html, css } from 'lit'; import { property } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { createFormControlIds, buildAriaDescribedBy, isHorizontalLabel, type LabelPosition, } from '../../../shared/form-control-utils'; import { formControlStyles } from '../../../shared/form-control-styles'; import { FaceMixin, type ValidationMessages } from '../../../shared/face-mixin'; // Event types export interface ToggleChangeEventDetail { checked: boolean; name: string; value: string; } export type ToggleChangeEvent = CustomEvent; export interface ToggleProps { label?: string; labelPosition?: LabelPosition; labelHidden?: boolean; noLabel?: boolean; checked?: boolean; size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'; variant?: 'default' | 'success' | 'warning' | 'danger' | 'monochrome'; disabled?: boolean; readonly?: boolean; required?: boolean; invalid?: boolean; errorMessage?: string; helpText?: string; name?: string; value?: string; validationMessages?: ValidationMessages; // Event callbacks onClick?: (event: MouseEvent) => void; onToggleChange?: (event: ToggleChangeEvent) => void; } /** * AgToggle - Accessible binary toggle/switch component * * A semantic button element implementing the WAI-ARIA Switch pattern * for binary on/off state controls with comprehensive accessibility support. * * Features: * - WAI-ARIA Switch pattern compliance with role="switch" * - Semantic `; // Check if label should be in horizontal layout const isHorizontal = isHorizontalLabel(this.labelPosition); // Horizontal layout (start/end positions) if (isHorizontal) { return html`
${this.renderLabel()} ${toggleButton}
${helperText} ${errorText} `; } // Bottom position layout if (this.labelPosition === 'bottom') { return html` ${toggleButton} ${helperText} ${errorText} ${this.renderLabel()} `; } // Top position layout (default) return html` ${this.renderLabel()} ${toggleButton} ${helperText} ${errorText} `; } }