26 lines
907 B
JavaScript
26 lines
907 B
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
export default class extends Controller {
|
|
static targets = ['text'];
|
|
|
|
copy(event) {
|
|
event.preventDefault();
|
|
const text = this.textTarget.getAttribute('data-copy-text-value') || this.textTarget.textContent;
|
|
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
// Feedback visuel : changement temporaire du texte/couleur
|
|
const originalText = this.textTarget.textContent;
|
|
this.textTarget.textContent = '✓ Copié !';
|
|
this.textTarget.classList.add('copied');
|
|
|
|
// Restaurer après 2 secondes
|
|
setTimeout(() => {
|
|
this.textTarget.textContent = originalText;
|
|
this.textTarget.classList.remove('copied');
|
|
}, 2000);
|
|
}).catch(err => {
|
|
console.error('Erreur lors de la copie:', err);
|
|
});
|
|
}
|
|
}
|
|
|