行内复制文本
@cloudflare/kumo
import { InlineCopyText } from "@cloudflare/kumo";

/** Compact copy control for a short identifier. */
export function InlineCopyTextBasicDemo() {
  return (
    <InlineCopyText
      labels={{ copyAction: "Copy database ID", copied: "Database ID copied" }}
    >
      f86b3f10-32e9-4db7-ae95-84a1b2c3d4e5
    </InlineCopyText>
  );
}

安装

桶式导出

import { InlineCopyText } from "@cloudflare/kumo";

细粒度导入

import { InlineCopyText } from "@cloudflare/kumo/components/inline-copy-text";

用法

在表格单元格等密集型界面中,使用 InlineCopyText 展示较短的标识符与值。当值需要显示在只读、类似输入框的字段中并带有常驻复制按钮时,请使用 ClipboardText。

import { InlineCopyText } from "@cloudflare/kumo";

export default function Example() {
  return (
    <InlineCopyText
      labels={{ copyAction: "Copy database ID", copied: "Database ID copied" }}
    >
      f86b3f10-32e9-4db7-ae95-84a1b2c3d4e5
    </InlineCopyText>
  );
}

示例

资源行

外层添加 Tailwind group 后,当整行被悬停或其中获得焦点时,可显示复制图标。

Production database
import { InlineCopyText } from "@cloudflare/kumo";

/** Inline copy text inside a dense, hoverable resource row. */
export function InlineCopyTextResourceRowDemo() {
  return (
    <div className="group flex w-full max-w-xl items-center justify-between gap-4 rounded-lg bg-kumo-base px-4 py-3 ring ring-kumo-line">
      <span className="min-w-0 truncate text-sm text-kumo-default">
        Production database
      </span>
      <InlineCopyText
        labels={{
          copyAction: "Copy database ID",
          copied: "Database ID copied",
        }}
      >
        f86b3f10-32e9-4db7-ae95-84a1b2c3d4e5
      </InlineCopyText>
    </div>
  );
}

富内容

默认情况下复制的是字符串子内容。当子内容不是字符串时,请通过必需的 value prop 提供要复制的值。InlineCopyText 也接受 variant、size、bold、truncate、as 等 Text prop;不支持标题变体。

import { InlineCopyText } from "@cloudflare/kumo";

/** Display rich content while copying its underlying value. */
export function InlineCopyTextRichContentDemo() {
  return (
    <InlineCopyText
      value="f86b3f10-32e9-4db7-ae95-84a1b2c3d4e5"
      variant="body"
      labels={{ copyAction: "Copy database ID", copied: "Database ID copied" }}
    >
      <span>
        Database ID: <strong>f86b3f10…</strong>
      </span>
    </InlineCopyText>
  );
}

API 参考

PropTypeDefaultDescription
labelsInlineCopyTextLabels-

用于本地化的无障碍标签。

childrenReactNode-

要显示的内容。除非提供了 value,否则字符串子元素会被复制。

valuestring-

要复制的内容。当 children 不是字符串时为必填项。

size"xs" | "sm" | "base" | "lg"-

文本大小。支持的值取决于文本变体。

boldboolean-

是否使用中等字重。仅适用于正文文本变体。

as"h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "label" | "dt" | "dd" | "li" | "figcaption" | "legend" | "pre" | "code" | "em" | "strong" | "small" | "abbr" | "time"-

要渲染的 HTML 元素。支持标题("h1"–"h6")、块级文本("p", "pre")、行内文本("span", "code", "em", "strong", "small", "abbr", "time")、表单相关("label", "legend")、列表/定义("dt", "dd", "li")和 "figcaption"。

  • 可选:对于 "heading"(默认值为 "span"),传入反映该文本在文档大纲中所处位置的标题元素。
  • 必需:对于已弃用的标题变体("heading1", "heading2", "heading3")。
  • 可选:对于正文变体(默认值为 "p")和等宽变体(默认值为 "span")。
truncateboolean-

是否用省略号截断溢出的文本。添加 truncate min-w-0 类。

disabledboolean--
namestring--
type"submit" | "reset" | "button"--
classNamestring--
idstring--
langstring--
titlestring--
variant"body" | "secondary" | "success" | "error" | "mono" | "mono-secondary""mono-secondary"

文本样式变体。支持除标题变体外的所有 Text 变体。