Usage
Use the Splitter component to display a list of resizable panels separated by draggable handles.
Items
Use the items prop as an array of objects with the following properties:
defaultSize?: numberminSize?: numbermaxSize?: numbercollapsible?: booleancollapsedSize?: numbersizeUnit?: '%' | 'px'order?: numberid?: stringslot?: stringclass?: anyb24ui?: { panel?: ClassNameValue }
Use the slot key to fill the content of a panel and the class key to style it. Items without a slot key fall back to a panel-{index} slot. Sizes are percentages by default, set sizeUnit: 'px' on an item for pixel values.
id prop and give defaultSize to all items or to none. Ids are generated automatically otherwise and the server and the client can disagree, which breaks the layout on hydration. An item without a defaultSize falls back to an equal share on the server, so mixing the two makes panels jump once hydrated. Pixel sizes are measured on the client and always shift a little.<script setup lang="ts">
import type { SplitterItem } from '@bitrix24/b24ui-nuxt'
const items = ref<SplitterItem[]>([
{
slot: 'sidebar',
minSize: 15,
maxSize: 40,
defaultSize: 25,
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
},
{
slot: 'main',
defaultSize: 75,
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
}
])
</script>
<template>
<B24Splitter id="splitter-items" :items="items">
<template #sidebar> Sidebar </template>
<template #main> Main </template>
</B24Splitter>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SplitterItem } from '@bitrix24/b24ui-nuxt'
const items = ref<SplitterItem[]>([
{
slot: 'sidebar',
minSize: 15,
maxSize: 40,
defaultSize: 25,
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
},
{
slot: 'main',
defaultSize: 75,
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
}
])
</script>
<template>
<B24Splitter id="splitter-items" :items="items">
<template #sidebar> Sidebar </template>
<template #main> Main </template>
</B24Splitter>
</template>
Orientation
Use the orientation prop to change the direction of the splitter. Defaults to horizontal.
<script setup lang="ts">
import type { SplitterItem } from '@bitrix24/b24ui-nuxt'
const items = ref<SplitterItem[]>([
{
slot: 'first',
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
},
{
slot: 'second',
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
}
])
</script>
<template>
<B24Splitter id="splitter-orientation" orientation="vertical" :items="items">
<template #first> First </template>
<template #second> Second </template>
</B24Splitter>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SplitterItem } from '@bitrix24/b24ui-nuxt'
const items = ref<SplitterItem[]>([
{
slot: 'first',
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
},
{
slot: 'second',
class:
'bg-(--ui-color-bg-content-secondary) border border-(--ui-color-divider-default) rounded-(--ui-border-radius-md) items-center justify-center text-description font-(--ui-font-weight-medium)'
}
])
</script>
<template>
<B24Splitter id="splitter-orientation" orientation="vertical" :items="items">
<template #first> First </template>
<template #second> Second </template>
</B24Splitter>
</template>
Examples
With collapsible panel
Set collapsible: true on an item to let it collapse past its minSize, and use collapsedSize to keep part of the panel visible when collapsed. The panel slot exposes collapsed, collapse and expand so you can control it programmatically, and the collapse, expand and resize events fire with the panel index.
With nested splitters
Nest a Splitter inside a panel to build two-dimensional, IDE-style layouts.
With custom handle
The handle is invisible by default. Use the b24ui prop to restyle it, for example as a visible divider for flush layouts, and the resize-handle slot to render content inside it like a grip.
With persistence
Provide an auto-save-id to persist the layout to localStorage and restore it on reload.
<template>
<B24Splitter id="my-layout" auto-save-id="my-layout" :items="items">
<!-- ... -->
</B24Splitter>
</template>
API
Props
Slots
Emits
Theme
export default {
slots: {
root: '',
panel: 'flex',
handle: 'group relative shrink-0 outline-transparent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--ui-color-design-outline-focused-stroke) data-[panel-resize-handle-enabled=false]:cursor-default'
},
variants: {
orientation: {
horizontal: {
handle: 'w-2 cursor-col-resize'
},
vertical: {
handle: 'h-2 cursor-row-resize'
}
}
}
}