Skip to main content Sidebar Design tokens Components Layout Style utilities

We’d love to hear from you. Please reach out to us with any questions or inquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Skip to table of contents

The Placer Toolkit alpha has arrived! 🎉
Plenty of changes are coming your way—some big, some breaking, some even nuclear! Beware the changelog…

Bring it on!

    Copy Button

    <pc-copy-button> 0.5.1 experimental

    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

    Properties#

    NameDescriptionReflectsDefault
    valueThe text value to copy.
    Type: 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").
    Type: string
    ""
    disabledDisables the copy button.
    Type: boolean
    false
    copyLabel
    copy-label
    A custom label to show in the tooltip.
    Type: string
    ""
    successLabel
    success-label
    A custom label to show in the tooltip after copying.
    Type: string
    ""
    errorLabel
    error-label
    A custom label to show in the tooltip when a copy error occurs.
    Type: string
    ""
    feedbackDuration
    feedback-duration
    The length of time to show feedback before restoring the default trigger.
    Type: number
    1000
    tooltipPlacement
    tooltip-placement
    The preferred placement of the tooltip.
    Type: "top" | "right" | "bottom" | "left"
    "top"
    updateComplete A read‐only promise that resolves when the component has finished updating.

    Learn more about attributes and properties.

    Slots#

    NameDescription
    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>.

    Learn more about using slots.

    Events#

    NameDescriptionEvent detail
    pc-copyEmitted when the data has been copied.
    pc-errorEmitted when the data could not be copied.

    Learn more about events.

    Custom properties#

    NameDescriptionDefault
    --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)

    Learn more about customising custom properties.

    Parts#

    NameDescription
    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.

    Learn more about customising CSS parts.

    Animations#

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

    Learn more about customising animations.

    Importing#

    If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

    CDN (script tag) CDN (import) npm (import)

    To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

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

    To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

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

    To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

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

    Dependencies#

    This component automatically imports these components: