Skip to main content

Switch

A Switch widget is a user interface component that allows users to select one option from a set. Represented by a small switch, it can be checked or unchecked and generally has an associated text label.

src/main.tsx

import { WSwitch } from "@cedro/ui/switch.ui";
import { WContainer, WSpacer } from "@cedro/ui/container.ui";
import { createWidget } from "@cedro/ui/widget.builder";

export default createWidget(
<WContainer orientation="vertical">
<WSpacer />
<WContainer orientation="horizontal" fixedSize={45} padding={5}>
<WSpacer />
<WSwitch text="Switch One" checked />
<WSwitch text="Switch Two" />
<WSwitch text="Switch Three" />
<WSpacer />
</WContainer>
<WSpacer />
</WContainer>
);

Properties

The Switch widget inherits from ToggleButton class → Has all ToggleButton properties.

Constructor

ParameterTypeRequiredDescription
idstringyesThe id of the widget
textstringyesThe label of the widget
parentWidgetnoThe parent of the widget. Default is null
src/main.ts
import { Switch } from "@cedro/ui";

const switch: Switch = new Switch("my-switch", "option 1");

switch.setState(true);