English | 简体中文
- 渲染具有
role="switch"和aria-checked状态的本机按钮。 - 支持受控和非受控检查状态。
- 使用左右箭头键处理点击和键盘切换。
- 为选中和未选中的标签提供内容类/样式槽。
npm install @rc-component/switchimport Switch from '@rc-component/switch';
import '@rc-component/switch/assets/index.css';
export default () => <Switch checkedChildren="On" unCheckedChildren="Off" />;在线预览:https://switch.react-component.vercel.app/
运行本地 dumi 站点:
npm install
npm start然后打开 http://localhost:8000。
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
autoFocus |
boolean | - | 挂载后自动聚焦开关。 |
checked |
boolean | - | 受控的检查状态。 |
checkedChildren |
React.ReactNode | - | 勾选时显示的内容。 |
className |
string | - | 附加 className。 |
classNames |
{ content?: string } |
- | 内部内容的语义 className。 |
defaultChecked |
boolean | false | 初始检查状态。 |
disabled |
boolean | false | 禁用交互。 |
loadingIcon |
React.ReactNode | - | 额外加载图标节点。 |
onChange |
(checked, event) => void |
- | 检查状态更改后触发。 |
onClick |
(checked, event) => void |
- | 点击后触发。 |
onKeyDown |
React.KeyboardEventHandler | - | 按键按下处理函数。 |
prefixCls |
string | 'rc-switch' |
className 前缀。 |
style |
React.CSSProperties | - | 根样式。 |
styles |
{ content?: React.CSSProperties } |
- | 内部内容的语义样式。 |
tabIndex |
number | - | Tab index. |
title |
string | - | 本土产权属性。 |
unCheckedChildren |
React.ReactNode | - | 未选中时显示的内容。 |
npm install
npm start
npm test
npm run tsc
npm run compile
npm run builddumi 站点默认运行在 http://localhost:8000。
npm run prepublishOnly包构建完成后,发布流程由 @rc-component/np 通过 rc-np 命令处理。
@rc-component/switch 基于 MIT 许可证发布。