Skip to content

Switch

Class: FxSwitch · Tag: <fx-switch> · Mixins: Animatable

The <fx-switch> component is a premium, segmented multi-state selector featuring a fluid sliding thumb. It supports two or more custom states, optional icons, and both horizontal and vertical layouts for an elegant, tactile user experience.


Register the components by importing them in your entrypoint:

import '@salsafx/ui';

Interactive preview of the main variants:


When rendered with no states provided, <fx-switch> defaults to a standard binary On/Off toggle. Click the switch below to toggle it!

Active ID: off
<fx-switch active-id="off"></fx-switch>

Pass <fx-switch-state> child tags to create custom configurations. Click the state buttons below to toggle through active states — note how the highlighted thumb transitions smoothly across the switch track!

Active ID: medium
<fx-switch active-id="auto" theme="light">
<fx-switch-state
value="off"
label="Manual Off"
background-color="#ef4444"
></fx-switch-state>
<fx-switch-state
value="auto"
label="Auto Control"
background-color="#10b981"
></fx-switch-state>
<fx-switch-state
value="force"
label="Force Flush"
background-color="#f59e0b"
></fx-switch-state>
</fx-switch>

Set the optional icon attribute to a Font Awesome class string. Without icon, the segment shows only the label.

<fx-switch active-id="performance" state-width="105">
<fx-switch-state
value="eco"
label="Eco"
icon="fa-solid fa-leaf"
></fx-switch-state>
<fx-switch-state
value="standard"
label="Standard"
icon="fa-solid fa-sun"
></fx-switch-state>
<fx-switch-state
value="performance"
label="Performance"
icon="fa-solid fa-gauge-high"
></fx-switch-state>
<fx-switch-state
value="custom"
label="Custom"
icon="fa-solid fa-shield-halved"
></fx-switch-state>
</fx-switch>

PropertyAttributeTypeDefaultDescription
activeIdactive-idString""ID of the currently selected state.
orientationorientationString"horizontal"Orientation of the switch (“horizontal” or “vertical”).
themetheme"light" | "dark""dark"Color theme preset (“light” or “dark”).
foregroundColorforeground-colorString"#ffffff"Default active text and icon color.
backgroundColorbackground-colorString"#3b82f6"Default active sliding thumb background color.
stateWidthstate-widthNumber | String72Width of each state segment.
isAnimatedis-animatedBooleantrueEnables fluid, hardware-accelerated sliding transitions.
disableddisabledBooleanfalseDisables the control and prevents user interaction.
statesArray[]Array of state configurations.
PropertyAttributeTypeDefaultDescription
valuevalueString""Unique state identifier value.
labellabelString""State text label.
iconiconString""Optional Font Awesome icon class name.
foregroundColorforeground-colorString""Active state text and icon color override.
backgroundColorbackground-colorString""Active state thumb background color override.
disableddisabledBooleanfalseDisables only this state segment.

Icons are placed so that page-level stylesheets apply. With a states array, pass an icon-font class list or a .svg path on each item (e.g. icon: 'fa-solid fa-leaf').

NameDetailDescription
change{ id: String, state: Object }Emitted when a state is clicked. id contains the new active ID.
PropertyDefaultDescription
--fx-switch-track-color#ffffffBackground of the switch casing track.
--fx-switch-border-color#e5e7ebCasing outer boundary frame line.
--fx-switch-border-radius16pxOuter track corner radius.
--fx-switch-btn-border-radius12pxActive thumb corner radius.
--fx-switch-padding4pxPadding space between casing border and buttons.
--fx-switch-font-size0.8125remText size of the state labels.
--fx-switch-icon-size1.125remFont Awesome icon size.
--fx-switch-icon-gap6pxGap between icon and label.
--fx-switch-text-inactive#374151Color of inactive toggle buttons.
--fx-switch-divider-color#e5e7ebDivider between adjacent inactive segments.
--fx-switch-background-active#3b82f6Default sliding thumb background (if state overrides are absent).

classDiagram
    direction TB
    class FxElement
    class FxSwitch

    FxElement <|-- FxSwitch : Animatable

See also Architecture.