Getting started
Getting started
Install the package, import the stylesheet once, then turn any button into a copy button.
Install
npm install @reuse-sh/interactionsUse it
The browser module works without a framework. In React, the component creates the same controller when it mounts and destroys it when it unmounts.
import { createCopyButton } from "@reuse-sh/interactions";
import "@reuse-sh/interactions/styles.css";
// <button class="copy" aria-label="Copy command"></button>
const copy = createCopyButton(document.querySelector(".copy"), {
text: "npm install @reuse-sh/interactions",
});
// Later, when the button leaves the page
copy.destroy();import { CopyButton } from "@reuse-sh/interactions/react";
import "@reuse-sh/interactions/styles.css";
export function ShareLink({ url }) {
return <CopyButton text={url}>Copy link</CopyButton>;
}Read https://reuse.sh/copy-button/guide.md, install @reuse-sh/interactions and add Copy button to <where>. Keep the principles the guide lists.