- Plugins
- Overlay
Plugins
Tailwind CSS Overlay
The Overlay Tailwind plugin is an unstyled JavaScript utility for creating modals, drawers, and more, enhancing user interaction and content layout.
Installation
To get started, install Overlay plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/overlay
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<button type="button" aria-haspopup="dialog" aria-expanded="false" aria-controls="hs-unstyled-modal" data-hs-overlay="#hs-unstyled-modal">
Open modal
</button>
<div id="hs-unstyled-modal" class="hs-overlay hidden size-full fixed top-0 start-0 z-[60] overflow-x-hidden overflow-y-auto pointer-events-none" role="dialog" tabindex="-1" aria-labelledby="hs-unstyled-modal-label">
<div class="hs-overlay-open:opacity-100 hs-overlay-open:duration-500 opacity-0 transition-all sm:max-w-lg sm:w-full m-3 sm:mx-auto">
<div class="pointer-events-auto">
<h3 id="hs-unstyled-modal-label">Title</h3>
Modal content
</div>
</div>
</div>
Methods
The HSOverlay
object is contained within the global window
object
Open item (public method).
const modal = new HSOverlay(document.querySelector('#modal'));
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
modal.open();
});
Open item (static method).
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
HSOverlay.open('#modal');
});
Open item (mixed).
const { element } = HSOverlay.getInstance('#modal', true);
const openBtn = document.querySelector('#open-btn');
openBtn.addEventListener('click', () => {
element.open();
});
Events
Open any modal event example.
const el = HSOverlay.getInstance('[data-hs-overlay="#modal"]', true);
el.element.on('open', (instance) => {...});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Check out Preline UI Components