Switch开关
在两个互斥状态间切换,适用于立即生效的设置。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add switch安装
在项目根目录运行,安装源码。
npx https://kalos-ui-six.vercel.app/cli/kalos-ui-0.3.12.tgz add switch使用
React
"use client";
import { useState } from "react";import { KalosSwitch } from "@/components/ui/kalos-switch";
export default function Example() { const [enabled, setEnabled] = useState(true);
return ( <KalosSwitch label="消息通知" checked={enabled} onCheckedChange={setEnabled} /> );}API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label | string | — | 控件的可见标签 |
description | string | — | 仅在需要补充信息时显示 |
error | string | — | 校验错误;显示时替代说明并关联控件 |
checked | boolean | — | 受控开关状态 |
defaultChecked | boolean | false | 初始状态 |
onCheckedChange | (checked: boolean) => void | — | 状态变化时调用 |
disabled | boolean | false | 禁用开关 |
键盘操作
- Space
- 切换开关
- Tab
- 移动到下一个控件