---
title: Button 按钮 (done)
order: 1
group: 
  path: /components
nav: 
  title: 组件
  path: /components
---

## 使用

### 类型
+ 通过设置 `type` 为 `primary`、`dashed`、`link`、或者 `不设置` 分别把按钮设为主按钮、虚线按钮、链接按钮、次按钮。
+ 通过设置 `shape` 为 `circle` 和 `round` 分别把按钮设为圆形和圆角型。
+ 通过设置 `loading` 为 `true` 把按钮设为加载状态。
+ 通过设置 `disabled` 为 `true` 把按钮设为禁用状态。
+ 通过设置 `ghost` 为 `true` 把按钮的背景色设置为透明。
+ 通过设置 `dangerous` 为 `true` 把按钮设为危险按钮。

推荐顺序为：dangerous -> type -> shape -> size -> loading -> disabled。


```jsx
import React from 'react';
import { Button } from 'baas-ui';
import Table from './components/Table';

const columns = [
  { title: '按钮类型', dataIndex: 'type' },
  { title: 'Normal', dataIndex: 'normal' },
  { title: 'Disabled', dataIndex: 'disabled' },
  { title: 'Loading', dataIndex: 'loding' },
  { title: 'Danger', dataIndex: 'danger' },
  { title: 'Ghost', dataIndex: 'ghost' },
  { title: 'Shape', dataIndex: 'shape' },
];

const dataSource = [
  {
    type: '主按钮',
    normal: <Button type="primary">主按钮</Button>,
    disabled: <Button type="primary" disabled>主按钮</Button>,
    loding: <Button type="primary" loading>主按钮</Button>,
    danger: <Button type="primary" danger>主按钮</Button>,
    ghost: <Button type="primary" ghost>主按钮</Button>,
    shape: (
      <React.Fragment>
          <Button type="primary" shape="round">按钮</Button>
      </React.Fragment>
    ),
  },
  {
    type: '次按钮',
    normal: <Button>次按钮</Button>,
    disabled: <Button disabled>次按钮</Button>,
    loding: <Button loading>次按钮</Button>,
    danger: <Button danger>主按钮</Button>,
    ghost: <Button ghost>主按钮</Button>,
    shape: (
      <React.Fragment>
          <Button shape="round">按钮</Button>
      </React.Fragment>
    ),
  },
  {
    type: '虚线按钮',
    normal: <Button type="dashed">虚线按钮</Button>,
    disabled: <Button type="dashed" disabled>虚线按钮</Button>,
    loding: <Button type="dashed" loading>虚线按钮</Button>,
    danger: <Button type="dashed" danger>按钮</Button>,
    ghost: <Button type="dashed" ghost>按钮</Button>,
    shape: (
      <React.Fragment>
          <Button type="dashed" shape="round">按钮</Button>
      </React.Fragment>
    ),
  },
  {
    type: '链接按钮',
    normal: <Button type="link">链接按钮</Button>,
    disabled: <Button type="link" disabled>链接按钮</Button>,
    loding: <Button type="link" loading>链接按钮</Button>,
    danger: <Button type="link" danger>主按钮</Button>,
    ghost: <Button type="link" ghost>主按钮</Button>,
    shape: (
      <React.Fragment>
          <Button type="link" shape="round">按钮</Button>
      </React.Fragment>
    ),
  }
];

export default () => (
  <Table
    columns={columns}
    dataSource={dataSource}
    rowKey="type"
    pagination={false}
  />
);
```
> 选中按钮见 `Radio.Button`

### 尺寸
通过设置`size`为`large`、`middle`、`small`、`xsmall`分别把按钮设为大、中、小、较小尺寸，`size`的默认值为`middle`。不同的`size`类型的按钮，使用场景不同。
+ `large`：登录注册、需要重点突出的长按钮。
+ `middle`：最常用的按钮，页面表单里的按钮、弹窗里的按钮等。
+ `small`：卡片里的按钮；气泡确认框。
+ `xsmall`：层级弱的按钮，比如列表中的按钮、复制按钮、温馨提示框里的按钮。

```jsx
import React from 'react';
import { Button } from 'baas-ui';
export default () => (
  <div>
    <div style={{ marginBottom: 20 }}>
      <span style={{ width: 100, display: 'inline-block' }}>Large：</span>
      <Button type="primary" size="large">Large</Button>
    </div>
    <div style={{ marginBottom: 20 }}>
      <span style={{ width: 100, display: 'inline-block' }}>Middle：</span>
      <Button type="primary" size="middle">Middle</Button>
    </div>
    <div style={{ marginBottom: 20 }}>
      <span style={{ width: 100, display: 'inline-block' }}>Small：</span>
      <Button type="primary" size="small">Small</Button>
    </div>
    <div style={{ marginBottom: 20 }}>
      <span style={{ width: 100, display: 'inline-block' }}>XSmall：</span>
      <Button type="primary" size="xsmall">XSmall</Button>
    </div>
  </div>
);
```

## API
除了 `size` 属性中增加了 `xsmall` 选项外，其余API 与 `Ant Design` 中的 `Button` API 一致。

| 属性 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| disabled | 按钮失效状态 | boolean | `false` |  |
| ghost | 幽灵属性，使按钮背景透明 | boolean | false |  |
| href | 点击跳转的地址，指定此属性 button 的行为和 a 链接一致 | string | - |  |
| htmlType | 设置 `button` 原生的 `type` 值，可选值请参考 [HTML 标准](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type) | string | `button` |  |
| icon | 设置按钮的图标组件 | ReactNode | - |  |
| loading | 设置按钮载入状态 | boolean \| { delay: number } | `false` |  |
| shape | 设置按钮形状，可选值为 `circle`、 `round` 或者不设 | string | - |  |
| size | 设置按钮大小 | `large` \| `middle` \| `small` \| `xsmall` | 无 |  |
| target | 相当于 a 链接的 target 属性，href 存在时生效 | string | - |  |
| type | 设置按钮类型，可选值为 `primary` `dashed` `link` 或者不设 | string | - |  |
| onClick | 点击按钮时的回调 | (event) => void | - |  |
| block | 将按钮宽度调整为其父宽度的选项 | boolean | `false` |  |
| danger | 设置危险按钮 | boolean | `false` |  |
