- Plugins
- Layout Splitter
Plugins
Tailwind CSS Layout Splitter
Customize your layout effortlessly by adjusting block sizes to your preference with Tailwind CSS Layout Splitters.
Installation
To get started, install Layout Splitter plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/layout-splitter
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div data-hs-layout-splitter='{
"horizontalSplitterTemplate": "<div><span class=\"absolute top-1/2 start-1/2 -translate-x-2/4 -translate-y-2/4 block w-[11px] h-[20px] bg-gray-400\"></span></div>",
"horizontalSplitterClasses": "relative flex border-s border-gray-200"
}'>
<div class="flex h-[200px]" data-hs-layout-splitter-horizontal-group>
<div class="h-full" data-hs-layout-splitter-item="48.2">Horizontal Block 1</div>
<div class="h-full" data-hs-layout-splitter-item="30.0">Horizontal Block 2</div>
</div>
</div>
Methods
The HSLayoutSplitter
object is contained within the global window
object
Set different size on window resize.
let layoutSplitter = HSLayoutSplitter.getInstance('#layout-splitter', true);
const updateLayoutSplitter = (splitter) => {
splitter.updateFlexValues([
{
id: "section-01",
breakpoints: {
"0": 0,
"1280": 15.0
}
},
{
id: "section-02",
breakpoints: {
"0": 0,
"1024": 25.4,
"1280": 21.0
}
},
{
id: "section-03",
breakpoints: {
"0": 100,
"1024": 74.6,
"1280": 64.0
}
}
]);
};
window.addEventListener('resize', () => {
if (layoutSplitter) updateLayoutSplitter(layoutSplitter.element);
});
Get instance by ID.
const layoutSplitter = new HSLayoutSplitter(document.querySelector('#layout-splitter'));
console.log("Instance:", layoutSplitter);
Events
Adds classes that can be useful when you need to minimize the sidebar.
const { element } = HSLayoutSplitter.getInstance('#layout-splitter', true);
element.on('onPrevLimit', (prev) => {
prev.classList.add('prev-limit-reached');
});
element.on('onPrevPreLimit', (prev) => {
prev.classList.add('prev-pre-limit-reached');
});
element.on('drag', ({ prev, previousFlexSize }) => {
if (previousFlexSize > 10) {
prev.classList.remove('prev-limit-reached');
}
if (previousFlexSize > 20) {
prev.classList.remove('prev-pre-limit-reached');
}
});
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