Skip to content

Instantly share code, notes, and snippets.

@jplhomer
Created October 17, 2022 01:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplhomer/0cd773346a84e2ee368a3581c5c114e8 to your computer and use it in GitHub Desktop.
Save jplhomer/0cd773346a84e2ee368a3581c5c114e8 to your computer and use it in GitHub Desktop.
// 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