Data Display

CopyableValue

A value in monospace, such as an address or an identifier, that breaks after its punctuation when its place is narrow, with a copy control that stays on the value's last line.

import { CopyableValue } from '@lostgradient/cinder';
copyclipboardidentifier
01

Overview

CopyableValue shows a value such as an address or an identifier in monospace, with a copy control after it. The value breaks after a slash, colon, question mark, ampersand or equals sign when its place is narrow, so a host, a port and a path segment stay whole; it breaks after a dot only when one of those parts is longer than the place, and anywhere (overflow-wrap: anywhere) only when a piece between two dots is. Each part and piece is an inline-block with max-inline-size: 100%, the technique CodeBlock draws its flags with, so the browser's own break after a hyphen never splits one. The copied text is the value as given. The control is drawn quiet and bare, as CodeBlock draws its copy button, and stays on the value's last line, because the last character and the control are one stretch that never breaks. A CopyButton placed beside a code element wraps as two parts, so the button can land alone on a row while the value breaks above it.

The component is inline: put it in a sentence, after the words that name the value ("Deliveries go to"), and it flows with them. value is both what is shown and what is copied. Name the control with label and say what was copied with copiedLabel; other attributes, such as data-testid, land on the outer element.

Usage

svelte
<script lang="ts">
  import { CopyableValue } from '@lostgradient/cinder';
</script>

<p>
  Deliveries go to
  <CopyableValue
    value="https://example.com/triggers/nightly-digest"
    label="Copy the address"
    copiedLabel="Address copied"
  />
</p>
02

When to use

Use when
  • Showing an address or identifier a person copies, in a place that can be narrow, so its copy control never sits alone on a row.
Avoid when
  • Showing a snippet or several lines of code — use code-block.
  • Offering a copy control with no value beside it — use copy-button.
03

Props

Props for copyable-value
Name
Type
Default
Description
value required text The text shown, in monospace, and the text the copy control writes to the clipboard, such as an address or an identifier.
label text Accessible name of the copy control, also its tooltip. Defaults to "Copy to clipboard".
copiedLabel text What is announced once the copy succeeds. Defaults to "Copied"; say what was copied when label does ("Address copied").