Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Runtime example adjustment

The production sidebar now uses Runtime-backed Sidebar, Collapsible, and Dropdown parts. Account-menu entries are Runtime menu actions instead of legacy polymorphic anchor items.

Sidebars are one of the most complex components to build. They are central to any application and often contain a lot of moving parts.

The Starwind Sidebar is composable, themeable, and customizable.

Info

The Starwind Sidebar is extremely similar to the shadcn/ui sidebar component.

Installation

Framework Availability

Astro Available React Available

Sidebar is available for Astro and React.

Add the following colors to your global CSS file (usually src/styles/starwind.css) if they do not already exist:

Info

They may not exist if you are adding the sidebar to an existing project. For new projects the starwind init command automatically adds this setup.

src/styles/starwind.css
@theme inline {
/* other variables... */
--color-sidebar: var(--sidebar-background);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-outline: var(--sidebar-outline);
}
:root {
/* other variables... */
/* sidebar variables */
--sidebar-background: var(--color-neutral-50);
--sidebar-foreground: var(--color-neutral-950);
--sidebar-primary: var(--color-blue-700);
--sidebar-primary-foreground: var(--color-neutral-50);
--sidebar-accent: var(--color-neutral-100);
--sidebar-accent-foreground: var(--color-neutral-900);
--sidebar-border: var(--color-neutral-200);
--sidebar-outline: var(--color-neutral-400);
}
.dark {
/* other variables... */
/* sidebars variables */
--sidebar-background: var(--color-neutral-900);
--sidebar-foreground: var(--color-neutral-50);
--sidebar-primary: var(--color-blue-700);
--sidebar-primary-foreground: var(--color-neutral-50);
--sidebar-accent: var(--color-neutral-800);
--sidebar-accent-foreground: var(--color-neutral-100);
--sidebar-border: var(--color-neutral-800);
--sidebar-outline: var(--color-neutral-600);
}

Structure

A Sidebar component is composed of the following parts:

  • SidebarProvider - Handles collapsible state and keyboard shortcuts
  • Sidebar - The sidebar container
  • SidebarHeader and SidebarFooter - Sticky at the top and bottom of the sidebar
  • SidebarContent - Scrollable content area
  • SidebarGroup - Section within the SidebarContent
  • SidebarTrigger - Button to toggle the sidebar
Sidebar Structure

Usage

Basic Layout

Wrap your application with SidebarProvider and place Sidebar alongside your main content:

---
import {
Sidebar,
SidebarContent,
SidebarProvider,
SidebarTrigger,
} from "@/components/starwind/sidebar";
import { AppSidebar } from "@/components/app-sidebar";
---
<SidebarProvider>
<AppSidebar />
<main>
<SidebarTrigger />
<slot />
</main>
</SidebarProvider>

Creating a Sidebar Component

---
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarHeader,
} from "@/components/starwind/sidebar";
---
<Sidebar>
<SidebarHeader />
<SidebarContent>
<SidebarGroup />
<SidebarGroup />
</SidebarContent>
<SidebarFooter />
</Sidebar>

With Menu Items

Use SidebarMenu, SidebarMenuItem, and SidebarMenuButton to create navigation menus:

With Inset Variant

When using the inset variant, wrap your main content in SidebarInset:

---
import {
Sidebar,
SidebarInset,
SidebarProvider,
} from "@/components/starwind/sidebar";
---
<SidebarProvider>
<Sidebar variant="inset">
{/* Sidebar content */}
</Sidebar>
<SidebarInset>
<main>{/* Main content */}</main>
</SidebarInset>
</SidebarProvider>

API Reference

Styled Component API

These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.

Sidebar

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
persistenceKey string
Description
Sets the storage key used for persisted state.
Classification
Primitive override
Primitive prop
sidebar.Provider.persistenceKey
persistenceStorage "localStorage" | "cookie" | false
Description
Selects where persisted state is stored.
Classification
Primitive override
Primitive prop
sidebar.Provider.persistenceStorage

Sidebar

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
collapsible "offcanvas" | "icon" | "none" "offcanvas"
Description
Selects how the component can collapse.
Classification
Primitive override
Primitive prop
sidebar.Sidebar.collapsible

Sidebar Group Label

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Wrapper prop

Sidebar Menu Button

Inherits a attributes. Omits `type`.

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
asChild boolean false
Description
Merges the component behavior and props into its child element.
Classification
Wrapper prop
isActive boolean false
Description
Applies the active visual state.
Classification
Wrapper prop
size "default" | "sm" | "lg" "default"
Description
Selects the component's visual size.
Classification
Styled variant
tooltip string
Description
Provides collapsed-sidebar tooltip text for this menu button.
Classification
Wrapper prop
variant "default" | "outline" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Sidebar Menu Action

Inherits Button props.

Contains the following additional props:

Prop Type Default Toggle details
showOnHover boolean false
Description
Reveals the action when its containing item is hovered.
Classification
Wrapper prop

Sidebar Menu Skeleton

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
showIcon boolean false
Description
Shows the component's generated icon.
Classification
Wrapper prop
width string
Description
Sets the component width.
Classification
Wrapper prop

Sidebar Menu Sub Button

Inherits a attributes.

Contains the following additional props:

Prop Type Default Toggle details
isActive boolean false
Description
Applies the active visual state.
Classification
Wrapper prop
size "sm" | "md" "md"
Description
Selects the component's visual size.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Sidebar.

Primitive API

Runtime API

Sidebar primitive
createSidebarController from @starwind-ui/runtime/sidebar

Changelog

v2.0.0

  • Rebuilt Sidebar on Starwind Runtime for provider, collapsed, mobile, and control state.
  • See the Sidebar Primitive for the underlying unstyled anatomy and behavior API.