<script>
  /** @extends {"../Copy/Copy"} CopyProps */

  /** Set the title and ARIA label for the copy button */
  export let iconDescription = "Copy to clipboard";

  /**
   * Specify the text to copy
   * @type {string}
   */
  export let text = undefined;

  import Copy from "../Copy/Copy.svelte";
  import Copy16 from "carbon-icons-svelte/lib/Copy16/Copy16.svelte";
  import copy from "clipboard-copy";
  import { createEventDispatcher } from "svelte";

  const dispatch = createEventDispatcher();
</script>

<Copy
  class="bx--copy-btn"
  aria-label="{iconDescription}"
  title="{iconDescription}"
  {...$$restProps}
  on:click
  on:click="{() => {
    if (text !== undefined) {
      copy(text);
      dispatch('copy');
    }
  }}"
  on:animationend
>
  <Copy16 class="bx--snippet__icon" />
</Copy>
