Components
- 手风琴
- 提示
- 警告对话框
- 宽高比
- 头像
- 徽章
- 面包屑导航
- 按钮
- 按钮组
- 日历 Calendar
- 卡片
- Carousel
- 图表 Chart
- 复选框
- 折叠面板
- 组合框
- 命令
- 上下文菜单
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 抽屉
- 下拉菜单
- Empty
- 字段
- 悬停卡片
- 输入
- 输入组
- 输入 OTP
- 项目
- Kbd
- 标签
- 菜单栏
- 原生选择框
- 导航菜单 Navigation Menu
- 分页
- 弹出框
- 进度 Progress
- 单选框组
- 可调整大小
- 滚动区域 Scroll Area
- 选择框
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏
- 滑块
- Sonner
- 加载指示器 Spinner
- 开关
- 表格
- 标签页 Tabs
- 文本域
- 吐司
- 切换按钮 Toggle
- 切换组
- 提示 Tooltip
- 排版
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 参考
请参阅 Radix Switch 文档。