logo dile-components dile-components

dile-copy-text

Web Component that provides a clickable link to copy text to the clipboard with visual feedback.

Installation

npm i @dile/ui

Usage

Import the component

import '@dile/ui/components/copy-text/copy-text.js';

Use the component

<dile-copy-text content="Text to copy">
  Click to copy
</dile-copy-text>

Slots

This component has one slot.

Properties

Events

element.addEventListener('dile-text-copied', (e) => {
  console.log('Copied:', e.detail.text);
});

CSS Custom Properties

You can customize it using CSS Custom Properties.

Custom property Description Default
--dile-copy-text-color Link text color inherit
--dile-copy-text-text-decoration Link text decoration none
--dile-copy-text-hover-color Link color on hover #0066cc
--dile-copy-text-hover-text-decoration Link text decoration on hover underline
--dile-copy-text-focus-outline Link focus outline 2px solid #0066cc
--dile-copy-text-transition-duration Animation duration 0.3s

dile-copy-text demos

Basic usage

Click to copy
<script type="module">
  import '@dile/ui/components/copy-text/copy-text.js';
</script>
<dile-copy-text content="Hello, World!">
  Click to copy
</dile-copy-text>

Copy email address

Copy contact@example.com
<style>
  dile-copy-text {
    --dile-copy-text-color: #0066cc;
    --dile-copy-text-hover-color: #004499;
  }
</style>
<dile-copy-text content="contact@example.com">
  <dile-button>Copy contact@example.com</dile-button>
</dile-copy-text>

With custom feedback text

Copy this
<dile-copy-text content="Custom text" feedbackText="✅ Copied to clipboard!">
  Copy this
</dile-copy-text>

Without icon feedback

Copy without icon
<dile-copy-text content="No icon feedback" hideIcon>
  Copy without icon
</dile-copy-text>

Styled variant

🎯 Copy styled
<style>
  .styled-copy {
    --dile-copy-text-color: #28a745;
    --dile-copy-text-hover-color: #1e7e34;
    --dile-copy-text-hover-text-decoration: none;
    --dile-copy-text-transition-duration: 0.15s;
    font-weight: 500;
  }
</style>
<dile-copy-text content="Copy this styled text" class="styled-copy">
  🎯 Copy styled
</dile-copy-text>