Zum Hauptinhalt springen Seitenleiste
Auf dieser Seite
Zum Inhaltsverzeichnis springen

Copy Button

<pc-copy-button> 0.5.1 experimental

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Copies text data to the clipboard when the user clicks the trigger.

<pc-copy-button value="Placer Toolkit rocks!"></pc-copy-button>
Code Edit

Copy buttons use the browser’s clipboard.writeText() method, which requires a secure context (HTTPS) in most browsers.

Demos

Custom labels

Copy buttons display feedback in a tooltip. You can customise the labels using the copy-label, success-label and error-label attributes.

Edit

Custom icons

Use the copy-icon, success-icon and error-icon slots to customise the icons that get displayed for each state. You can use <pc-icon> or your own images.

Edit

Copying values from other elements

Normally, the data that gets copied will come from the component’s value attribute, but you can copy data from any element within the same document by providing its id to the from attribute.

When using the from attribute, the element’s textContent will be copied by default. Passing an attribute or property modifier will let you copy data from one of the element’s attributes or properties instead.

To copy data from an attribute, use from="id[attribute]" where id is the id of the target element and attribute is the name of the attribute you’d like to copy. To copy data from a property, use from="id.property" where id is the id of the target element and property is the name of the property you’d like to copy.

Edit

Handling errors

A copy error will occur if the value is an empty string, if the from attribute points to a non‐existent id or if the browser rejects the operation for any reason. When this happens, the pc-error event will be emitted.

This example demonstrates what happens when a copy error occurs. You can customise the error label and icon using the error-label attribute and the error-icon slot, respectively.

Edit

Disabled

Copy buttons can be disabled by adding the disabled attributes.

Edit

Changing feedback duration

A success indicator is briefly shown after copying. You can customise the length of time the indicator is shown using the feedback-duration attribute.

Edit

Custom styles

You can customise the button to your liking with CSS.

Edit

Eigenschaften

NameBeschreibungReflektiertStandard
valueThe text value to copy.
Typ: string
""
fromAn id that references an element in the same document from which data will be copied. If both this and value are present, this value will take precedence. By default, the target element’s textContent will be copied. To copy an attribute, append the attribute name wrapped in square brackets (e.g., from="element[value]"). To copy a property, append a dot and the property name (e.g., from="element.value").
Typ: string
""
disabledDisables the copy button.
Typ: boolean
false
copyLabel
copy-label
A custom label to show in the tooltip.
Typ: string
""
successLabel
success-label
A custom label to show in the tooltip after copying.
Typ: string
""
errorLabel
error-label
A custom label to show in the tooltip when a copy error occurs.
Typ: string
""
feedbackDuration
feedback-duration
The length of time to show feedback before restoring the default trigger.
Typ: number
1000
tooltipPlacement
tooltip-placement
The preferred placement of the tooltip.
Typ: "top" | "right" | "bottom" | "left"
"top"
updateComplete Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde.

Erfahre mehr über Attribute und Eigenschaften.

Slots

NameBeschreibung
copy-iconThe icon to show in the default copy state. Works best with <pc-icon>.
success-iconThe icon to show when the content is copied. Works best with <pc-icon>.
error-iconThe icon to show when a copy error occurs. Works best with <pc-icon>.

Erfahre mehr über die Benutzung von Slots.

Events

NameBeschreibungEvent‐Detail
pc-copyEmitted when the data has been copied.
pc-errorEmitted when the data could not be copied.

Erfahre mehr über Events.

Benutzerdefinierte Eigenschaften

NameBeschreibungStandard
--success-colorThe colour to use for success feedback.var(--pc-color-success-on-quiet)
--error-colorThe colour to use for error feedback.var(--pc-color-danger-on-quiet)

Erfahre mehr über das Anpassen von benutzerdefinierten Eigenschaften.

Parts

NameBeschreibung
buttonThe internal <button> element.
copy-iconThe container that holds the copy icon.
success-iconThe container that holds the success icon.
error-iconThe container that holds the error icon.
tooltip-baseThe tooltip’s base part.
tooltip-base-popupThe tooltip’s popup part.
tooltip-base-arrowThe tooltip’s arrow part.
tooltip-bodyThe tooltip’s body part.

Erfahre mehr über das Anpassen von CSS‐Parts.

Animationen

NameBeschreibung
copy.inThe animation to use when the icons animate in.
copy.outThe animation to use when the icons animate out.

Erfahre mehr über das Anpassen von Animationen.

Importieren

Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.

CDN (Skript‐Tag)CDN (Import)npm (Import)

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in dein HTML einfügen.

<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/copy-button/copy-button.js"></script>

Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/copy-button/copy-button.js";

Um diese Komponente manuell von npm zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.

import "placer-toolkit/dist/components/copy-button/copy-button.js";

Abhängigkeiten

Diese Komponente importiert automatisch folgende Komponenten:

Wir würden uns freuen, von dir zu hören. Kontaktiere uns bitte bei Fragen oder Anliegen, die du hast.

Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

Wir freuen uns darauf, von dir zu hören!

Alles klar!
Gefährliche Lande

Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

Ups! Aufladen!

Unsere Website ist zu 100 % frei von Cookies! Wir legen großen Wert auf deine Privatsphäre und speichern daher keinerlei Cookies oder persönliche Informationen über dich.

Dein Browserverlauf bleibt sauber und deine Daten sind geschützt, ganz im Einklang mit modernen Datenschutzstandards wie der DSGVO. Genieße deinen Besuch ganz ohne digitale Cookies! 🍪🚫

Weitere Informationen findest du in unserer Datenschutzerklärung.

Alles klar!