Components
Split Layout
A main pane with a secondary aside that stacks on small screens.
Installation
$ npx veil-ui@latest add split-layoutUsage
import { SplitLayout } from "@/components/ui/split-layout";
<SplitLayout aside={<TableOfContents />}>
<Article />
</SplitLayout>;Examples
Aside at the end
Article
The main pane grows to fill the remaining space.
Aside at the start
Content with a narrow leading aside.
Sticky aside
Section 1
Section 2
Section 3
Section 4
Section 5
Section 6
Below the lg breakpoint the panes stack in DOM order.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| aside | React.ReactNode | — | Secondary pane content. |
| asidePosition | "start" | "end" | "end" | Which side the aside sits on at lg and up. |
| asideSize | "sm" | "md" | "lg" | "md" | Aside width: 240, 320 or 400px. |
| gap | "none" | "sm" | "md" | "lg" | "md" | Space between the panes. |
| stickyAside | boolean | false | Keep the aside visible while the main pane scrolls. |
| ...props | React.ComponentProps<"div"> | — | All native div attributes. |
Accessibility
- The aside renders as an
asidelandmark; give it a label when the page has more than one. - DOM order follows
asidePosition; choose the position that matches the reading order you want on mobile.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add split-layout --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed } from "vue";
import { cn } from "@/lib/utils";
const grids = {
start: {
sm: "lg:grid-cols-[240px_1fr]",
md: "lg:grid-cols-[320px_1fr]",
lg: "lg:grid-cols-[400px_1fr]",
},
end: {
sm: "lg:grid-cols-[1fr_240px]",
md: "lg:grid-cols-[1fr_320px]",
lg: "lg:grid-cols-[1fr_400px]",
},
} as const;
const gaps = {
none: "gap-0",
sm: "gap-4",
md: "gap-6",
lg: "gap-8",
} as const;
const props = withDefaults(
defineProps<{
asidePosition?: "start" | "end";
asideSize?: "sm" | "md" | "lg";
gap?: keyof typeof gaps;
stickyAside?: boolean;
class?: string;
}>(),
{
asidePosition: "end",
asideSize: "md",
gap: "md",
stickyAside: false,
},
);
const classes = computed(() =>
cn(
"grid min-h-0 grid-cols-1",
grids[props.asidePosition][props.asideSize],
gaps[props.gap],
props.class,
),
);
const asideClasses = computed(() =>
cn(
"min-w-0",
props.stickyAside && "lg:sticky lg:top-4 lg:self-start",
),
);
</script>
<template>
<div data-slot="split-layout" :class="classes">
<aside
v-if="props.asidePosition === 'start'"
data-slot="split-layout-aside"
:class="asideClasses"
>
<slot name="aside" />
</aside>
<div data-slot="split-layout-main" class="min-w-0">
<slot />
</div>
<aside
v-if="props.asidePosition === 'end'"
data-slot="split-layout-aside"
:class="asideClasses"
>
<slot name="aside" />
</aside>
</div>
</template>