A button that copies text to the clipboard: @value, or the text of the element whose id is @source. It stays hidden without a script or where the Clipboard API is missing, so it never offers what it can't do. After a click its label reads the copied or failed text for two seconds, the icon turns to a check tinted in the success color, and a status message says the same to a screen reader. The button keeps its width, since the three texts share one cell. The texts are in the page, hidden, and the script shows them: the button only exists with a script.
<norn-copy-button>
a component, from
@allons-y/webc-patterns
Copy {name} to clipboardCopyCopiedCopy failedhtml code
Props
Write them with the @ prefix, and :@ for an expression.
Name
Type
Description
@value
string
The text to copy.
@source
string
The id of the element whose text to copy, when there is no value.
@compact
boolean
Show only the icon until the pointer or focus is on the button, for a button laid over a corner, as norn-code-block does. On for @compact, @compact="true", or :@compact="true".
@surface
string
base, raised, or code: fill the button with that surface token, for a button laid over it, as norn-code-block does with code. Without it the button has no fill and sits on its surroundings.
@strings
string
The id of an element that holds the texts in place of the slots, for a component that wraps the button, as norn-code-block does. It holds one element per slot, marked data-string="label", "copy", "copied", and "failed"; the label one needs an id.
Slots
Name
Description
label
The button's accessible name, such as "Copy the install command", as one element. Without it, the visible text names the button.
copy
The visible text, as one element. Falls back to the site's componentStrings, then "Copy".
copied
The text after a copy. Falls back to the site's componentStrings, then "Copied".
failed
The text when the copy fails. Falls back to the site's componentStrings, then "Copy failed".
Tokens
The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.
Type a value to try it in every example above. Reset puts the default back.
Token
Type
Default
Override
--norn-ui-accentThe brand color, shared by every component.
<color>
#2346d4
--norn-ui-border-radiusCorner radius.
<length>
6px
--norn-ui-state-hoverShare of the text color mixed into the background while the pointer is over a control.
<percentage>
8%
--norn-ui-state-pressShare of the text color mixed into the background while a control is pressed, and of the accent on a selected or current item.
<percentage>
12%
--norn-ui-motion-durationLength of a state change, such as a hover layer.
<time>
150ms
--norn-ui-motion-easingEasing for every transition.
<easing-function>
cubic-bezier(0.2, 0, 0, 1)
--norn-ui-control-heightHeight of a button, field, or tab. A component raises it to 2.75rem for a coarse pointer.
<length>
2.25rem
--norn-surface-basePage surface. Light and dark values.
<color>
light-dark(#ffffff, #101216)
--norn-surface-raisedRaised surface.
<color>
light-dark(hsl(40, 14%, 96%), #242932)
--norn-surface-codeCode surface.
<color>
light-dark(hsl(40, 14%, 94%), #2c313b)
--norn-text-mutedSecondary text color.
<color>
light-dark(#4b5160, #a4abba)
--norn-font-size-sSmall text: captions, code, navigation, and notes.
<length>
0.875rem
--norn-space-2xsSmallest spacing step.
<length>
0.25rem
--norn-space-xsExtra small spacing step.
<length>
0.5rem
--norn-status-successSuccess. The color of a tip, a success notice, and a copied mark.
<color>
light-dark(#0b6b3a, #7ed6a1)
--norn-status-dangerDanger. The color of a caution and an error.