Duostrap Switch
基于 Base Switch 的 Duostrap 设计语言扩展开关组件,支持表单组合、RTL 与拖动。
Duostrap Switch 是一项设计语言扩展(design-language extension),借鉴经典立体渐变与内嵌阴影风格构建 Root / Thumb 结构,同时完整继承 Base Switch 的键盘交互、RTL 镜像与拖动语义。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-wrap items-center gap-6">
<div class="inline-flex items-center gap-2.5">
<proto-ui-duostrap-switch-root>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
<span class="sr-only">Airplane Mode</span>
</proto-ui-duostrap-switch-root>
<span class="text-sm font-medium">Airplane Mode</span>
</div>
<div class="inline-flex items-center gap-2.5">
<proto-ui-duostrap-switch-root default-checked>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
<span class="sr-only">Release alerts</span>
</proto-ui-duostrap-switch-root>
<span class="text-sm font-medium">Release alerts</span>
</div>
<div class="inline-flex items-center gap-2.5">
<proto-ui-duostrap-switch-root disabled>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
<span class="sr-only">Archived alerts</span>
</proto-ui-duostrap-switch-root>
<span class="text-sm font-medium">Archived alerts</span>
</div>
</div>当前仅在源码工作区提供,可从 @proto.ui/prototypes-duostrap/switch 导入。查看已实现的子集。
import { switchRoot, switchThumb } from '@proto.ui/prototypes-duostrap/switch';<proto-ui-duostrap-switch-root default-checked> <proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb> <span class="sr-only">Release alerts</span></proto-ui-duostrap-switch-root>- 状态由 Root 统一管理:支持受控
checked与非受控defaultChecked,处理点击、键盘激活、悬停/按压立体反馈、焦点与禁用状态。 - Thumb 自动同步:放置在
Root内部,自动跟随开关状态、拖动百分比与direction滑动,并在prefers-reduced-motion: reduce下取消位移动画。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root
class="flex max-w-sm flex-row items-center justify-between gap-4"
>
<div class="flex min-w-0 flex-1 flex-col gap-1">
<proto-ui-duostrap-field-label>
Share across devices
</proto-ui-duostrap-field-label>
<proto-ui-duostrap-field-description>
Focus is shared across devices, and turns off when you leave
the app.
</proto-ui-duostrap-field-description>
</div>
<proto-ui-duostrap-field-switch>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
</proto-ui-duostrap-field-switch>
</proto-ui-duostrap-field-root> Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root
disabled
class="flex max-w-sm flex-row items-center justify-between gap-4"
>
<div class="flex min-w-0 flex-1 flex-col gap-1">
<proto-ui-duostrap-field-label>
Disabled (off)
</proto-ui-duostrap-field-label>
</div>
<proto-ui-duostrap-field-switch>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
</proto-ui-duostrap-field-switch>
</proto-ui-duostrap-field-root>校验失败状态
Section titled “校验失败状态” Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root
invalid
class="flex max-w-sm flex-row items-center justify-between gap-4"
>
<div class="flex min-w-0 flex-1 flex-col gap-1">
<proto-ui-duostrap-field-label>
Accept terms and conditions
</proto-ui-duostrap-field-label>
<proto-ui-duostrap-field-description>
You must accept the terms and conditions to continue.
</proto-ui-duostrap-field-description>
</div>
<proto-ui-duostrap-field-switch>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
</proto-ui-duostrap-field-switch>
</proto-ui-duostrap-field-root>拖动与 RTL 方向
Section titled “拖动与 RTL 方向” Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<proto-ui-duostrap-field-root
dir="rtl"
class="flex max-w-sm flex-row items-center justify-between gap-4"
>
<div class="flex min-w-0 flex-1 flex-col gap-1">
<proto-ui-duostrap-field-label>
المشاركة عبر الأجهزة
</proto-ui-duostrap-field-label>
<proto-ui-duostrap-field-description>
يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة
التطبيق.
</proto-ui-duostrap-field-description>
</div>
<proto-ui-duostrap-field-switch
direction="rtl"
draggable
default-checked
>
<proto-ui-duostrap-switch-thumb></proto-ui-duostrap-switch-thumb>
</proto-ui-duostrap-field-switch>
</proto-ui-duostrap-field-root>以下属性与事件属于 Root(Thumb 无额外属性):
| 属性 / 事件 | 类型 | 默认值 |
|---|---|---|
checked | boolean undefined | 非受控 |
defaultChecked | boolean | false |
disabled | boolean | false |
draggable | boolean | false |
direction | 'ltr' 'rtl' | 'ltr' |
checkedChange | event ({ checked: boolean }) | — |
focusSelf | method (options?: FocusRequestOptions) => void | — |