Clipboard
A pure vanilla JS implementation of Zag JS Clipboard
Anatomy
The Clipboard component consists of the following data-part
root
control
trigger
label
input
indicator
To hide and show the icons on copy state you must add id="clipboard-copy"
and id="clipboard-copied"
to the respective icons
Select the input text and press Ctrl + C to experience the accessibility feature.
Data attributes
Each clipboard can be set with different settings with the following data-attribute.
Callbacks
Each Clipboard component can receive callbacks that can be used to respond to user interaction with custom behavior.
You must add a custom id for the clipboard and a event listener for your event name
document.getElementById("my-callback-clipboard")
?.addEventListener("my-callback-clipboard-event", (event) => {
console.log("Received event:", (event as CustomEvent).detail);
});
Open your browser's console to see the events received when the clipboard is copied
Custom (Tailwind)
If you are using Tailwind styling, you can customize each clipboard and its parts with Tailwind utilities
Templates
Clipboard components is available in the followng templates
-
Corex template
Default corex templates. It provides the global, semantic and components tokens
-
Modex template
Based on Corex default template, it adds dark and light mode option to the tokens
-
Themex template
Based on the Corex default template, it adds theming capabilities as well as light and dark mode options to the tokens.