UNPKG

drab

Version:

Interactivity for You

27 lines (26 loc) 613 B
import { Base } from "../index.js"; export class BaseCopy extends Base { constructor() { super(); } /** * The value to copy or share. * * @default "" the empty string */ get value() { return this.getAttribute("value") ?? ""; } set value(value) { this.setAttribute("value", value); } /** * Copies the `text`. * @param text The `text` to share */ async copy(text = this.value) { this.announce(`copied ${text} to clipboard`); await navigator.clipboard.writeText(text); this.swapContent(); } }