﻿# nf-text-overflow {#text-overflow}

多行文本折叠，支持富文本插槽、响应式测量和八种语言的展开／收起文案。

导入组件后使用；单包安装方式见本包 README。

## 示例 {#examples}

### 基础用法 {#example-1}

### 基础用法
```vue
<script setup>
import { ref } from 'vue'
import { NfConfigProvider, NfTextOverflow } from '@94ai-plus/common-ui'
const content = 'Vue 3 and Element Plus provide reusable components. '.repeat(20)
const expanded = ref(false)
</script>

<template>
  <NfConfigProvider theme="chalk" locale="zh-CN">
    <NfTextOverflow :content="content" :rows="2" :row-height="22" style="max-width:420px" @click-action="event => expanded = event.expanded" />
    <output>expanded: {{ expanded }}</output>
  </NfConfigProvider>
</template>
```

### 更多用法 2 {#example-2}

### 更多用法 2
```vue
<script setup>
import { NfConfigProvider, NfTextOverflow } from '@94ai-plus/common-ui'
</script>

<template>
  <NfConfigProvider theme="chalk" locale="zh-CN">
    <NfTextOverflow :rows="2" expand-text="Read more" collapse-text="Read less" style="max-width:320px">
      <p style="margin:0"><strong>Rich content: </strong><span v-for="i in 20" :key="i">Section {{ i }}. </span><a href="https://vuejs.org/" target="_blank" rel="noopener noreferrer">Vue documentation</a></p>
    </NfTextOverflow>
  </NfConfigProvider>
</template>
```

## 属性 {#props}

文案属性未传时跟随组件库当前语言；下表列出本语言的默认文案。

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| --- | --- | --- | --- | --- |
| `rows` | 收起时展示的行数。 | `number \| string` | — | `1` |
| `row-height` | 行高，单位 px。 | `number \| string` | — | `20` |
| `content` | 需要展示的文本；默认插槽存在时优先使用插槽内容。 | `string` | — | `''` |
| `expand-text` | 定制“展开”文案。 | `string` | — | `展开` |
| `collapse-text` | 定制“收起”文案。 | `string` | — | `收起` |

## 事件 {#events}

| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| `click-action` | 点击展开／收起时触发；参数包含原始鼠标事件和展开状态。 | `({ event: MouseEvent, expanded: boolean })` |

## 插槽 {#slots}

| 参数 | 说明 | 回调参数 |
| --- | --- | --- |
| `default` | 自定义展示的文本或富文本内容，优先于 content。 | — |

## 方法 {#methods}

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `init()` | `void` | Schedule a new overflow measurement. |

## 迁移说明 {#migration}

保留完整文本 DOM，通过高度裁剪替代旧版二分截取字符串；不会插入 HTML。内容、宽度、字体变化后自动重算；展开／收起按钮支持键盘操作。
