---
url: /reference/interface/ui-components/button.md
---
# Button

按钮会触发一个事件或动作，它让用户知道接下来会发生什么。

## 使用

::: code-group

```ts [Angular]
import { NxButton, NxButtonGroup } from "@pc-nexus/angular";
```

```ts [React]
import { NxButton, NxButtonGroup } from "@pc-nexus/react";
```

:::

## 属性

### Button

:::comp-props

| 名称         | 类型                                                                     | 必填 | 描述                                 |
| ------------ | ------------------------------------------------------------------------ | ---- | ------------------------------------ |
| `color`      | `'default' \| 'primary' \| 'info' \| 'warning' \| 'danger' \| 'success'` |      | 按钮颜色，默认 `default`             |
| `appearance` | `'fill' \| 'outline' \| 'link'`                                          |      | 按钮外观，默认 `fill`                |
| `type`       | `'button' \| 'submit' \| 'reset'`                                        |      | 原生 button type，默认 `button`      |
| `name`       | `string`                                                                 |      | 原生 name                            |
| `autofocus`  | `boolean`                                                                |      | 原生 autofocus，默认 `false`         |
| `tabindex`   | `number`                                                                 |      | 原生 tabindex                        |
| `size`       | `'small' \| 'medium' \| 'large'`                                         |      | 按钮大小，默认 `medium`              |
| `icon`       | `string`                                                                 |      | 按钮图标，仅支持内置图标库中的名称   |
| `block`      | `boolean`                                                                |      | 按钮是否占满父容器宽度，默认 `false` |
| `disabled`   | `boolean`                                                                |      | 按钮禁用，默认 `false`               |

:::

### ButtonGroup

:::comp-props

| 名称         | 类型                             | 必填 | 描述                       |
| ------------ | -------------------------------- | ---- | -------------------------- |
| `appearance` | `'outline' \| 'fill'`            |      | 按钮组外观，默认 `outline` |
| `size`       | `'small' \| 'medium' \| 'large'` |      | 按钮组大小                 |

:::

## 示例

### Default

按钮的默认外观和大小，参数使用默认值。

:::demo src=button-default
:::

### Color

通过 `color` 设置按钮颜色，取值可以为 `'default' | 'primary' | 'info' | 'warning' | 'danger' | 'success'`。

:::demo src=button-color
:::

### Appearance

通过 `appearance` 设置按钮外观，取值可以为 `'fill' | 'outline' | 'link'`。常与 `color` 组合使用。

:::demo src=button-appearance
:::

### Size

通过 `size` 设置按钮大小，取值可以为 `'small' | 'medium' | 'large'`。

:::demo src=button-size
:::

### Disabled

通过 `disabled` 设置按钮的禁用状态。

:::demo src=button-disabled
:::

### Icon

通过 `icon` 为按钮添加图标，可与文字组合，也可单独作为图标按钮。

:::demo src=button-icon
:::

### Block

通过 `block` 让按钮占满父容器宽度。

:::demo src=button-block
:::

### Button Group

按钮组，用于将多个按钮组合在一起。

:::demo src=button-group-basic
:::

### Button Group Appearance

通过 `appearance` 设置按钮组外观，取值可以为 `'outline' | 'fill'`。

:::demo src=button-group-appearance
:::

### Button Group Size

通过 `size` 设置按钮组大小，取值可以为 `'small' | 'medium' | 'large'`。

:::demo src=button-group-size
:::

### Button Group Icon

按钮组中的按钮可通过 `icon` 添加图标。

:::demo src=button-group-icon
:::
