Switch

维护者:
zamkovskaya
GitHub
size
content
checked
disabled
import {Switch} from '@gravity-ui/uikit';

Switch 组件用于在两种状态之间切换:通常是在开启 关闭之间 ,或者启用禁用之间

国家

A Switch 可以有不同的状态:

  • 已选中:当交换机处 于 On 状态时。
  • 已禁用:当交换机不可用时。
<Switch size="l" checked={false}>Unchecked</Switch>
<Switch size="l" checked>Checked</Switch>
<Switch size="l" disabled>Disabled</Switch>

大小

使用该 size 属性来管理大 Switch 小。默认大小为 m

<Switch size="m">M Size</Switch>
<Switch size="l">L Size</Switch>

标签

您可以使用该 content 属性为分配标签,也可以将其作为子属性提供。 Switch

<div>
  <Switch content="Content" size="l" />
  <div
    style={{
      marginTop: 10,
    }}
  >
    <Switch size="l">
      <span>Content as children</span>
    </Switch>
  </div>
</div>

属性

姓名描述类型默认
儿童交换机的内容(通常是标签)ReactNode
内容交换机的内容(儿童替代方案)ReactNode
残疾的切换交换机的 disabled 状态booleanfalse
已检查切换交换机的 checked 状态booleanfalse
defaultChecked设置组件挂载时的初始检查状态booleanfalse
onUpdate当用户更改开关状态时触发,并将检查值作为回调参数提供(checked: boolean) => void
onChange当用户更改开关状态时触发,并将更改事件作为回调参数提供Function
onFocus开关输入元素获得焦点时使用的事件处理程序Function
onBlur当开关输入元素失去焦点时使用的事件处理器Function
尺寸设置交换机的大小m lm
idid HTML 属性string
qadata-qa HTML 属性,用于测试string
风格style HTML 属性React.CSSProperties
classNameclass HTML 属性string
标题title HTML 属性string
名称name 输入元素的 HTML 属性string
价值value 输入元素的 HTML 属性string
不确定切换交换机的不确定状态booleanfalse
controlProps底层输入元素的其他属性react.inputhtmlAtributes<HTMLInputElement>
controlRef引用底层输入元素React.Ref<HTMLInputElement>