Switch · With label · 01
Loading preview...
Component
安装 Installation
用法 Usage
className 与 variant、size 可以一起用。字段以 timkit agent inspect switch --json 的 props 为准。
示例
一次看一个示例。左侧按名称筛选,预览里可切换源码和框架。
17 / 17
结构化 API
与 UCS schema 对齐的 props、逻辑机与多框架运行时。
Component
switch
Logic
zag / switch
Runtime Frameworks
Supported Platforms
| Prop | Type | Default | Description |
|---|---|---|---|
| logic.provider* | enum (zag | native | none) | zag | State and interaction provider used by this component. |
| logic.machine | string | switch | Underlying state machine identifier when provider is zag. |
| platforms* | array | Web, WeChat Mini Program | Platforms officially supported by this schema. |
| frameworks* | array | React, Vue, Weapp, HTML | Framework demos/code currently available in registry files. |
| dependencies | array | @timui/core, @zag-js/react | Runtime package dependencies required by this registry item. |
| optionalPeerDependencies | array | - | Optional peer dependencies used by this registry item. |
| registryDependencies | array | use-machine | Dependent Timkit registry components/hook entries. |
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | The controlled checked state. |
| disabled | boolean | false | Whether the switch is disabled. |
| readOnly | boolean | false | When true, checked changes are ignored. |
| required | boolean | false | When true, the switch is announced as required. |
| Prop | Type | Default | Description |
|---|---|---|---|
| onCheckedChange | event | - | Callback called when checked state changes. |
来自 TypeScript 导出。
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | - | Input behavior configuration for id. |
| defaultChecked | boolean | - | The default checked state of the component when initially rendered. |
| name | string | - | The name of the component, used when submitting an HTML form. |
| value | string | - | The controlled value of the component. |
| modelValue | boolean | - | The controlled value bound via `v-model` (Vue specific). |
| Prop | Type | Default | Description |
|---|---|---|---|
| default | slot | - | Default slot content rendered inside the component root. |
| Prop | Type | Default | Description |
|---|---|---|---|
| root* | root | - | The switch container |
| thumb | part | - | The thumb element that slides |
该组件尚无扩展说明文档。
键盘与焦点
跨 React、Vue 与小程序共享的交互与可读名称约定。
行为契约
props、默认值和运行时状态。