runway

Runway

Switcher

A component for toggling between options



The Switcher component is for for toggling between multiple options. It supports both horizontal and vertical layouts, customizable sizes, colors, shapes, and optional tooltips.



Usage

javascript

1import { useState } from "react";
2import Switch from "@/components/atoms/Switch";
3
4const [selected, setSelected] = useState("option1");
5
6<Switch
7    options={[
8        { value: "option1", name: "Option 1" },
9        { value: "option2", name: "Option 2" },
10        { value: "option3", name: "Option 3" }
11    ]}
12    selected={selected}
13    onChange={setSelected}
14/>



Props

PropTypeDefaultDescription
optionsarray-An array of options, [{ value: string, name: string, tooltip?: string, Icon?: ReactNode, image?: string }].
selectedstring-The currently selected value.
onChangefunction-Callback function that is called when the selected value changes.
colorstring"gray"The base color (use tailwind.config).
size"sm" | "md" | "lg""md"The size of the switch.
borderRadiusstring"md"The border radius of the switch (uses Tailwind border radius to shape component).
verticalbooleanfalseIf true, the switch will be displayed vertically.
animatebooleantrueIf true, the switch will animate with a sliding indicator.
hoverbooleantrueIf true, the switch will have a hover effect.
borderbooleanfalseIf true, the switch will have a border.
buttonBorderbooleanfalseIf true, the switch will have a border on the buttons.
buttonShadowbooleantrueIf true, the switch will have a shadow on the buttons.
tooltipPosition"top" | "right" | "bottom" | "left""top"The position of the tooltip (if tooltip is provided).
classNamestring""Additional Tailwind classes for the container.
buttonClassNamestring""Additional Tailwind classes for the buttons.
...propsobject-Any other valid <div> attributes (e.g. role, aria-*, etc.).

Use options to customize the switch with icons, images, and tooltips.




Examples

Basic Switch


Vertical Switch with Tooltips


Customized Switch