附件与移除确认

AttachmentList

交互预览

  • 交接清单.md12 KB
  • 工作区草图.pdf320 KB

移除附件?

「」将从这条消息中移除,原文件仍保留。

用法

将多个附件作为一组呈现。

import { AttachmentList, AttachmentItem } from 'nibferry';

<AttachmentList aria-label="待发送附件"><AttachmentItem name="会议纪要.md" /></AttachmentList>

参数与交互

children 通常为 AttachmentItem。通过 aria-label 命名列表,透传 ul 的其他属性和 ref。附件顺序由接入方决定。

layout="list" 为默认纵向列表。layout="strip" 用于聊天草稿和已发消息,所有卡片在同一行横向滚动。--nf-attachment-card-size 控制卡片边长,默认 122px。

附件项 AttachmentItem

显示文件名、说明与可选操作。

import { AttachmentItem } from 'nibferry';

<AttachmentItem name="设计稿.pdf" detail="上传中" onOpen={preview} onRemove={remove} />

参数与交互

name 为文件名,icon 可替换文件图标,detail 接收大小、传输状态或自定义内容。传入 onOpen 或 onRemove 时显示对应按钮。上传、删除和确认流程由宿主管理。

在 AttachmentList layout="strip" 中,preview 可以传图片或文档首页。图片卡使用 imageOnly 铺满缩略图,文件名仍作为可访问名称。文档卡保留底部图标与文件名。移除按钮在悬停、键盘焦点进入卡片或触屏时显示,点击与打开文件是独立操作。

可用 transfer={{ state: 'uploading', progress: 42, onCancel }} 展示上传进度并允许取消,省略 progress 显示不定进度。失败或取消后传 { state: 'failed' | 'cancelled', message, onRetry },完成后移除 transfer。message 和操作回调均可省略。上传和发送策略由宿主持有,同一列表可同时展示不同文件的状态。

附件缩略图 AttachmentThumbnail

在附件预留的位置展示缩略图。图片载入时,取原图的低分辨率采样并过渡到清晰图像。尺寸由预览区域控制。

import { AttachmentItem, AttachmentThumbnail } from 'nibferry';

<AttachmentItem name={file.name} preview={<AttachmentThumbnail src={file.thumbnail} alt="" />} />

接受原生 img 属性,包含 src、alt、onLoad、onError 与 ref。缩略图采用主题 reveal 时长,减少动效时直接显示原图。

确认弹框 AlertDialog

对重要操作进行确认,默认聚焦取消按钮。

import { AlertDialog } from 'nibferry';

<AlertDialog open={open} onOpenChange={setOpen} title="移除附件?"
  description="文件仍保存在工作区。" confirmLabel="移除" destructive onConfirm={removeFile} />

参数与交互

title、description 与 confirmLabel 由接入方提供。取消或 Esc 回调 onOpenChange(false),点击遮罩保留弹框。确认时先调用 onConfirm,再请求关闭。destructive 控制危险操作配色。若操作移除了触发按钮,由接入方为列表选择下一个焦点。