@mks2508/mks-ui
Components

Switch

Toggle switch with smooth animation for boolean settings.

Switch

A toggle switch component with smooth transition animation for boolean on/off settings.

Import

import { Switch } from '@mks2508/mks-ui/react';

Basic Usage

Basic Usage
.tsx
<Switch />
<Switch defaultChecked />

With Label

With Label
.tsx
<div className="flex items-center gap-2">
<Switch id="notifications" />
<Label htmlFor="notifications">Enable notifications</Label>
</div>

Controlled

const [enabled, setEnabled] = useState(false);

<Switch checked={enabled} onCheckedChange={setEnabled} />

Disabled

Disabled
.tsx
<Switch disabled />
<Switch disabled defaultChecked />

API Reference

PropTypeDefaultDescription
checkedbooleanControlled checked state
defaultCheckedbooleanfalseInitial state (uncontrolled)
onCheckedChange(checked: boolean) => voidChange handler
disabledbooleanfalseDisable interactions
classNamestringAdditional CSS classes