import { useState } from "react";
import { Switch } from "@cloudflare/kumo";
export function SwitchBasicDemo() {
const [checked, setChecked] = useState(false);
return (
<Switch label="Switch" checked={checked} onCheckedChange={setChecked} />
);
} Installation
Barrel
import { Switch } from "@cloudflare/kumo";Granular
import { Switch } from "@cloudflare/kumo/components/switch"; Usage
import { Switch } from "@cloudflare/kumo";
import { useState } from "react";
export default function Example() {
const [checked, setChecked] = useState(false);
return (
<Switch checked={checked} onCheckedChange={(val) => setChecked(val)} />
);
} Examples
Off State
import { Switch } from "@cloudflare/kumo";
export function SwitchOffDemo() {
return <Switch label="Switch" checked={false} onCheckedChange={() => {}} />;
} On State
import { Switch } from "@cloudflare/kumo";
export function SwitchOnDemo() {
return <Switch label="Switch" checked={true} onCheckedChange={() => {}} />;
} Disabled
import { Switch } from "@cloudflare/kumo";
export function SwitchDisabledDemo() {
return <Switch label="Disabled" checked={false} disabled />;
} Variants
The Switch supports two variants: default (blue when on) and
neutral (monochrome). Both use a squircle shape.
import { Switch } from "@cloudflare/kumo";
/** All variants comparison — 2×2 grid showing off/on for default and neutral */
export function SwitchVariantsDemo() {
return (
<div className="grid grid-cols-2 gap-x-8 gap-y-4">
<Switch
label="Default off"
checked={false}
onCheckedChange={() => {}}
/>
<Switch
label="Default on"
checked={true}
onCheckedChange={() => {}}
/>
<Switch
label="Neutral off"
variant="neutral"
checked={false}
onCheckedChange={() => {}}
/>
<Switch
label="Neutral on"
variant="neutral"
checked={true}
onCheckedChange={() => {}}
/>
</div>
);
} Neutral Variant
The neutral variant uses monochrome colors and a squircle shape, ideal for subtle, less prominent toggles.
import { useState } from "react";
import { Switch } from "@cloudflare/kumo";
/** Neutral variant - monochrome switch for subtle, less prominent toggles */
export function SwitchNeutralDemo() {
const [checked, setChecked] = useState(false);
return (
<Switch
label="Neutral switch"
variant="neutral"
checked={checked}
onCheckedChange={setChecked}
/>
);
} Neutral States
import { Switch } from "@cloudflare/kumo";
/** Neutral variant in different states */
export function SwitchNeutralStatesDemo() {
return (
<div className="flex flex-col gap-4">
<Switch
label="Neutral off"
variant="neutral"
checked={false}
onCheckedChange={() => {}}
/>
<Switch
label="Neutral on"
variant="neutral"
checked={true}
onCheckedChange={() => {}}
/>
<Switch
label="Neutral disabled"
variant="neutral"
checked={false}
disabled
/>
</div>
);
} Sizes
Three sizes available: sm, base (default), and lg.
import { Switch } from "@cloudflare/kumo";
/** All sizes comparison */
export function SwitchSizesDemo() {
return (
<div className="flex flex-col gap-4">
<Switch
label="Small"
size="sm"
checked={true}
onCheckedChange={() => {}}
/>
<Switch
label="Base (default)"
size="base"
checked={true}
onCheckedChange={() => {}}
/>
<Switch
label="Large"
size="lg"
checked={true}
onCheckedChange={() => {}}
/>
</div>
);
} API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "neutral" | "default" | Visual variant: "default" (pill, brand color) or "neutral" (squircle, monochrome) |
| label | ReactNode | - | Label content for the switch (Field wrapper is built-in) - can be a string or any React node. Optional when used standalone for visual-only purposes. |
| labelTooltip | ReactNode | - | Tooltip content to display next to the label via an info icon |
| required | boolean | - | Whether the switch is required. When explicitly false, shows "(optional)" text after the label. |
| controlFirst | boolean | - | When true (default), switch appears before label. When false, label appears before switch. |
| size | "sm" | "base" | "lg" | "base" | - |
| checked | boolean | - | - |
| disabled | boolean | - | - |
| transitioning | boolean | - | - |
| name | string | - | - |
| type | "submit" | "reset" | "button" | - | - |
| value | string | string[] | number | - | - |
| className | string | - | - |
| id | string | - | - |
| lang | string | - | - |
| title | string | - | - |
| onClick* | (event: React.MouseEvent) => void | - | Callback when switch is clicked |