---
url: /reference/interface/ui-components/icon.md
---
# Icon

图标用于展示内置图标库中的图形符号，可与文本或其他组件组合使用。

## 使用

::: code-group

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

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

:::

## 属性

:::comp-props

| 名称         | 类型                                                                     | 必填 | 描述                               |
| ------------ | ------------------------------------------------------------------------ | ---- | ---------------------------------- |
| `name`       | `string`                                                                 | Y    | 图标名称，仅支持内置图标库中的名称 |
| `appearance` | `'outline' \| 'fill'`                                                    |      | 图标外观，默认 `outline`           |
| `size`       | `'small' \| 'medium' \| 'large'`                                         |      | 图标大小，默认 `medium`            |
| `color`      | `'default' \| 'primary' \| 'success' \| 'info' \| 'warning' \| 'danger'` |      | 语义色，默认 `default`             |
| `rotate`     | `number`                                                                 |      | 旋转角度（度），如 `90`、`180`     |

:::

## 示例

### Basic

通过 `name` 指定图标。`name` 只支持内置图标库中的名称，暂不支持应用本地资源图标与远程图标。

:::demo src=icon-basic
:::

### Appearance

通过 `appearance` 设置图标外观，取值可以为 `'outline' | 'fill'`。`fill` 会在图标名后追加 `-fill`，因此只有提供了 fill 变体的图标可用；默认为 `outline`。

:::demo src=icon-appearance
:::

### Size

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

:::demo src=icon-size
:::

### Color

通过 `color` 设置语义色，取值可以为 `'default' | 'primary' | 'success' | 'info' | 'warning' | 'danger'`。不支持任意色值；需要自定义色时用 `className`。

:::demo src=icon-color
:::

### Rotate

通过 `rotate` 设置旋转角度（单位为度）。

:::demo src=icon-rotate
:::
