按钮有三种视觉层次:主按钮、次按钮、普通按钮。不同的类型可以用来区别按钮的重要程度。
默认情况下 Button 组件使用 <button> 标签来渲染按钮,通过 component 属性可以自定义 Button 的标签类型。
可选值为 button 和 a。
Button 可以嵌入 Icon,默认情况下 Icon 尺寸自动跟随 Button 的尺寸,可以通过 iconSize 属性进行设置。
通过设置 icons 属性中的 loading 即可自定义加载的 icon。
| 参数 | 说明 | 类型 | 默认值 | 是否必填 |
|---|---|---|---|---|
| type | 按钮的类型 | 'primary' | 'secondary' | 'normal' | 'normal' | |
| size | 按钮的尺寸 | ButtonSize | 'medium' | |
| icons | 按钮中可配置的 Icon | { loading?: React.ReactNode } | - | |
| iconSize | 按钮中 Icon 的尺寸 | | number | 'xxs' | 'xs' | 'small' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' | 'inherit' |
默认根据 size 自动映射,映射规则: size:large -> smallsize:medium -> xssize:small -> xs |
|
| htmlType | button 标签的 type 值 | 'submit' | 'reset' | 'button' | 'button' | |
| component | 最终渲染的 jsx 标签标签类型 | 'button' | 'a' | React.ComponentType<unknown> | - | |
| loading | 设置按钮的载入状态 | boolean | false | |
| ghost | 是否为幽灵按钮 | true | false | 'light' | 'dark' | false | |
| text | 是否为文本按钮 | boolean | false | |
| warning | 是否为警告按钮 | boolean | false | |
| disabled | 是否禁用 | boolean | false | |
| onClick | 点击按钮的回调 | React.MouseEventHandler | - |
| 参数 | 说明 | 类型 | 默认值 | 是否必填 |
|---|---|---|---|---|
| size | 统一设置 Button 组件的按钮大小 | ButtonSize | - |
按钮类型
export type ButtonSize = 'small' | 'medium' | 'large';
| 按键 | 说明 |
|---|---|
| Enter | 触发onClick事件 |
| SPACE | 触发onClick事件 |