145a208687
HD-04 scope, against heroui ce90ea3 cn sources: - stale/fictional content: input.md no longer claims TextField is unmigrated; color-field.md no longer claims ColorPicker is private; header.md drops the fictional Header.Root subcomponent and the stale 'menus not migrated' wording (MenuSection label registration is now documented from HeaderRoot source); radio-group.md drops three copied CheckboxGroup wordings (variant override is Radio's, scalar emits, native single-value submit); input-otp.md drops the fictional data-complete state and lists the real missing upstream props - toggle-button disabled row now matches the real CSS hooks (:disabled / [aria-disabled], with data-disabled as a marker only) - part API / CSS classes / interactive states restored per pinned sources: button (full class lists + real variable-based global CSS), accordion (per-part tables + variant/state lists), card (per-part tables + variant list), switch (SwitchGroup snippet + Switch/ SwitchGroup class lists + states), color-field Group (class list + states), input-otp (variant notes, global CSS, class/state lists); input-group gains the two upstream usage chapters - RelatedComponents restored from the pinned componentRelationships (first-3, filtered against componentsMap): 64 pages rewritten, list-box/slider sections added, 7 empty-mapping pages' fabricated entries removed; RelatedShowcases left unmigrated with its real data inventory recorded (2 cases, showcase-site cards) - defaults unified on implementation evidence: granularity (inferred day/minute) and visibleYears (full min-max span, no "or 20" fallback); HD-03 hand-offs resolved (trigger focus-visible noted for HD-06, width guards kept) - new demos: header-collection-grouping (MenuSection/ListBoxSection label wiring), empty-state-collection (collection empty slot); empty-state page deduplicated with a boundary compatibility note - ComponentPreview minHeight/isBgSolid restored per the 30 upstream marks; tabs-overflow max-w-full kept after measuring internal scroll - tests: +3 header registration/demo cases, +1 empty-state collection case; full suite 110 files / 1630 tests, typecheck and build:docs pass
161 lines
5.0 KiB
Markdown
161 lines
5.0 KiB
Markdown
---
|
|
title: Chip 标签
|
|
description: 用于显示标签、状态与分类的小型信息徽章
|
|
component: chip
|
|
group: 组件
|
|
---
|
|
|
|
## 用法
|
|
|
|
```vue
|
|
<script setup lang="ts">
|
|
import { Chip } from "@heroui-vue/components";
|
|
</script>
|
|
```
|
|
|
|
<ComponentPreview name="chip-basic" />
|
|
|
|
## 组件结构
|
|
|
|
> 纯文本子节点会自动包裹在 `<ChipLabel>` 中。
|
|
|
|
```vue
|
|
<Chip>
|
|
Label text
|
|
</Chip>
|
|
```
|
|
|
|
显式使用部件或组合内容时不会重复包装:
|
|
|
|
```vue
|
|
<Chip>
|
|
<IconCircleFilled :size="6" aria-hidden="true" />
|
|
<ChipLabel>标签</ChipLabel>
|
|
</Chip>
|
|
```
|
|
|
|
## 示例
|
|
|
|
### 变体
|
|
|
|
<ComponentPreview name="chip-variants" />
|
|
|
|
### 状态类型
|
|
|
|
<ComponentPreview name="chip-statuses" />
|
|
|
|
### 带图标
|
|
|
|
<ComponentPreview name="chip-with-icon" />
|
|
|
|
## 自定义样式
|
|
|
|
### Tailwind CSS
|
|
|
|
<ComponentPreview name="chip-custom-styles" />
|
|
|
|
### 全局 CSS
|
|
|
|
可使用 `@layer components` 指令自定义 Chip 组件类。
|
|
|
|
```css
|
|
@layer components {
|
|
.hv-chip {
|
|
@apply rounded-full text-xs;
|
|
}
|
|
|
|
.hv-chip__label {
|
|
@apply font-medium;
|
|
}
|
|
|
|
.hv-chip--accent {
|
|
@apply border-accent/20;
|
|
}
|
|
|
|
.hv-chip--accent .hv-chip__label {
|
|
@apply text-accent;
|
|
}
|
|
}
|
|
```
|
|
|
|
## 样式参考
|
|
|
|
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
|
|
|
### CSS 类
|
|
|
|
Chip 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/chip.css)):
|
|
|
|
#### 基础类 [!toc]
|
|
|
|
- `.hv-chip` - 基础标签容器样式
|
|
- `.hv-chip__label` - 标签文本 slot 样式
|
|
|
|
#### 颜色类 [!toc]
|
|
|
|
- `.hv-chip--accent` - 强调色变体
|
|
- `.hv-chip--danger` - 危险色变体
|
|
- `.hv-chip--default` - 默认色变体
|
|
- `.hv-chip--success` - 成功色变体
|
|
- `.hv-chip--warning` - 警告色变体
|
|
|
|
#### 变体类 [!toc]
|
|
|
|
- `.hv-chip--primary` - 填充背景的主变体
|
|
- `.hv-chip--secondary` - 带边框的次变体
|
|
- `.hv-chip--tertiary` - 透明背景的三级变体
|
|
- `.hv-chip--soft` - 浅色背景的 soft 变体
|
|
|
|
#### 尺寸类 [!toc]
|
|
|
|
- `.hv-chip--sm` - 小尺寸
|
|
- `.hv-chip--md` - 中尺寸(默认)
|
|
- `.hv-chip--lg` - 大尺寸
|
|
|
|
#### 复合变体类 [!toc]
|
|
|
|
Chip 支持组合变体与颜色类(如 `.hv-chip--secondary.hv-chip--accent`)。以下组合有默认样式:
|
|
|
|
**Primary Variants:**
|
|
|
|
- `.hv-chip--primary.hv-chip--accent` - 填充背景的 primary accent 组合
|
|
- `.hv-chip--primary.hv-chip--success` - 填充背景的 primary success 组合
|
|
- `.hv-chip--primary.hv-chip--warning` - 填充背景的 primary warning 组合
|
|
- `.hv-chip--primary.hv-chip--danger` - 填充背景的 primary danger 组合
|
|
|
|
**Soft Variants:**
|
|
|
|
- `.hv-chip--accent.hv-chip--soft` - 浅色背景的 soft accent 组合
|
|
- `.hv-chip--success.hv-chip--soft` - 浅色背景的 soft success 组合
|
|
- `.hv-chip--warning.hv-chip--soft` - 浅色背景的 soft warning 组合
|
|
- `.hv-chip--danger.hv-chip--soft` - 浅色背景的 soft danger 组合
|
|
|
|
**Note:** 可使用 CSS 中的 `@layer components` 指令为任意变体-颜色组合(如 `.hv-chip--secondary.hv-chip--accent`、`.hv-chip--tertiary.hv-chip--success`)应用自定义样式。
|
|
|
|
## API 参考
|
|
|
|
### Chip
|
|
|
|
| Prop | 类型 | 默认值 | 描述 |
|
|
| --------- | ------------------------------------------------------------- | ------------- | --------------------------------------------------- |
|
|
| `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | 标签颜色变体 |
|
|
| `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'soft'` | `'secondary'` | 视觉样式变体 |
|
|
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 标签尺寸 |
|
|
| 默认插槽 | `Component` | - | 标签内显示的内容;纯文本/数字自动包装为 `ChipLabel` |
|
|
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
|
|
|
### ChipLabel
|
|
|
|
| Prop | 类型 | 默认值 | 描述 |
|
|
| -------- | --------------------------- | ------ | ----------------------------- |
|
|
| 默认插槽 | `Component` | - | 标签文本内容 |
|
|
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
|
|
|
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象,并与组件或 slot 基础类合并;不要使用 React 的 `className`。
|
|
|
|
纯文本或数字默认插槽会在渲染时包装为 `ChipLabel`;显式 `ChipLabel` 或图标等组合内容不会重复包装。文本与组合内容之间动态切换时会按当前插槽重新判断。
|
|
|
|
## 相关组件
|
|
|
|
[Avatar 头像](./avatar) · [CloseButton 关闭按钮](./close-button) · [Separator 分隔符](./separator)
|