# Descriptions

> 对象详情的名称与值，支持容器分列、跨列、长内容和操作组合。

网页来源：/components/descriptions

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

展示一个对象的只读属性。`items` 中每项提供唯一 `key`、`label` 和 `value`；多条记录的行列比较使用 [Table](/raw/components/table.md)。

## 基本用法

默认标签在左、值在右，最多两列。`title` 添加可见标题，`titleAs` 指定标题层级；无标题时可用 `label` 为列表提供可访问名称。

### 示例：descriptions/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { QuireDescriptions } from '@quirekit/ui/vue';
const items = [
  { key: 'name', label: '文档名称', value: '产品设计规范' },
  { key: 'owner', label: '负责人', value: '林晓' },
  { key: 'updated', label: '更新日期', value: '2026-09-10' },
  { key: 'version', label: '版本', value: 'v2.4' }
];
</script>
<template>
  <div class="p-qk-surface" data-descriptions-basic><QuireDescriptions title="文档信息" :items="items" /></div>
</template>
```

## 响应式列与跨列

`columns` 设置最多 1–4 列。以组件容器宽度为准，低于 36rem 为一列，达到 36、54、72rem 时依次允许两、三、四列，放入窄面板也会自动收拢。条目的 `span` 支持 1–4 并受当前列数限制；`full` 独占一行，保持原有阅读顺序。

### 示例：descriptions/columns

文件：`columns.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireDescriptions, QuireSpace } from '@quirekit/ui/vue';
import type { QuireKitDescriptionItem, QuireKitDescriptionsColumns } from '@quirekit/ui/vue';
const columns = ref<QuireKitDescriptionsColumns>(3);
const narrow = ref(false);
const items: readonly QuireKitDescriptionItem[] = [
  { key: 'name', label: '项目', value: '协同编辑器' }, { key: 'owner', label: '负责人', value: '陈安' },
  { key: 'stage', label: '阶段', value: '设计评审' }, { key: 'priority', label: '优先级', value: '常规' },
  { key: 'note', label: '说明', value: '支持文档编辑、共享与协同审阅。', span: 2 },
  { key: 'scope', label: '交付范围', value: '组件与文档一起交付；布局随容器变化，内容保持阅读顺序。', span: 'full' }
];
</script>
<template>
  <div class="grid gap-qk-surface p-qk-surface" data-descriptions-columns>
    <QuireSpace block wrap>
      <QuireButton v-for="count in ([1, 2, 3, 4] as const)" :key="count" :aria-pressed="columns === count" :variant="columns === count ? 'soft' : 'text'" @click="columns = count">{{ count }} 列</QuireButton>
      <QuireButton :aria-pressed="narrow" variant="outline" @click="narrow = !narrow">{{ narrow ? '恢复宽容器' : '使用窄容器' }}</QuireButton>
    </QuireSpace>
    <div :style="{ maxWidth: narrow ? '320px' : undefined }" data-descriptions-container>
      <QuireDescriptions :items="items" :columns="columns" label="项目详情" />
    </div>
  </div>
</template>
```

## 标签方向与宽度

`orientation="vertical"` 将标签放到值的上方。横排的 `labelWidth` 默认 `8em`，最大占每项的 40%，长标签和值均可换行。文字方向继承所在区域的 `dir`。

### 示例：descriptions/orientation

文件：`orientation.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireDescriptions, QuireSpace } from '@quirekit/ui/vue';
const vertical = ref(true);
const rtl = ref(false);
const items = [{ key: 'name', label: '归档名称', value: '设计系统' }, { key: 'access', label: '访问权限', value: '团队成员可查看' }];
</script>
<template>
  <div class="grid gap-qk-surface p-qk-surface" data-descriptions-orientation>
    <QuireSpace>
      <QuireButton :aria-pressed="vertical" variant="outline" @click="vertical = !vertical">纵向标签</QuireButton>
      <QuireButton :aria-pressed="rtl" variant="outline" @click="rtl = !rtl">从右向左</QuireButton>
    </QuireSpace>
    <QuireDescriptions :items="items" :orientation="vertical ? 'vertical' : 'horizontal'" label-width="6em" :dir="rtl ? 'rtl' : 'ltr'" label="归档信息" />
  </div>
</template>
```

## 分隔与密度

`variant="divided"` 为每项添加轻分隔线；默认 `plain` 仅用间距组织。`density="compact"` 收紧条目间距与字号，内部按钮尺寸由按钮自身决定。外围留白由页面或 [Card](/raw/components/card.md) 提供。

### 示例：descriptions/appearance

文件：`appearance.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireDescriptions, QuireSpace } from '@quirekit/ui/vue';
const compact = ref(false);
const items = [{ key: 'format', label: '文件格式', value: 'DOCX' }, { key: 'size', label: '文件大小', value: '2.8 MB' }, { key: 'pages', label: '页数', value: 24 }];
</script>
<template>
  <div class="grid gap-qk-group p-qk-surface" data-descriptions-appearance>
    <QuireSpace><QuireButton :aria-pressed="compact" variant="outline" @click="compact = !compact">紧凑密度</QuireButton></QuireSpace>
    <QuireDescriptions title="plain" :items="items" :density="compact ? 'compact' : 'regular'" />
    <QuireDescriptions title="divided" :items="items" variant="divided" :density="compact ? 'compact' : 'regular'" />
  </div>
</template>
```

## 自定义内容与操作

`label`、`value` 插槽提供当前 `item` 和 `index`，可按 `item.key` 组合状态、复制或链接。`trailing` 插槽放独立标题操作，`title` 插槽定制标题文字；编辑和保存由调用方处理。

### 示例：descriptions/composition

文件：`composition.vue`

```vue
<script setup lang="ts">
import { computed, ref } from 'vue';
import { QuireButton, QuireCard, QuireClipboard, QuireDescriptions, QuireSpace, QuireTag } from '@quirekit/ui/vue';
const archived = ref(false);
const items = computed(() => [
  { key: 'id', label: '文档编号', value: 'QK-2026-0148' },
  { key: 'status', label: '状态', value: archived.value ? '已归档' : '协作中' },
  { key: 'owner', label: '创建人', value: '林晓' },
  { key: 'access', label: '权限', value: '团队可查看' }
]);
</script>
<template>
  <div class="p-qk-surface" data-descriptions-composition>
    <QuireCard>
      <QuireDescriptions :items="items" title="共享文档" :columns="2">
        <template #trailing><QuireButton variant="text" @click="archived = !archived">{{ archived ? '恢复协作' : '归档文档' }}</QuireButton></template>
        <template #value="{ item }">
          <QuireSpace v-if="item.key === 'id'"><span>{{ item.value }}</span><QuireClipboard :value="String(item.value ?? '')" variant="text" mode="icon" /></QuireSpace>
          <QuireTag v-else-if="item.key === 'status'" :color="archived ? 'neutral' : 'success'">{{ item.value }}</QuireTag>
          <span v-else>{{ item.value }}</span>
        </template>
      </QuireDescriptions>
    </QuireCard>
  </div>
</template>
```

## 长值与空内容

普通值按原文显示，长地址和连续字符可换行。`null`、`undefined` 和空字符串使用 `emptyValue`，默认显示 `—`；数字 `0` 正常保留。布尔值请转为明确的业务文案，空数组不会生成虚构条目，需要引导时组合 [EmptyState](/raw/components/empty-state.md)。

### 示例：descriptions/content

文件：`content.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireDescriptions, QuireSpace } from '@quirekit/ui/vue';
import type { QuireKitDescriptionItem } from '@quirekit/ui/vue';
const empty = ref(false);
const items: readonly QuireKitDescriptionItem[] = [
  { key: 'path', label: '完整资源地址', value: 'https://example.com/workspaces/product-design/documents/0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz', span: 'full' },
  { key: 'remaining', label: '未处理批注', value: 0 }, { key: 'owner', label: '归档负责人', value: null },
  { key: 'note', label: '备注', value: '' }, { key: 'literal', label: '原始文本', value: '<document title="项目计划" />' }
];
</script>
<template>
  <div class="grid gap-qk-surface p-qk-surface" data-descriptions-content>
    <QuireSpace><QuireButton :aria-pressed="empty" variant="outline" @click="empty = !empty">{{ empty ? '恢复数据' : '清空数据' }}</QuireButton></QuireSpace>
    <QuireDescriptions :items="empty ? [] : items" empty-value="未设置" label="内容边界" />
    <span v-if="empty" class="text-qk-helper text-qk-text-secondary">暂无属性，可恢复数据继续查看。</span>
  </div>
</template>
```

## API

### QuireDescriptions

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| items | 是 | — | Ordered, uniquely keyed name–value pairs. |
| title | 否 | — | Optional visible heading. |
| titleAs | 否 | "h3" | Native heading level for the optional title. Defaults to h3. |
| label | 否 | — | Accessible list name when there is no visible title. |
| columns | 否 | 2 | Maximum columns; the container admits 2/3/4 at 36/54/72rem. Defaults to 2. |
| orientation | 否 | "horizontal" | Position labels before or above values. Defaults to horizontal. |
| variant | 否 | "plain" | Whitespace grouping or subtle item separators. Defaults to plain. |
| density | 否 | "regular" | Content spacing and typography, independent of nested control sizes. Defaults to regular. |
| labelWidth | 否 | "8em" | Horizontal label track width as CSS length; capped at 40% of each item. Defaults to 8em. |
| emptyValue | 否 | "—" | Text displayed for missing values. Defaults to an em dash. |

**items**

```ts
readonly QuireKitDescriptionItem[]
```

```ts
readonly ({
  /** Stable unique identity, retained across updates and reordering. */
  key: string;
  /** Human-readable name; the label slot may enrich its content. */
  label: string;
  /** Literal value; null, undefined and empty strings use emptyValue. */
  value?: undefined | null | string | number;
  /** Columns occupied, capped by the current responsive count; full starts a new row. */
  span?: undefined | 2 | 1 | 3 | 4 | "full";
})[]
```

**title**

```ts
string | undefined
```

```ts
undefined | string
```

**titleAs**

```ts
"h3" | "h2" | "h4" | "h5" | "h6" | undefined
```

```ts
undefined | "h3" | "h2" | "h4" | "h5" | "h6"
```

**label**

```ts
string | undefined
```

```ts
undefined | string
```

**columns**

```ts
QuireKitDescriptionsColumns | undefined
```

```ts
undefined | 2 | 1 | 3 | 4
```

**orientation**

```ts
"horizontal" | "vertical" | undefined
```

```ts
undefined | "horizontal" | "vertical"
```

**variant**

```ts
"plain" | "divided" | undefined
```

```ts
undefined | "plain" | "divided"
```

**density**

```ts
"regular" | "compact" | undefined
```

```ts
undefined | "regular" | "compact"
```

**labelWidth**

```ts
string | undefined
```

```ts
undefined | string
```

**emptyValue**

```ts
string | undefined
```

```ts
undefined | string
```

#### Events

无。

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| title | 否 | — | Replaces title text within the configured heading. |
| trailing | 否 | — | Independent header actions; no wrapper is created when absent. |
| label | 否 | — | Enriches each item's name without changing dt semantics. |
| value | 否 | — | Replaces each value with consumer-owned content or controls. |

**title**

```ts
any
```

**trailing**

```ts
any
```

**label**

```ts
{ item: QuireKitDescriptionItem; index: number; }
```

```ts
{
  item: {
    /** Stable unique identity, retained across updates and reordering. */
    key: string;
    /** Human-readable name; the label slot may enrich its content. */
    label: string;
    /** Literal value; null, undefined and empty strings use emptyValue. */
    value?: undefined | null | string | number;
    /** Columns occupied, capped by the current responsive count; full starts a new row. */
    span?: undefined | 2 | 1 | 3 | 4 | "full";
  };
  index: number;
}
```

**value**

```ts
{ item: QuireKitDescriptionItem; index: number; }
```

```ts
{
  item: {
    /** Stable unique identity, retained across updates and reordering. */
    key: string;
    /** Human-readable name; the label slot may enrich its content. */
    label: string;
    /** Literal value; null, undefined and empty strings use emptyValue. */
    value?: undefined | null | string | number;
    /** Columns occupied, capped by the current responsive count; full starts a new row. */
    span?: undefined | 2 | 1 | 3 | 4 | "full";
  };
  index: number;
}
```

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitDescriptionItem = {
  /** Stable unique identity, retained across updates and reordering. */
  key: string;
  /** Human-readable name; the label slot may enrich its content. */
  label: string;
  /** Literal value; null, undefined and empty strings use emptyValue. */
  value?: undefined | null | string | number;
  /** Columns occupied, capped by the current responsive count; full starts a new row. */
  span?: undefined | 2 | 1 | 3 | 4 | "full";
};
```
