runway

Runway

Toggle

A simple toggle switch component



The Toggle component is a simple switch that can be toggled on or off. It is commonly used to enable or disable a feature or setting.

Use showIcon prop to display an icon inside the toggle switch.



Usage

javascript

1import Toggle from "@/components/atoms/Toggle";
2
3export default function Example() {
4    const [isToggled, setIsToggled] = useState(false);
5
6    return (
7        <Toggle
8            checked={isToggled}
9            onChange={() => setIsToggled(!isToggled)}
10        />
11    );
12}



Props

The Toggle component accepts the following props:

NameTypeDefaultDescription
labelstring""The label to display next to the toggle switch.
labelPosition"left" | "right""left"The position of the label relative to the toggle switch.
colorstring"primary"Color used for the toggle switch (see tailwind.config).
inactiveColorstring"gray"Inactive color used for the toggle switch (see tailwind.config).
variant"solid" | "soft""solid"The variant of the toggle switch.
borderRadiusstring"full"Tailwind border-radius class (e.g. "none", "sm", "md", etc.).
showIconbooleanfalseIf true, an icon will be displayed inside the toggle switch.
disabledbooleanfalseIf true, the toggle switch will be disabled.
checkedbooleanfalseIf true, the toggle switch will be in the "on" position.
onChangefunction-Callback function called when the toggle switch is toggled.
classNamestring""Additional Tailwind classes for the container.
...propsobject-Any other valid <input> attributes (e.g. name, id, etc.).

The onChange prop is required to handle the toggle switch change event.


Examples

Basic Toggle

Toggle with Label

Toggle with Icon

Disabled Toggle

Customized Toggle