Toggle Component

Axiom01's toggle component provides a visually distinct and accessible switch for binary choices (on/off, true/false). It's built on native HTML checkbox inputs, ensuring robust functionality and accessibility.

Live Example

Basic Toggle

Checked Toggle

Disabled Toggle

Toggle with Icon

HTML Structure

The toggle component uses a hidden checkbox input and a styled label to create the switch appearance.

<div class="toggle-switch">
			<input type="checkbox" id="toggle-basic">
			<label for="toggle-basic">Enable Feature</label>
	</div>

Styling

The .toggle-switch container wraps the native checkbox and its label. The checkbox itself is visually hidden, and the label is styled to resemble a switch.

JavaScript Integration

The toggle component is primarily CSS-driven. JavaScript is generally not required for basic functionality, as the native checkbox handles state changes. However, you might use JavaScript to:

Accessibility

The toggle component is built with accessibility in mind:

Customization

Customize the appearance using Axiom01's CSS variables for colors (e.g., --a-color-primary for the active state, --a-color-outline for the track), spacing, and animation speed. You can adjust the size, shape, and transition of the toggle switch to match your theme.