# 何时使用

- 需要多行输入、对话输入框场景
- 需要联网搜索、深度思考等功能开关条，或附件（相机/相册/文件）上传
- 需要按住说话、语音转文字等与 `SpeechToText` 集成的能力
- 不适用：仅需单行极简输入时可优先使用 `Input`

---

# API

| 属性           | 类型                                         | 是否必传 | 默认值  | 说明                                                         |
| -------------- | -------------------------------------------- | -------- | ------- | ------------------------------------------------------------ |
| allowFunction  | `false` \| `FunctionProps`                   | 否       | `true`  | 功能列表（联网搜索、深度思考等），传 `false` 关闭            |
| allowAudio     | `boolean` \| `SpeechToTextBaseProps`         | 否       | `false` | 语音输入；可传配置对象，见下文子表                         |
| allowAffix     | `false` \| `AffixProps`                      | 否       | `false` | 附件上传能力，见下文子表                                   |
| loading        | `boolean`                                    | 否       | `false` | 加载状态（搜索模式下有效）                                 |
| bordered       | `boolean`                                    | 否       | `false` | 是否显示边框                                               |
| suffix         | `React.ReactNode`                            | 否       | -       | 后置自定义元素                                             |
| search         | `boolean`                                    | 否       | `false` | 搜索模式，展示发送等交互                                   |
| onSearch       | `(value: string) => void`                    | 否       | -       | 搜索提交回调                                               |
| onPauseLoading | `() => void`                                 | 否       | -       | 暂停加载（配合 `loading`）                                 |

更多属性参考 [Ant Design Mobile 的 TextArea 组件](https://mobile.ant.design/zh/components/text-area)（本组件对 `prefix` 等做了定制，以类型定义为准）。

## 功能列表 FunctionProps

| 属性      | 类型                          | 默认值 | 说明                                       |
| --------- | ----------------------------- | ------ | ------------------------------------------ |
| functions | `boolean` \| `FunctionConfig[]` | `true` | `true` 为默认功能集；也可传入自定义列表 |
| onChange  | `(value: Partial<Record<string, boolean>>) => void` | - | 各功能开关变化回调                         |

### FunctionConfig

| 属性     | 类型                                      | 说明           |
| -------- | ----------------------------------------- | -------------- |
| name     | `string`                                  | 功能唯一标识   |
| text     | `string`                                  | 展示文案       |
| icon     | `keyof typeof Icons` \| `React.ReactElement` | 图标（sofa-icons 名或元素） |
| disabled | `boolean`                                 | 是否禁用       |

## 附件 AffixProps

| 属性             | 类型                          | 说明                                                         |
| ---------------- | ----------------------------- | ------------------------------------------------------------ |
| value            | `File[]`                      | 受控附件列表                                                 |
| affix            | `boolean` \| `AffixType[]`    | `AffixType`: `camera` \| `gallery` \| `file`；`true` 为全部 |
| affixContainer   | `HTMLElement` \| `string`     | 附件区域挂载容器                                           |
| previewContainer | `HTMLElement` \| `string`     | 预览列表挂载容器                                           |
| onChange         | `(files: File[]) => void`     | 附件变化                                                   |
| onFilePreview    | `(file: File) => void`        | 非图片文件点击预览                                         |

## 语音 SpeechToTextBaseProps（allowAudio 为对象时）

| 属性                 | 类型                                                                 | 默认值                     | 说明                    |
| -------------------- | -------------------------------------------------------------------- | -------------------------- | ----------------------- |
| pressText            | `string`                                                             | `'按住 说话'`              | 空闲态主按钮文案       |
| speechToTextLabel    | `string`                                                             | `'语音转文字'`             | 转文字按钮文案         |
| cancelLabel          | `string`                                                             | `'取消'`                   | 取消按钮文案           |
| speakingText         | `string`                                                             | `'请说话'`                 | 未检测到说话时提示     |
| recordingText        | `string`                                                             | `'松手发送'`               | 检测到说话后提示       |
| willCancelText       | `string`                                                             | `'松开取消'`               | 滑入取消区提示         |
| willSpeechToTextText | `string`                                                             | `'松手转文字'`             | 滑入转文字区提示       |
| countdownText        | `string`                                                             | `'{seconds}s后将停止录音'` | 支持 `{seconds}` 占位  |
| onCancel             | `() => void`                                                         | -                          | 取消录音               |
| onChange             | `(blob: Blob, type: 'send' \| 'speechToText') => void`               | -                          | 松手发送或转文字结果   |
| waveProps            | `Omit<WaveProps, 'source' \| 'className'>`                          | -                          | 音波条配置             |
| waveContainerClassName | `string`                                                          | -                          | 音波容器类名           |
| showHalo             | `boolean`                                                            | `true`                     | 是否显示 Halo 光圈     |
| style                | `React.CSSProperties`                                                | -                          | 样式                   |
| onVibrate            | `(type?: 'countdown' \| 'timeout' \| 'cancel') => void`              | `navigator.vibrate`        | 震动回调               |
| onStreamChange       | `(stream: MediaStream \| null) => void`                              | -                          | 音频流变化             |
| onRecordingStateChange | `(state: RecordingState) => void`                                  | -                          | 录音状态，`RecordingState` 含 `idle` \| `recording` \| `willCancel` \| `willSpeechToText` |

---

# FAQ

- 语音能力依赖浏览器麦克风权限；生产环境需 HTTPS 等安全上下文。
- `allowAudio` 与 `Input` 的 `AudioInputBaseProps` 不同：多行场景使用 `SpeechToText` 流程与双通道文案（发送 / 转文字）。
