Components
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
安装
pnpm dlx shadcn@latest add switch
用法
import { Switch } from "@/components/ui/switch"<Switch />示例
描述
Focus is shared across devices, and turns off when you leave the app.
import {
Field,
FieldContent,选择卡片
卡片样式的选择,FieldLabel 包裹整个 Field,实现可点击的卡片模式。
import {
Field,
FieldContent,禁用
向 Switch 组件添加 disabled 属性以禁用开关。向 Field 组件添加 data-disabled 属性以便样式化。
import { Field, FieldLabel } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
无效
向 Switch 组件添加 aria-invalid 属性以指示无效状态。向 Field 组件添加 data-invalid 属性以便样式化。
You must accept the terms and conditions to continue.
import {
Field,
FieldContent,大小
使用 size 属性更改开关的大小。
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
API 参考
请参阅 Base UI Switch 文档。