Components
@shadcn/react
@shadcn/helpers
Utilities
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,形成可点击的卡片模式。
Enable notifications
Receive notifications when focus mode is enabled or disabled.
import {
Field,
FieldContent,禁用#
向 Switch 组件添加 isDisabled 属性以禁用开关。向 Field 组件添加 data-disabled 属性以设置样式。
import { Field, FieldLabel } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
无效#
向 Switch 组件添加 data-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"
RTL#
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.
"use client"
import * as React from "react"API 参考#
请参阅 React Aria Switch 文档。