文件状态#

点击附件依次查看完成、上传、处理和错误状态。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
file := tree.ID(page, "file")
card := components.BeginAttachment(canvas, theme, file, bounds,
    components.AttachmentData{
        Name: "product-demo.mov", Description: descriptions[index],
        Kind: components.AttachmentFile, State: states[index], Progress: 0.64,
    })
card.Paint()
if canvas.Clicked(file) {
    index = (index + 1) % len(states)
}

尺寸与方向#

展示小型文件与竖向图片附件。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
components.BeginAttachment(canvas, theme, tree.ID(page, "notes"), bounds,
    components.AttachmentData{
        Name: "release-notes.md", Description: "18 KB · Markdown",
        Kind: components.AttachmentFile, State: components.AttachmentDone,
        Size: components.AttachmentSizeSmall,
    }).Paint()
components.BeginAttachment(canvas, theme, tree.ID(page, "cover"), cover,
    components.AttachmentData{
        Name: "cover.png", Description: "1200 × 1200", Kind: components.AttachmentImage,
        Orientation: components.AttachmentVertical,
    }).Paint()

操作与分组#

附件上的删除、重试按钮,以及一行并排的附件组。

启用 JavaScript 后可运行预览;源码和安装命令仍可直接查看。

用法
group := components.BeginAttachmentGroup(theme, bounds)
for index, data := range attachments {
    card := components.BeginAttachment(canvas, theme, items.At(index), ui.Rect{}, data)
    card = card.Action(components.AttachmentAction{
        ID: remove.At(index), Label: "Remove " + data.Name, Icon: crossIcon,
    })
    if group.Fits(card.Size()) {
        card.PaintIn(&group)
    }
}
failedCard := components.BeginAttachment(canvas, theme, failedID, cover, failed)
failedCard.Action(components.AttachmentAction{ID: retryID, Label: "Retry"}).Paint()

安装

将组件源码复制到自己的项目,直接修改。

仓库命令
go run ./cmd/viva add --out ./components/local attachment

源码组件用法#

此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。

  • 标题旁的源码链接列出了全部选项与视觉决策。
  • 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
  • 浏览器预览验证共享布局和场景行为,不代表原生性能。

验证边界#

示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。

键盘操作

Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。