You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
543 B
18 lines
543 B
import { Controller } from '@hotwired/stimulus'; |
|
|
|
export default class extends Controller { |
|
static targets = ["copyButton", "textToCopy"]; |
|
|
|
copyToClipboard(event) { |
|
event.preventDefault(); |
|
const text = this.textToCopyTarget.textContent; |
|
navigator.clipboard.writeText(text).then(() => { |
|
this.copyButtonTarget.textContent = "Copied!"; |
|
setTimeout(() => { |
|
this.copyButtonTarget.textContent = "Copy to Clipboard"; |
|
}, 2000); |
|
}).catch(err => { |
|
console.error('Failed to copy: ', err); |
|
}); |
|
} |
|
}
|
|
|