Veil UI
Components

Sidebar Layout

Documentation-style layout with a sticky sidebar and content column.

Installation

$ npx veil-ui@latest add sidebar-layout

Usage

import { SidebarLayout } from "@/components/ui/sidebar-layout";

<SidebarLayout sidebar={<DocsNav />} header={<h1>Theming</h1>}>
  <DocsContent />
</SidebarLayout>;

Examples

Basic

Introduction

The content column flows next to a sticky sidebar.

With header

Theming

Use the header slot for the page title and actions.

End-aligned asides work well for table-of-contents panes.

Unlike AppShell, this layout is page-level: it constrains width, adds padding and does not force a viewport height.

API reference

PropTypeDefaultDescription
sidebarReact.ReactNode—Sidebar content.
headerReact.ReactNode—Optional content above the main column.
footerReact.ReactNode—Optional content below the main column.
sidebarPosition"start" | "end""start"Sidebar side at lg and up.
sidebarSize"sm" | "md" | "lg""md"Sidebar width: 220, 260 or 300px.
stickySidebarbooleantrueKeep the sidebar visible while reading.
...propsReact.ComponentProps<"div">—All native div attributes.

Accessibility

  • The sidebar renders as an aside; label it when it acts as navigation.
  • The layout stacks on small screens. Move the same links into a collapsible menu on mobile.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add sidebar-layout --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import { cn } from "@/lib/utils";

const columns = {
  start: {
    sm: "lg:grid-cols-[220px_1fr]",
    md: "lg:grid-cols-[260px_1fr]",
    lg: "lg:grid-cols-[300px_1fr]",
  },
  end: {
    sm: "lg:grid-cols-[1fr_220px]",
    md: "lg:grid-cols-[1fr_260px]",
    lg: "lg:grid-cols-[1fr_300px]",
  },
} as const;

const props = withDefaults(
  defineProps<{
    sidebarPosition?: "start" | "end";
    sidebarSize?: "sm" | "md" | "lg";
    stickySidebar?: boolean;
    class?: string;
  }>(),
  {
    sidebarPosition: "start",
    sidebarSize: "md",
    stickySidebar: true,
  },
);

const classes = computed(() =>
  cn(
    "mx-auto grid w-full max-w-7xl grid-cols-1 gap-8 px-4 py-8 sm:px-6",
    columns[props.sidebarPosition][props.sidebarSize],
    props.class,
  ),
);

const asideClasses = computed(() =>
  cn(
    "min-w-0",
    props.stickySidebar && "lg:sticky lg:top-8 lg:self-start",
  ),
);
</script>

<template>
  <div data-slot="sidebar-layout" :class="classes">
    <aside
      v-if="props.sidebarPosition === 'start'"
      data-slot="sidebar-layout-sidebar"
      :class="asideClasses"
    >
      <slot name="sidebar" />
    </aside>
    <div data-slot="sidebar-layout-content" class="min-w-0">
      <div v-if="$slots.header" data-slot="sidebar-layout-header" class="mb-6">
        <slot name="header" />
      </div>
      <slot />
      <div v-if="$slots.footer" data-slot="sidebar-layout-footer" class="mt-8">
        <slot name="footer" />
      </div>
    </div>
    <aside
      v-if="props.sidebarPosition === 'end'"
      data-slot="sidebar-layout-sidebar"
      :class="asideClasses"
    >
      <slot name="sidebar" />
    </aside>
  </div>
</template>

On this page