Legacy (shadcn-uikit)Components
Switch
A toggle control that switches between on and off states.
Usage
import { Switch } from '@acronis-platform/shadcn-uikit';Basic
A simple on/off switch.
View sourceHide source
import { Switch } from '@acronis-platform/shadcn-uikit/react';
export function SwitchBasic() {
return <Switch />;
}
With Label
Switch paired with a descriptive label.
View sourceHide source
import { Switch, Label } from '@acronis-platform/shadcn-uikit/react';
export function SwitchWithLabel() {
return (
<div className="flex items-center space-x-2">
<Switch id="airplane-mode" />
<Label htmlFor="airplane-mode">Airplane Mode</Label>
</div>
);
}
Controlled
Switch with externally managed state.
Status: Disabled
View sourceHide source
import * as React from 'react';
import { Switch, Label } from '@acronis-platform/shadcn-uikit/react';
export function SwitchControlled() {
const [enabled, setEnabled] = React.useState(false);
return (
<div className="space-y-4">
<div className="flex items-center space-x-2">
<Switch id="feature" checked={enabled} onCheckedChange={setEnabled} />
<Label htmlFor="feature">Enable Feature</Label>
</div>
<p className="text-sm text-muted-foreground">
Status: {enabled ? 'Enabled' : 'Disabled'}
</p>
</div>
);
}
Form
Switch integrated within a form.
Notification Preferences
Receive push notifications on your device.
Receive emails about new products and features.
Get notified when someone follows you.
View sourceHide source
import * as React from 'react';
import { Switch, Label } from '@acronis-platform/shadcn-uikit/react';
export function SwitchForm() {
const [notifications, setNotifications] = React.useState(true);
const [marketing, setMarketing] = React.useState(false);
const [social, setSocial] = React.useState(true);
return (
<div className="max-w-md space-y-6 rounded-lg border p-6">
<div>
<h4 className="mb-4 font-semibold">Notification Preferences</h4>
<div className="space-y-4">
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="notifications">Push Notifications</Label>
<p className="text-sm text-muted-foreground">
Receive push notifications on your device.
</p>
</div>
<Switch
id="notifications"
checked={notifications}
onCheckedChange={setNotifications}
/>
</div>
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="marketing">Marketing Emails</Label>
<p className="text-sm text-muted-foreground">
Receive emails about new products and features.
</p>
</div>
<Switch
id="marketing"
checked={marketing}
onCheckedChange={setMarketing}
/>
</div>
<div className="flex items-center justify-between">
<div className="space-y-0.5">
<Label htmlFor="social">Social Updates</Label>
<p className="text-sm text-muted-foreground">
Get notified when someone follows you.
</p>
</div>
<Switch id="social" checked={social} onCheckedChange={setSocial} />
</div>
</div>
</div>
</div>
);
}
API Reference
The Switch wraps the Base UI Switch primitive and extends React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>. It accepts checked, defaultChecked, onCheckedChange, and disabled props.