﻿# Tag {#tag}

A native status tag with six variants, an optional status dot, text fallback and click events. Switch Chalk/OEM component themes from the header.

## Status variants {#variants}

### Status 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>
```

## Status dot {#circle}

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

## Text and slots {#content}

### Text and slots
```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 events {#click}

### Click events
```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 defaults to undefined: no variant class is added when omitted. value defaults to an empty string and renders as plain text; the default slot takes precedence. circle defaults to true and is decorative.

> **info disabled**
type="disabled" is a gray visual variant, not a disabled control: it still emits click. click receives the original MouseEvent and keeps native bubbling/default behavior. The legacy documentation omitted this payload; the implementation is the compatibility baseline.

## Interactive example {#interactive}


See expanded example example-5 (TagExamples).


## On-demand import {#installation}

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

app.use(NfTag)
```

## Types {#types}

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

## Props {#props}

| Attribute | Description | Type | Accepted values | Default |
| --- | --- | --- | --- | --- |
| type | Type; disabled changes appearance only, not click behavior | string | disabled / success / info / warning / danger / tip | undefined |
| circle | Whether to show the dot | boolean | — | true |
| value | Text displayed when the default slot is absent | string | — | `''` |

## Events {#events}

| Event | Description | Payload |
| --- | --- | --- |
| click | Click callback with the original MouseEvent | event: MouseEvent |

## Slots {#slots}

| Slot | Description | Payload |
| --- | --- | --- |
| default | Tag content | — |

## Migration notes {#migration}

Preserves all three props, the default slot, div root and click behavior. Chalk info text/dot remains #0b73ff; OEM follows the theme primary color (default #007555). Its background stays #e7f1ff. Other colors and dimensions remain unchanged.

Business text comes from value or slots and is not translated automatically. The tag does not add button semantics or keyboard behavior; use appropriate accessible buttons/links for actions. Incorrect ai-action-md event/slot anchors in the old tag page are not claimed, to avoid conflicts with the real action page. Tag routes use their own anchors.

## 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 }
}
```
