Overview
HuxToggle
is a two-state button component commonly used for formatting controls (like bold, italic) or feature toggles. It supports both icon-only and icon-with-text configurations, with multiple variants and sizes.
Basic Usage

Icon-Only Toggle
Variants
HuxToggle supports four visual variants through theHuxButtonVariant
enum:
Primary Toggle

Secondary Toggle

Outline Toggle

Ghost Toggle

Sizes
Control toggle dimensions with three size options:Small Toggle
Compact size for tight spaces (32px height).
Medium Toggle (Default)
Default size for most use cases (40px height).
Large Toggle
Prominent size for important actions (48px height).
States
Disabled State

Custom Primary Color

API Reference
HuxToggle Properties
Property | Type | Default | Description |
---|---|---|---|
value | bool | required | The current toggle state (on/off) |
onChanged | ValueChanged<bool>? | null | Callback triggered when toggle state changes |
icon | IconData | required | The icon to display in the toggle |
label | String? | null | Optional text label to display next to the icon |
size | HuxToggleSize | medium | Size variant of the toggle |
variant | HuxButtonVariant | primary | Visual variant of the toggle |
isDisabled | bool | false | Whether the toggle is disabled |
primaryColor | Color? | null | Optional custom primary color |
HuxToggleSize Enum
HuxToggleSize.small
- 32px height, compact paddingHuxToggleSize.medium
- 40px height, standard paddingHuxToggleSize.large
- 48px height, generous padding
Accessibility
HuxToggle includes several accessibility features:Automatic Contrast
Text and icon colors are automatically calculated to ensure WCAG AA compliance (4.5:1 contrast ratio) against any background color.Semantic Roles
Toggles include proper semantic roles for screen readers.Focus States
Keyboard navigation support with visible focus indicators.Disabled States
Proper disabled state handling for assistive technologies.Best Practices
Choose the Right Variant
Choose the Right Variant
- Use Primary for important toggles that need emphasis
- Use Secondary for standard toggles in content areas
- Use Outline for toggles that need visual separation
- Use Ghost for subtle toggles in toolbars
Size Appropriately
Size Appropriately
- Use Large for important feature toggles
- Use Medium for most standard interactions
- Use Small for compact toolbars or formatting controls
Icon Selection
Icon Selection
- Choose clear, meaningful icons that represent the action
- Use standard icons (bold, italic) for formatting controls
- Add labels for actions that aren’t immediately clear
Theme Integration
Theme Integration
- Let toggles adapt to your app’s theme
- Use
primaryColor
only for specific emphasis - Maintain consistent styling within toggle groups