For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/components/copy-button.md.

复制按钮

复制代码、命令或标识符,并在同一操作位置提供进行中、成功和失败反馈。

安装命令
空内容拒绝

用法

<button
  type="button"
  class="btn copy-button"
  data-copy-text="npm install @a3s-lab/ui"
  data-copy-success="已复制"
  data-copy-error="复制失败"
  data-copy-reset="1600"
>
  <span data-copy-label>复制命令</span>
  <span data-copy-feedback aria-live="polite"></span>
</button>

当 data-state="copying" / aria-busy="true" 时,重复激活会被忽略。空来源会进入 error 且不写入剪贴板。data-copy-reset 在成功反馈后回到 ready。

独立控制器

import "@a3s-lab/ui/runtime";
import "@a3s-lab/ui/copy-button";

const component = document.querySelector(".copy-button");
component.getState();

控制器是幂等的;完整包可改为一次导入 @a3s-lab/ui/all。宿主通过可取消的 before-* 事件执行权限与业务校验。

契约

接口值
根选择器.copy-button
原生根元素<button>
状态ready, copying, copied, error, disabled
事件a3s:copy-before, a3s:copy-error, a3s:copy-success
方法copy, getState, setSource

产品边界

复制不得伪装成下载、分享或授权。敏感值由宿主显式提供;组件不会自行读取剪贴板或受保护数据。

组件只发布可复用的交互边界。数据获取、持久化、权限、可信内容与业务实体继续由宿主产品拥有。

无障碍

键盘 Enter/Space 激活原生按钮。反馈通过 aria-live 留在同一控件内。复制中通过 busy 状态播报且不改变控件几何;成功与失败用文字表达,而不是只靠颜色。