﻿# Empty {#empty}

Display empty data, network errors and permission states with the eight original illustrations and slots. Use the header menus to switch component theme and language.

## Built-in types {#types}

### Built-in types
```vue
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px">
  <nf-empty type="data" :image-size="120" />
  <nf-empty type="internet" :image-size="120" />
  <nf-empty type="message" :image-size="120" />
  <nf-empty type="server" :image-size="120" />
  <nf-empty type="loading" :image-size="120" />
  <nf-empty type="authority" :image-size="120" />
  <nf-empty type="call" :image-size="120" />
  <nf-empty type="seat" :image-size="120" />
</div>
```

## Image and size {#custom}

### Image and size
```vue
<div style="display: flex; flex-wrap: wrap; gap: 20px">
  <nf-empty :image-size="80" border />
  <nf-empty :image-size="145" description="Custom description" />
  <nf-empty :image-size="100" image="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Ccircle cx='60' cy='60' r='50' fill='%2317f'/%3E%3C/svg%3E" />
</div>
```

## Description and actions {#slots}

### Description and actions
```vue
<nf-empty description="Custom description">
  <template #description><strong>The description slot takes priority</strong></template>
  <nf-button type="primary">Retry</nf-button>
</nf-empty>
```

## Interactive example {#interactive}


See expanded example example-4 (EmptyExamples).


## On-demand usage {#installation}

```ts
import { createApp } from 'vue'
import NfEmpty from '@94ai-plus/nf-empty'
import '@94ai-plus/nf-theme-chalk/nf-empty.css'

const app = createApp(App)
app.use(NfEmpty)
```

Supports standalone installation, named full-library exports and automatic resolver imports. Illustrations follow Chalk/OEM and default messages follow the locale. Explicit descriptions and slots remain application-controlled.

## Props {#props}

| Prop | Description | Type / values | Default |
| --- | --- | --- | --- |
| image | Custom image URL overrides built-in illustrations | string | `''` |
| type | Empty state type | data / internet / message / server / loading / authority / call / seat | data |
| border | Show a border | boolean | false |
| image-size | Image width in px; 0 keeps the default size | number | undefined |
| description | Custom message; empty values use the current locale | string | `''` |

## Slots {#slot-api}

| Slot | Description |
| --- | --- |
| description | Custom description; overrides the description prop |
| default | Bottom actions |

## Migration notes {#migration}

Fixes the missing seat message, reversed OEM seat/server mapping and incorrect imageSize default. Use NfConfigProvider theme or data-nf-theme instead of window.$agentCustomization. SVGs are inlined and rendering is SSR-safe.

## Expanded component examples

### EmptyExamples

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

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

const { locale } = useDocsLanguage()
const types: EmptyType[] = ['data', 'internet', 'message', 'server', 'loading', 'authority', 'call', 'seat']
const type = ref<EmptyType>('data')
const imageSize = ref(140)
const description = ref('')
const border = ref(false)
const customImage = ref(false)
const useDescriptionSlot = ref(false)
const count = ref(0)
const image = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="120" height="120"%3E%3Ccircle cx="60" cy="60" r="50" fill="%2317f"/%3E%3C/svg%3E'
</script>

<template>
  <section class="empty-examples" data-testid="empty-examples">
    <div class="empty-controls">
      <label>type <select v-model="type" data-testid="empty-type"><option v-for="item in types" :key="item">{{ item }}</option></select></label>
      <label>imageSize <input v-model.number="imageSize" data-testid="empty-size" type="number" min="0" max="300"></label>
      <label>description <input v-model="description" data-testid="empty-description"></label>
      <label><input v-model="border" data-testid="empty-border" type="checkbox">border</label>
      <label><input v-model="customImage" data-testid="empty-custom-image" type="checkbox">image</label>
      <label><input v-model="useDescriptionSlot" data-testid="empty-description-slot" type="checkbox">description slot</label>
    </div>
    <NfEmpty data-testid="interactive-empty" :type="type" :image="customImage ? image : ''" :image-size="imageSize" :description="description" :border="border">
      <template v-if="useDescriptionSlot" #description><strong data-testid="empty-slot-text">{{ locale === 'zh-CN' ? '自定义描述插槽' : 'Custom description slot' }}</strong></template>
      <NfButton type="primary" data-testid="empty-retry" @click="count++">{{ locale === 'zh-CN' ? '重试' : 'Retry' }} {{ count }}</NfButton>
    </NfEmpty>
  </section>
</template>

<style scoped>
.empty-controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.empty-controls label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; }
.empty-controls input:not([type='checkbox']) { width: 120px; }
.empty-controls input, .empty-controls select { border: 1px solid var(--site-border); border-radius: 4px; padding: 4px; background: var(--site-background); color: var(--site-text); }
.empty-examples > .nf-empty { padding: 16px; }
</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 }
}
```
