﻿# 标签 {#tag}

原生状态标签，支持六种类型、小圆点、文本回退和点击事件。可通过导航栏切换 Chalk／OEM 组件主题。

## 状态类型 {#variants}

### 状态类型
```vue
<template>
  <div style="display: flex; flex-wrap: wrap; gap: 16px">
    <nf-tag type="success">Success</nf-tag>
    <nf-tag type="info">Info</nf-tag>
    <nf-tag type="disabled">Disabled</nf-tag>
    <nf-tag type="warning">Warning</nf-tag>
    <nf-tag type="tip">Tip</nf-tag>
    <nf-tag type="danger">Danger</nf-tag>
  </div>
</template>
```

## 显示圆点 {#circle}

### 显示圆点
```vue
<template>
  <nf-tag type="success" value="With dot" />
  <nf-tag type="success" value="Without dot" :circle="false" style="margin-left: 12px" />
</template>
```

## 文本与插槽 {#content}

### 文本与插槽
```vue
<template>
  <nf-tag type="info" value="Value text" />
  <nf-tag type="tip" value="Fallback" style="margin-left: 12px"><strong>Slot wins</strong></nf-tag>
  <nf-tag value="No type" style="margin-left: 12px" />
</template>
```

## 点击事件 {#click}

### 点击事件
```vue
<script setup>
import { ref } from 'vue'
const count = ref(0)
const target = ref('')
function onClick(event) {
  count.value++
  target.value = event.target.tagName
}
</script>

<template>
  <nf-tag type="disabled" @click="onClick">Click me</nf-tag>
  <output style="margin-left: 12px">click: {{ count }} / target: {{ target }}</output>
</template>
```

type 默认 undefined，不设置状态类型时不添加状态类。value 默认为空字符串，作为普通文本渲染；默认插槽优先于 value。circle 默认为 true，圆点仅作装饰。

> **info disabled**
type="disabled" 仅为灰色外观，仍会触发 click，不代表禁用交互。click 传回原始 MouseEvent，保持原生冒泡，不自动阻止默认行为；旧文档省略了事件参数，本次以源码实际行为为准。

## 交互体验 {#interactive}


See expanded example example-5 (TagExamples).


## 按需引入 {#installation}

```ts
import NfTag from '@94ai-plus/nf-tag'
import '@94ai-plus/nf-theme-chalk/nf-tag.css'

app.use(NfTag)
```

## 类型 {#types}

```ts
import type { TagProps, TagType } from '@94ai-plus/nf-tag'
// TagType: 'disabled' | 'success' | 'info' | 'warning' | 'danger' | 'tip'
```

## 属性 {#props}

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| type | 类型；disabled 仅改变外观，不禁用点击 | string | disabled / success / info / warning / danger / tip | undefined |
| circle | 是否显示小圆点 | boolean | — | true |
| value | 未提供默认插槽时显示的文本 | string | — | `''` |

## 事件 {#events}

| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| click | 点击回调，传回原始 MouseEvent | event: MouseEvent |

## 插槽 {#slots}

| Slot | 说明 | 回调参数 |
| --- | --- | --- |
| default | tag 内容 | — |

## 迁移说明 {#migration}

保留原有三属性、默认插槽、div 根节点及点击行为。Chalk info 文字／圆点为 #0b73ff，OEM 跟随主题主色（默认 #007555），背景仍为 #e7f1ff；其余状态保留旧版配色与尺寸。

业务文案由 value 或插槽传入，不自动翻译。组件不新增按钮语义或键盘行为；可操作控件应使用合适的按钮／链接并提供无障碍交互。旧文档 Event／Slot 错写的 ai-action-md 锚点不接管，以免影响真实 action 文档；新的 tag 路由使用独立锚点。

## Expanded component examples

### TagExamples

Source: docs/.vitepress/theme/components/TagExamples.vue

```vue
<script setup lang="ts">
import { ref } from 'vue'
import { NfTag, type TagType } from '@94ai-plus/common-ui'
import { useDocsLanguage } from '../locale'

const { english } = useDocsLanguage()
const type = ref<TagType | ''>('success')
const value = ref('Status')
const circle = ref(true)
const custom = ref(false)
const clicks = ref(0)
const bubbles = ref(0)
const last = ref('')
function onClick(event: MouseEvent) {
  clicks.value++
  last.value = `${event.type}/${(event.target as Element).tagName}/${event instanceof MouseEvent}`
}
</script>

<template>
  <section class="tag-examples">
    <div class="tag-controls">
      <label>type <select v-model="type" data-testid="tag-type"><option value="">—</option><option>success</option><option>info</option><option>disabled</option><option>warning</option><option>tip</option><option>danger</option></select></label>
      <label>value <input v-model="value" data-testid="tag-value"></label>
      <label><input v-model="circle" type="checkbox" data-testid="tag-circle">circle</label>
      <label><input v-model="custom" type="checkbox" data-testid="tag-slot">default slot</label>
    </div>
    <div class="tag-preview" data-testid="tag-parent" @click="bubbles++">
      <NfTag data-testid="interactive-tag" title="Status tag" :type="type || undefined" :value="value" :circle="circle" @click="onClick">
        <template v-if="custom" #default><strong data-testid="tag-slot-content">{{ english ? 'Custom content' : '自定义内容' }}</strong></template>
      </NfTag>
    </div>
    <output data-testid="tag-result">click: {{ clicks }}; bubble: {{ bubbles }}; last: {{ last }}</output>
  </section>
</template>

<style scoped>
.tag-controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.tag-controls label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.tag-controls input:not([type='checkbox']) { width: 150px; }
.tag-controls input, .tag-controls select { border: 1px solid var(--site-border); border-radius: 4px; padding: 4px; background: var(--site-background); color: var(--site-text); }
.tag-preview { padding: 12px; border: 1px solid var(--site-border); overflow-wrap: anywhere; }
.tag-examples output { display: block; margin-top: 12px; font-size: 12px; overflow-wrap: anywhere; }
</style>
```

Source: docs/.vitepress/theme/locale.ts

```ts
import { computed, inject, type InjectionKey, type Ref } from 'vue'
import { withBase } from 'vitepress'
import { localizePath, type LocaleName } from '../../../packages/common-locale/src/languages'
import { additionalMessages } from '../locales/ui'
export { languageDefinitions, localeFromPath, isLocaleName } from '../../../packages/common-locale/src/languages'

export type DocsLanguage = LocaleName
export const languageStorageKey = 'common-ui-plus:docs-language'
export const docsLanguageKey: InjectionKey<Ref<DocsLanguage>> = Symbol('docs-language')

const zh = {
  brand: '94智能通用组件库', home: '94智能公共组件库首页', skip: '跳至正文',
  toggleSidebar: '切换侧边导航', closeNav: '关闭导航', navigation: '顶部导航', sidebar: '文档导航', outline: '当前页面目录',
  guide: '指南', packages: '分包集合', theme: '主题', language: '语言', links: '边缘库',
  chalk: 'Chalk 默认主题', oem: 'OEM 定制主题', playground: '演练场',
  dark: '切换为暗色模式', light: '切换为亮色模式',
  search: '搜索文档', searchPlaceholder: '搜索文档，索引至标题，定位至组件', noResults: '没有匹配结果',
  example: '示例', loadingDemo: '正在加载示例…', preview: '实时预览', actions: '示例操作',
  edit: '在线编辑', editTitle: '在演练场中编辑', copy: '复制代码', copied: '代码已复制',
  expand: '展开代码', collapse: '收起代码', switchJs: '切换为 JS', switchTs: '切换为 TS',
  editor: '示例代码编辑器', switchFailed: '语言切换失败，代码未更改：',
  manualCopy: '请展开代码后手动复制。', copyFailed: '无法访问剪贴板，请在展开的编辑器中手动复制。',
}
const en: typeof zh = {
  brand: '94AI Common UI', home: '94AI Common UI home', skip: 'Skip to content',
  toggleSidebar: 'Toggle sidebar', closeNav: 'Close navigation', navigation: 'Top navigation', sidebar: 'Documentation navigation', outline: 'On this page',
  guide: 'Guide', packages: 'Packages', theme: 'Theme', language: 'Language', links: 'Links',
  chalk: 'Chalk default theme', oem: 'OEM custom theme', playground: 'Playground',
  dark: 'Switch to dark mode', light: 'Switch to light mode',
  search: 'Search docs', searchPlaceholder: 'Search docs, headings and components', noResults: 'No matching results',
  example: 'Example', loadingDemo: 'Loading example…', preview: ' live preview', actions: 'Example actions',
  edit: 'Edit online', editTitle: 'Edit in playground', copy: 'Copy code', copied: 'Code copied',
  expand: 'Expand code', collapse: 'Collapse code', switchJs: 'Switch to JS', switchTs: 'Switch to TS',
  editor: 'Example code editor', switchFailed: 'Language switch failed; code unchanged: ',
  manualCopy: 'Expand the code and copy it manually.', copyFailed: 'Clipboard unavailable. Copy the code manually from the editor.',
}
export const docsMessages: Record<DocsLanguage, typeof zh> = { 'zh-CN': zh, 'en-US': en, ...additionalMessages }

export function localizedPath(path: string, locale: DocsLanguage): string {
  return localizePath(path, locale)
}

export function useDocsLanguage() {
  const locale = inject(docsLanguageKey)!
  const english = computed(() => locale.value !== 'zh-CN')
  const ui = computed(() => docsMessages[locale.value])
  const docLink = (path: string) => withBase(localizedPath(path, locale.value))
  return { locale, english, ui, docLink }
}
```
