githubEdit

Segmented Control

Last updated: 3.0.0 (04/07/2024)

The Segmented Control is an input component that allows users to select one option from a set of mutually exclusive options. It presents options as a row of buttons within a styled container.

Usage

import { SegmentedControl } from "@valence-ui/core";
import { useState } from "react";

function MyComponent() { 
    const [value, setValue] = useState("option1");

    return ( 
        <SegmentedControl
            value={value}
            setValue={setValue}
            options={["option1", "option2", "option3"]}
        />
    )
}

Custom labels

By default, the option value will be used as the label. To provide custom labels, use the object form:

Custom label components

Labels can also be React nodes, allowing for icons or other custom content:

Styling


Props

Extends GenericInputProps<string> and StyledFlexProps.

Property
Type
Description

options (required)

SegmentedControlOption[]

A list of options to supply for the content of this input.

onSelect

(value: SegmentedControlOption) => void

Callback to be called when an option is selected.

equalWidth

boolean

Whether every option should have an equal width. Defaults to true.

buttonProps

PrimitiveButtonProps

Optional props to pass to the child button components.

SegmentedControlOption

Can be either a string or an object:

Last updated