ImageSwitch
A boolean control that displays one of two images based on state, perfect for on/off switches and buttons with custom bitmap graphics.
ImageSwitch is a boolean control that displays one of two images based on the boolean value. It shares the same layout, parameter model, interaction, and accessibility as other controls (vector, raster, and control primitives); see the Raster introduction.
The image displayed is determined by the boolean value:
false(normalized 0.0) displaysimageHrefFalsetrue(normalized 1.0) displaysimageHrefTrue
Note:
No Theming Support: This component does NOT support themable props (color, roundness, thickness) as visuals are entirely determined by the image content.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
value | boolean | — | Yes | Current value of the control |
onChange | (event: AudioControlEvent<boolean>) => void | — | No | Handler for value changes |
latch | boolean | false | No | Whether the button operates in latch (toggle) mode or momentary mode |
label | string | — | No | Label displayed below the component |
frameWidth | number | — | Yes | Width of the viewBox (determines viewBox width) |
frameHeight | number | — | Yes | Height of the viewBox (determines viewBox height) |
imageHrefFalse | string | — | Yes | URL to the image for false/off state |
imageHrefTrue | string | — | Yes | URL to the image for true/on state |
adaptiveSize | boolean | false | No | Whether the component stretches to fill its container |
size | "xsmall" | "small" | "normal" | "large" | "xlarge" | normal | No | Size of the component |
parameter | BooleanParameter | — | No | Audio Parameter definition (Model). If provided, overrides label/latch from ad-hoc props |
Basic Usage
ImageSwitch requires two image URLs (one for off state, one for on state) and frame dimensions:
Modes of Operation
Latch Mode (Toggle)
In latch mode, the button toggles between pressed and released states:
Momentary Mode
In momentary mode, the button is only active while being pressed:
Image Selection
The component displays different images based on the boolean value:
Parameter Model
Use a parameter model for integration with audio parameter systems. The following example uses ad-hoc props; with the full library you would use createBooleanParameter and the parameter prop:
Adaptive Sizing
The ImageSwitch component supports both fixed sizes and adaptive sizing. By default, the size of the component is driven by the Size System and their size attribute:
Adaptive sizing allows the component to adapt to the size of its parent container, adjusting its dimensions intelligently without causing distortion (scaleToFit display mode). The fill display mode makes the component fill the entire container, potentially distorting it.
Common Use Cases
Favorite/Star Button
Power Switch
Momentary Record Button
Image Requirements
- Format: Any image format supported by browsers (PNG, JPG, SVG, etc.)
- Dimensions: The
frameWidthandframeHeightprops determine the viewBox dimensions - Aspect Ratio: Images will be scaled to fit the viewBox while preserving aspect ratio
- States: Provide two separate images for off and on states
Image Selection Logic
The component selects images based on the boolean value:
value === false→ DisplaysimageHrefFalsevalue === true→ DisplaysimageHrefTrue
The selection is immediate and does not animate between states.
Next Steps
- Explore ImageKnob for continuous rotary controls
- Learn about ImageRotarySwitch for discrete rotary controls
- Check out the playground for interactive examples