Button

A button component for audio applications supporting both toggle (latch) and momentary modes with proper event handling.

The Button component provides a customizable button for audio applications. It shares the same layout, parameter model, interaction, and accessibility as other vector components; see the Vector introduction.

  • Two operation modes: Latch (toggle) and momentary
  • Full theming support: color, roundness customization
  • Drag interactions: Proper handling of global mouse events to ensure reliable release behavior, and allow easy implementations of, for example, step sequencers and pads

Props

NameTypeDefaultRequiredDescription
valuebooleanYesCurrent value of the button (true = pressed/active, false = released/inactive)
onChange(event: AudioControlEvent<boolean>) => voidNoHandler for value changes
latchbooleanfalseNoWhether the button should latch (toggle between states) or momentary (only active while pressed). Ad-hoc mode only, ignored if parameter provided.
labelstringNoLabel displayed below the component
colorstringNoComponent primary color - any valid CSS color value
roundnessnumberNoRoundness for component corners (normalized 0.0-1.0)
adaptiveSizebooleanfalseNoWhether the component stretches to fill its container
size"xsmall" | "small" | "normal" | "large" | "xlarge"normalNoSize of the component
displayMode"scaleToFit" | "fill"scaleToFitNoLayout mode for the control
labelMode"none" | "hidden" | "visible"visibleNoVisibility of the label row
labelPosition"above" | "below"belowNoVertical position of the label relative to the control
labelAlign"start" | "center" | "end"centerNoHorizontal alignment of the label text
labelOverflow"ellipsis" | "abbreviate" | "auto"autoNoHow to handle label text overflow
labelHeightUnitsnumberNoLabel height in the same units as SVG viewBox height
parameterBooleanParameterNoAudio Parameter definition (Model). If provided, overrides label/latch from ad-hoc props
paramIdstringNoIdentifier for the parameter this control represents
midiResolutionMidiResolution7NoMIDI resolution in bits (ad-hoc mode, ignored if parameter provided)
onClickReact.MouseEventHandlerNoClick event handler
onMouseDownReact.MouseEventHandlerNoMouse down event handler
onMouseUpReact.MouseEventHandlerNoMouse up event handler
onMouseEnterReact.MouseEventHandlerNoMouse enter event handler
onMouseLeaveReact.MouseEventHandlerNoMouse leave event handler
classNamestringNoAdditional CSS classes
styleReact.CSSPropertiesNoAdditional inline styles

Basic Usage

The Button component requires a value (boolean) and onChange handler. The button operates in two modes: latch (toggle) or momentary.

Latch Mode (Toggle)

In latch mode, the button toggles between pressed and released states:

LatchButton.tsx

Momentary Mode

In momentary mode, the button is only active while being pressed:

MomentaryButton.tsx

Modes of Operation

The Button component supports two modes of operation:

Ad-Hoc Mode (Props Only)

In ad-hoc mode, you provide individual props (label, latch, etc.) and the component creates the parameter model internally:

AdHocButton.tsx

Strict Mode (Parameter Only)

In strict mode, you provide a full parameter model via the parameter prop. The following example uses ad-hoc props; with the full library you would use createBooleanParameter and the parameter prop:

StrictModeButton.tsx

Theming

Vector components share common theming features; see Theming Features in the Vector introduction for an overview. The Button component supports theming through the color and roundness props:

Color Customization

ButtonColor.tsx

Roundness

Control the roundness of the button corners:

ButtonRoundness.tsx

Adaptive Sizing

The Button 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:

ButtonSizing.tsx

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.

ButtonAdaptiveSize.tsx

Label Configuration

Control how the label is displayed:

Label Position

LabelPosition.tsx

Label Alignment

LabelAlignment.tsx

Label Visibility

LabelVisibility.tsx

Event Handling

The Button component provides standard mouse event handlers:

ButtonEvents.tsx

Global Mouse Event Handling

The Button component handles global mouse events for momentary buttons to ensure reliable release behavior. This means that even if you drag the mouse outside the button before releasing, the button will still properly detect the release event.

This is particularly important for momentary buttons used in audio applications where precise timing is critical.

Common Patterns

Power Button

A typical power toggle button:

PowerButton.tsx

Record Button

A momentary record button:

RecordButton.tsx

Button Group

Multiple buttons in a group:

ButtonGroup.tsx

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:

ButtonParameterModel.tsx

Common Use Cases

Power Switch

PowerSwitch.tsx

Record Button

RecordButton.tsx

Effect Bypass

EffectBypass.tsx

Next Steps