MenuChevron Down
Switch 开关 - Docs - Artefact

Switch 开关

Forms
智能自动检测

简介

一种允许用户在选中和未选中状态之间切换的控件。

用法

import { Switch } from "../components/ui";

export default function MyPage() {
  return (
    <Switch
      defaultChecked={true}
      onCheckedChange={(details) => console.log(details.checked)}
      interactive
    >
      Enable Notifications
    </Switch>
  );
}

CMS 页面构建器

该组件可作为 switch 区块在 页面构建器content/pages/*.json)中使用:

{
  "type": "switch",
  "label": "Dark Mode",
  "checked": true,
  "colorPalette": "blue"
}

属性

属性类型说明
childrenany渲染在开关旁边的标签内容。
classstring自定义 CSS 类。
checkedboolean开关是否被选中(受控)。
defaultCheckedboolean初始选中状态(非受控)。
disabledboolean开关是否被禁用。
onCheckedChange(details: { checked: boolean }) => void选中状态变化时触发的回调。

| size | `"sm" \ | "md" \ | "lg"` | 开关的尺寸。 |

| interactive | boolean | 强制作为岛屿进行水合。 |