Created
October 17, 2022 01:21
-
-
Save jplhomer/0cd773346a84e2ee368a3581c5c114e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directive: x-clipboard | |
Alpine.directive('clipboard', async (el, { expression }) => { | |
el.addEventListener('click', async () => { | |
await navigator.clipboard.writeText(expression); | |
document.dispatchEvent( | |
new CustomEvent('banner-message', { detail: { style: 'success', message: 'Copied to clipboard!' } }) | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment