Sidebar
---import BellIcon from "@tabler/icons/outline/bell.svg";import BookOpenIcon from "@tabler/icons/outline/book.svg";import ChartPieIcon from "@tabler/icons/outline/chart-pie.svg";import ChevronRightIcon from "@tabler/icons/outline/chevron-right.svg";import ChevronUpIcon from "@tabler/icons/outline/chevron-up.svg";import CodeIcon from "@tabler/icons/outline/code.svg";import CreditCardIcon from "@tabler/icons/outline/credit-card.svg";import FrameIcon from "@tabler/icons/outline/frame.svg";import LogoutIcon from "@tabler/icons/outline/logout.svg";import MapIcon from "@tabler/icons/outline/map.svg";import BotIcon from "@tabler/icons/outline/robot.svg";import BadgeCheckIcon from "@tabler/icons/outline/rosette-discount-check.svg";import Settings2Icon from "@tabler/icons/outline/settings-2.svg";import SparklesIcon from "@tabler/icons/outline/sparkles.svg";import TerminalIcon from "@tabler/icons/outline/terminal-2.svg";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/starwind/avatar";import { Collapsible, CollapsibleContent, CollapsibleTrigger,} from "@/components/starwind/collapsible";import { Dropdown, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator, DropdownTrigger,} from "@/components/starwind/dropdown";import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger,} from "@/components/starwind/sidebar";
const navMain = [ { title: "Playground", url: "#", icon: TerminalIcon, isActive: true, items: [ { title: "History", url: "#" }, { title: "Starred", url: "#" }, { title: "Settings", url: "#" }, ], }, { title: "Models", url: "#", icon: BotIcon, items: [ { title: "Genesis", url: "#" }, { title: "Explorer", url: "#" }, { title: "Quantum", url: "#" }, ], }, { title: "Documentation", url: "#", icon: BookOpenIcon, items: [ { title: "Introduction", url: "#" }, { title: "Get Started", url: "#" }, { title: "Tutorials", url: "#" }, { title: "Changelog", url: "#" }, ], }, { title: "Settings", url: "#", icon: Settings2Icon, items: [ { title: "General", url: "#" }, { title: "Team", url: "#" }, { title: "Billing", url: "#" }, { title: "Limits", url: "#" }, ], },];
const projects = [ { name: "Design Engineering", url: "#", icon: FrameIcon }, { name: "Sales & Marketing", url: "#", icon: ChartPieIcon }, { name: "Travel", url: "#", icon: MapIcon },];---
<SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarSeparator />
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Platform</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { navMain.map((item) => ( <Collapsible defaultOpen={item.isActive} class="group/collapsible"> <SidebarMenuItem> <CollapsibleTrigger asChild> <SidebarMenuButton tooltip={item.title}> <item.icon /> <span>{item.title}</span> <ChevronRightIcon class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" /> </SidebarMenuButton> </CollapsibleTrigger> {item.items && ( <CollapsibleContent> <SidebarMenuSub> {item.items.map((subItem) => ( <SidebarMenuSubItem> <SidebarMenuSubButton href={subItem.url}> <span>{subItem.title}</span> </SidebarMenuSubButton> </SidebarMenuSubItem> ))} </SidebarMenuSub> </CollapsibleContent> )} </SidebarMenuItem> </Collapsible> )) } </SidebarMenu> </SidebarGroupContent> </SidebarGroup>
<SidebarGroup class="group-data-[collapsible=icon]:hidden"> <SidebarGroupLabel>Projects</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { projects.map((project) => ( <SidebarMenuItem> <SidebarMenuButton href={project.url} tooltip={project.name}> <project.icon /> <span>{project.name}</span> </SidebarMenuButton> </SidebarMenuItem> )) } </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent>
<SidebarFooter> <SidebarMenu> <SidebarMenuItem> <Dropdown> <DropdownTrigger asChild> <SidebarMenuButton size="lg"> <Avatar class="size-10 shrink-0 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Boston343</span> <span class="text-sidebar-foreground/70 truncate text-xs">@boston343</span> </div> <ChevronUpIcon class="ml-auto size-4" /> </SidebarMenuButton> </DropdownTrigger> <DropdownContent class="min-w-48" side="right"> <DropdownLabel class="p-0 font-normal"> <div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm"> <Avatar class="size-8 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">boston343</span> <span class="text-muted-foreground truncate text-xs">@boston343</span> </div> </div> </DropdownLabel> <DropdownSeparator /> <DropdownItem> <SparklesIcon class="mr-2 size-4" /> Upgrade to Pro </DropdownItem> <DropdownSeparator /> <DropdownItem> <BadgeCheckIcon class="mr-2 size-4" /> Account </DropdownItem> <DropdownItem> <CreditCardIcon class="mr-2 size-4" /> Billing </DropdownItem> <DropdownItem> <BellIcon class="mr-2 size-4" /> Notifications </DropdownItem> <DropdownSeparator /> <DropdownItem> <LogoutIcon class="mr-2 size-4" /> Log out </DropdownItem> </DropdownContent> </Dropdown> </SidebarMenuItem> </SidebarMenu> </SidebarFooter>
<SidebarRail /> </Sidebar>
<main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main></SidebarProvider>import { IconBell as BellIcon, IconBook as BookOpenIcon, IconChartPie as ChartPieIcon, IconChevronRight as ChevronRightIcon, IconChevronUp as ChevronUpIcon, IconCode as CodeIcon, IconCreditCard as CreditCardIcon, IconFrame as FrameIcon, IconLogout as LogoutIcon, IconMap as MapIcon, IconRobot as BotIcon, IconRosetteDiscountCheck as BadgeCheckIcon, IconSettings2 as Settings2Icon, IconSparkles as SparklesIcon, IconTerminal2 as TerminalIcon,} from "@tabler/icons-react";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/starwind/avatar";import { Collapsible, CollapsibleContent, CollapsibleTrigger,} from "@/components/starwind/collapsible";import { Dropdown, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator, DropdownTrigger,} from "@/components/starwind/dropdown";import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger,} from "@/components/starwind/sidebar";
const navMain = [ { title: "Playground", url: "#", Icon: TerminalIcon, isActive: true, items: [ { title: "History", url: "#" }, { title: "Starred", url: "#" }, { title: "Settings", url: "#" }, ], }, { title: "Models", url: "#", Icon: BotIcon, items: [ { title: "Genesis", url: "#" }, { title: "Explorer", url: "#" }, { title: "Quantum", url: "#" }, ], }, { title: "Documentation", url: "#", Icon: BookOpenIcon, items: [ { title: "Introduction", url: "#" }, { title: "Get Started", url: "#" }, { title: "Tutorials", url: "#" }, { title: "Changelog", url: "#" }, ], }, { title: "Settings", url: "#", Icon: Settings2Icon, items: [ { title: "General", url: "#" }, { title: "Team", url: "#" }, { title: "Billing", url: "#" }, { title: "Limits", url: "#" }, ], },];
const projects = [ { name: "Design Engineering", url: "#", Icon: FrameIcon }, { name: "Sales & Marketing", url: "#", Icon: ChartPieIcon }, { name: "Travel", url: "#", Icon: MapIcon },];
export function Example() { return ( <> <SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div className="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon className="size-5" /> </div> <div className="grid flex-1 text-left text-sm leading-tight"> <span className="truncate font-semibold">Starwind UI</span> <span className="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarSeparator />
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Platform</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { navMain.map((item) => ( <Collapsible key={`${item.url}-${item.title}`} defaultOpen={item.isActive} className="group/collapsible" > <SidebarMenuItem> <CollapsibleTrigger asChild> <SidebarMenuButton tooltip={item.title}> <item.Icon /> <span>{item.title}</span> <ChevronRightIcon className="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" /> </SidebarMenuButton> </CollapsibleTrigger> {item.items && ( <CollapsibleContent> <SidebarMenuSub> {item.items.map((subItem) => ( <SidebarMenuSubItem key={`${subItem.url}-${subItem.title}`}> <SidebarMenuSubButton href={subItem.url}> <span>{subItem.title}</span> </SidebarMenuSubButton> </SidebarMenuSubItem> ))} </SidebarMenuSub> </CollapsibleContent> )} </SidebarMenuItem> </Collapsible> ))} </SidebarMenu> </SidebarGroupContent> </SidebarGroup>
<SidebarGroup className="group-data-[collapsible=icon]:hidden"> <SidebarGroupLabel>Projects</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { projects.map((project) => ( <SidebarMenuItem key={`${project.url}-${project.name}`}> <SidebarMenuButton href={project.url} tooltip={project.name}> <project.Icon /> <span>{project.name}</span> </SidebarMenuButton> </SidebarMenuItem> ))} </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent>
<SidebarFooter> <SidebarMenu> <SidebarMenuItem> <Dropdown> <DropdownTrigger asChild> <SidebarMenuButton size="lg"> <Avatar className="size-10 shrink-0 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback className="rounded-lg">B3</AvatarFallback> </Avatar> <div className="grid flex-1 text-left text-sm leading-tight"> <span className="truncate font-semibold">Boston343</span> <span className="text-sidebar-foreground/70 truncate text-xs">@boston343</span> </div> <ChevronUpIcon className="ml-auto size-4" /> </SidebarMenuButton> </DropdownTrigger> <DropdownContent className="min-w-48" side="right"> <DropdownLabel className="p-0 font-normal"> <div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm"> <Avatar className="size-8 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback className="rounded-lg">B3</AvatarFallback> </Avatar> <div className="grid flex-1 text-left text-sm leading-tight"> <span className="truncate font-semibold">boston343</span> <span className="text-muted-foreground truncate text-xs">@boston343</span> </div> </div> </DropdownLabel> <DropdownSeparator /> <DropdownItem> <SparklesIcon className="mr-2 size-4" /> Upgrade to Pro </DropdownItem> <DropdownSeparator /> <DropdownItem> <BadgeCheckIcon className="mr-2 size-4" /> Account </DropdownItem> <DropdownItem> <CreditCardIcon className="mr-2 size-4" /> Billing </DropdownItem> <DropdownItem> <BellIcon className="mr-2 size-4" /> Notifications </DropdownItem> <DropdownSeparator /> <DropdownItem> <LogoutIcon className="mr-2 size-4" /> Log out </DropdownItem> </DropdownContent> </Dropdown> </SidebarMenuItem> </SidebarMenu> </SidebarFooter>
<SidebarRail /> </Sidebar>
<main className="bg-background flex flex-1 flex-col"> <header className="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span className="text-muted-foreground text-sm">Main Content</span> </header> <div className="flex-1 p-6"> <p className="text-muted-foreground text-sm"> Use <kbd className="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main> </SidebarProvider> </> );}<script setup lang="ts">import { IconBell as BellIcon } from "@tabler/icons-vue";import { IconBook as BookOpenIcon } from "@tabler/icons-vue";import { IconChartPie as ChartPieIcon } from "@tabler/icons-vue";import { IconChevronRight as ChevronRightIcon } from "@tabler/icons-vue";import { IconChevronUp as ChevronUpIcon } from "@tabler/icons-vue";import { IconCode as CodeIcon } from "@tabler/icons-vue";import { IconCreditCard as CreditCardIcon } from "@tabler/icons-vue";import { IconFrame as FrameIcon } from "@tabler/icons-vue";import { IconLogout as LogoutIcon } from "@tabler/icons-vue";import { IconMap as MapIcon } from "@tabler/icons-vue";import { IconRobot as BotIcon } from "@tabler/icons-vue";import { IconRosetteDiscountCheck as BadgeCheckIcon } from "@tabler/icons-vue";import { IconSettings2 as Settings2Icon } from "@tabler/icons-vue";import { IconSparkles as SparklesIcon } from "@tabler/icons-vue";import { IconTerminal2 as TerminalIcon } from "@tabler/icons-vue";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/starwind/avatar";import { Collapsible, CollapsibleContent, CollapsibleTrigger,} from "@/components/starwind/collapsible";import { Dropdown, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator, DropdownTrigger,} from "@/components/starwind/dropdown";import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger,} from "@/components/starwind/sidebar";
const navMain = [ { title: "Playground", url: "#", icon: TerminalIcon, isActive: true, items: [ { title: "History", url: "#" }, { title: "Starred", url: "#" }, { title: "Settings", url: "#" }, ], }, { title: "Models", url: "#", icon: BotIcon, items: [ { title: "Genesis", url: "#" }, { title: "Explorer", url: "#" }, { title: "Quantum", url: "#" }, ], }, { title: "Documentation", url: "#", icon: BookOpenIcon, items: [ { title: "Introduction", url: "#" }, { title: "Get Started", url: "#" }, { title: "Tutorials", url: "#" }, { title: "Changelog", url: "#" }, ], }, { title: "Settings", url: "#", icon: Settings2Icon, items: [ { title: "General", url: "#" }, { title: "Team", url: "#" }, { title: "Billing", url: "#" }, { title: "Limits", url: "#" }, ], },];
const projects = [ { name: "Design Engineering", url: "#", icon: FrameIcon }, { name: "Sales & Marketing", url: "#", icon: ChartPieIcon }, { name: "Travel", url: "#", icon: MapIcon },];</script>
<template> <SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarSeparator />
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Platform</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> <template v-for="item in navMain" :key="item.title"> <Collapsible :defaultOpen="item.isActive" class="group/collapsible"> <SidebarMenuItem> <CollapsibleTrigger asChild> <SidebarMenuButton :tooltip="item.title"> <component :is="item.icon" /> <span>{{ item.title }}</span> <ChevronRightIcon class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" /> </SidebarMenuButton> </CollapsibleTrigger> <template v-if="item.items"> <CollapsibleContent> <SidebarMenuSub> <template v-for="subItem in item.items" :key="subItem.title"> <SidebarMenuSubItem> <SidebarMenuSubButton :href="subItem.url"> <span>{{ subItem.title }}</span> </SidebarMenuSubButton> </SidebarMenuSubItem> </template> </SidebarMenuSub> </CollapsibleContent> </template> </SidebarMenuItem> </Collapsible> </template> </SidebarMenu> </SidebarGroupContent> </SidebarGroup>
<SidebarGroup class="group-data-[collapsible=icon]:hidden"> <SidebarGroupLabel>Projects</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> <template v-for="project in projects" :key="project.name"> <SidebarMenuItem> <SidebarMenuButton :href="project.url" :tooltip="project.name"> <component :is="project.icon" /> <span>{{ project.name }}</span> </SidebarMenuButton> </SidebarMenuItem> </template> </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent>
<SidebarFooter> <SidebarMenu> <SidebarMenuItem> <Dropdown> <DropdownTrigger asChild> <SidebarMenuButton size="lg"> <Avatar class="size-10 shrink-0 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Boston343</span> <span class="text-sidebar-foreground/70 truncate text-xs">@boston343</span> </div> <ChevronUpIcon class="ml-auto size-4" /> </SidebarMenuButton> </DropdownTrigger> <DropdownContent class="min-w-48" side="right"> <DropdownLabel class="p-0 font-normal"> <div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm"> <Avatar class="size-8 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">boston343</span> <span class="text-muted-foreground truncate text-xs">@boston343</span> </div> </div> </DropdownLabel> <DropdownSeparator /> <DropdownItem> <SparklesIcon class="mr-2 size-4" /> Upgrade to Pro </DropdownItem> <DropdownSeparator /> <DropdownItem> <BadgeCheckIcon class="mr-2 size-4" /> Account </DropdownItem> <DropdownItem> <CreditCardIcon class="mr-2 size-4" /> Billing </DropdownItem> <DropdownItem> <BellIcon class="mr-2 size-4" /> Notifications </DropdownItem> <DropdownSeparator /> <DropdownItem> <LogoutIcon class="mr-2 size-4" /> Log out </DropdownItem> </DropdownContent> </Dropdown> </SidebarMenuItem> </SidebarMenu> </SidebarFooter>
<SidebarRail /> </Sidebar>
<main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main> </SidebarProvider></template><script lang="ts">import { IconBell as BellIcon } from "@tabler/icons-svelte";import { IconBook as BookOpenIcon } from "@tabler/icons-svelte";import { IconChartPie as ChartPieIcon } from "@tabler/icons-svelte";import { IconChevronRight as ChevronRightIcon } from "@tabler/icons-svelte";import { IconChevronUp as ChevronUpIcon } from "@tabler/icons-svelte";import { IconCode as CodeIcon } from "@tabler/icons-svelte";import { IconCreditCard as CreditCardIcon } from "@tabler/icons-svelte";import { IconFrame as FrameIcon } from "@tabler/icons-svelte";import { IconLogout as LogoutIcon } from "@tabler/icons-svelte";import { IconMap as MapIcon } from "@tabler/icons-svelte";import { IconRobot as BotIcon } from "@tabler/icons-svelte";import { IconRosetteDiscountCheck as BadgeCheckIcon } from "@tabler/icons-svelte";import { IconSettings2 as Settings2Icon } from "@tabler/icons-svelte";import { IconSparkles as SparklesIcon } from "@tabler/icons-svelte";import { IconTerminal2 as TerminalIcon } from "@tabler/icons-svelte";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/starwind/avatar";import { Collapsible, CollapsibleContent, CollapsibleTrigger,} from "@/components/starwind/collapsible";import { Dropdown, DropdownContent, DropdownItem, DropdownLabel, DropdownSeparator, DropdownTrigger,} from "@/components/starwind/dropdown";import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger,} from "@/components/starwind/sidebar";
const navMain = [ { title: "Playground", url: "#api-reference", icon: TerminalIcon, isActive: true, items: [ { title: "History", url: "#api-reference" }, { title: "Starred", url: "#api-reference" }, { title: "Settings", url: "#api-reference" }, ], }, { title: "Models", url: "#api-reference", icon: BotIcon, items: [ { title: "Genesis", url: "#api-reference" }, { title: "Explorer", url: "#api-reference" }, { title: "Quantum", url: "#api-reference" }, ], }, { title: "Documentation", url: "#api-reference", icon: BookOpenIcon, items: [ { title: "Introduction", url: "#api-reference" }, { title: "Get Started", url: "#api-reference" }, { title: "Tutorials", url: "#api-reference" }, { title: "Changelog", url: "#api-reference" }, ], }, { title: "Settings", url: "#api-reference", icon: Settings2Icon, items: [ { title: "General", url: "#api-reference" }, { title: "Team", url: "#api-reference" }, { title: "Billing", url: "#api-reference" }, { title: "Limits", url: "#api-reference" }, ], },];
const projects = [ { name: "Design Engineering", url: "#api-reference", icon: FrameIcon }, { name: "Sales & Marketing", url: "#api-reference", icon: ChartPieIcon }, { name: "Travel", url: "#api-reference", icon: MapIcon },];</script>
<SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarSeparator />
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Platform</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> {#each navMain as item (item.title)} <Collapsible defaultOpen={item.isActive} class="group/collapsible"> <SidebarMenuItem> <CollapsibleTrigger>{#snippet child({ props })} <SidebarMenuButton {...props} tooltip={item.title}> <item.icon /> <span>{item.title}</span> <ChevronRightIcon class="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" /> </SidebarMenuButton> {/snippet}</CollapsibleTrigger> {#if item.items} <CollapsibleContent> <SidebarMenuSub> {#each item.items as subItem (subItem.title)} <SidebarMenuSubItem> <SidebarMenuSubButton href={subItem.url}> <span>{subItem.title}</span> </SidebarMenuSubButton> </SidebarMenuSubItem> {/each} </SidebarMenuSub> </CollapsibleContent> {/if} </SidebarMenuItem> </Collapsible> {/each} </SidebarMenu> </SidebarGroupContent> </SidebarGroup>
<SidebarGroup class="group-data-[collapsible=icon]:hidden"> <SidebarGroupLabel>Projects</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> {#each projects as project (project.name)} <SidebarMenuItem> <SidebarMenuButton href={project.url} tooltip={project.name}> <project.icon /> <span>{project.name}</span> </SidebarMenuButton> </SidebarMenuItem> {/each} </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent>
<SidebarFooter> <SidebarMenu> <SidebarMenuItem> <Dropdown> <DropdownTrigger>{#snippet child({ props })} <SidebarMenuButton {...props} size="lg"> <Avatar class="size-10 shrink-0 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Boston343</span> <span class="text-sidebar-foreground/70 truncate text-xs">@boston343</span> </div> <ChevronUpIcon class="ml-auto size-4" /> </SidebarMenuButton> {/snippet}</DropdownTrigger> <DropdownContent class="min-w-48" side="right"> <DropdownLabel class="p-0 font-normal"> <div class="flex items-center gap-2 px-1 py-1.5 text-left text-sm"> <Avatar class="size-8 rounded-lg"> <AvatarImage src="https://github.com/boston343.png" alt="boston343" /> <AvatarFallback class="rounded-lg">B3</AvatarFallback> </Avatar> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">boston343</span> <span class="text-muted-foreground truncate text-xs">@boston343</span> </div> </div> </DropdownLabel> <DropdownSeparator /> <DropdownItem> <SparklesIcon class="mr-2 size-4" /> Upgrade to Pro </DropdownItem> <DropdownSeparator /> <DropdownItem> <BadgeCheckIcon class="mr-2 size-4" /> Account </DropdownItem> <DropdownItem> <CreditCardIcon class="mr-2 size-4" /> Billing </DropdownItem> <DropdownItem> <BellIcon class="mr-2 size-4" /> Notifications </DropdownItem> <DropdownSeparator /> <DropdownItem> <LogoutIcon class="mr-2 size-4" /> Log out </DropdownItem> </DropdownContent> </Dropdown> </SidebarMenuItem> </SidebarMenu> </SidebarFooter>
<SidebarRail /> </Sidebar>
<main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main> </SidebarProvider>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
pnpx starwind@latest add sidebar --framework astronpx starwind@latest add sidebar --framework astroyarn dlx starwind@latest add sidebar --framework astropnpx starwind@latest add sidebar --framework reactnpx starwind@latest add sidebar --framework reactyarn dlx starwind@latest add sidebar --framework reactpnpx starwind@latest add sidebar --framework vuenpx starwind@latest add sidebar --framework vueyarn dlx starwind@latest add sidebar --framework vuepnpx starwind@latest add sidebar --framework sveltenpx starwind@latest add sidebar --framework svelteyarn dlx starwind@latest add sidebar --framework svelteThe command also adds the sidebar color tokens to your CSS file when they are missing.
Usage
Wrap the sidebar and the page content with SidebarProvider. The trigger can live in the page header or another control region.
---import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger } from "@/components/starwind/sidebar";---
<SidebarProvider> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> <slot /> </main></SidebarProvider>import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger } from "@/components/starwind/sidebar";
export function Example() { return ( <SidebarProvider> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> <div>Page content</div> </main> </SidebarProvider> );}<script setup lang="ts">import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";</script>
<template> <SidebarProvider> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> <slot /> </main> </SidebarProvider></template><script lang="ts"> import type { Snippet } from "svelte"; let { children }: { children?: Snippet } = $props(); import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger, } from "@/components/starwind/sidebar";</script>
<SidebarProvider> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> {@render children?.()} </main></SidebarProvider>Composition
A Sidebar layout starts with SidebarProvider. Add only the groups, menus, actions, and supporting parts that the application needs.
SidebarProvider├── Sidebar│ ├── SidebarHeader│ ├── SidebarContent│ │ └── SidebarGroup│ │ ├── SidebarGroupLabel│ │ ├── SidebarGroupAction│ │ └── SidebarGroupContent│ │ └── SidebarMenu│ │ └── SidebarMenuItem│ │ ├── SidebarMenuButton│ │ ├── SidebarMenuAction│ │ ├── SidebarMenuBadge│ │ └── SidebarMenuSub│ │ └── SidebarMenuSubItem│ │ └── SidebarMenuSubButton│ ├── SidebarFooter│ └── SidebarRail├── SidebarInset└── SidebarTrigger
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.astro";---
<SidebarProvider> <AppSidebar /> <main> <SidebarTrigger /> <slot /> </main></SidebarProvider>import type { ReactNode } from "react";import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";import { AppSidebar } from "@/components/app-sidebar";
export function Example({ children }: { children: ReactNode }) { return ( <> <SidebarProvider> <AppSidebar /> <main> <SidebarTrigger /> {children} </main> </SidebarProvider> </> );}<script setup lang="ts">import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";</script>
<template> <SidebarProvider> <Sidebar><SidebarContent>Navigation</SidebarContent></Sidebar> <main> <SidebarTrigger /> <slot /> </main> </SidebarProvider></template><script lang="ts"> import type { Snippet } from "svelte"; let { children }: { children?: Snippet } = $props(); import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger, } from "@/components/starwind/sidebar";</script>
<SidebarProvider> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> {@render children?.()} </main></SidebarProvider>Creating a Sidebar Component
---import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader,} from "@/components/starwind/sidebar";---
<Sidebar> <SidebarHeader /> <SidebarContent> <SidebarGroup /> <SidebarGroup /> </SidebarContent> <SidebarFooter /></Sidebar>import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader,} from "@/components/starwind/sidebar";
export function AppSidebar() { return ( <> <Sidebar> <SidebarHeader /> <SidebarContent> <SidebarGroup /> <SidebarGroup /> </SidebarContent> <SidebarFooter /> </Sidebar> </> );}<script setup lang="ts">import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader,} from "@/components/starwind/sidebar";import { SidebarProvider } from "@/components/starwind/sidebar";</script>
<template> <SidebarProvider> <Sidebar> <SidebarHeader /> <SidebarContent> <SidebarGroup /> <SidebarGroup /> </SidebarContent> <SidebarFooter /> </Sidebar> </SidebarProvider></template><script lang="ts"> import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader, } from "@/components/starwind/sidebar"; import { SidebarProvider } from "@/components/starwind/sidebar";</script>
<SidebarProvider> <Sidebar> <SidebarHeader /> <SidebarContent> <SidebarGroup /> <SidebarGroup /> </SidebarContent> <SidebarFooter /> </Sidebar></SidebarProvider>With Menu Items
Use SidebarMenu, SidebarMenuItem, and SidebarMenuButton to create navigation menus. SidebarMenuButton supports sm, md, and lg sizes and defaults to md:
---import CalendarIcon from "@tabler/icons/outline/calendar.svg";import CodeIcon from "@tabler/icons/outline/code.svg";import HomeIcon from "@tabler/icons/outline/home.svg";import InboxIcon from "@tabler/icons/outline/inbox.svg";import SearchIcon from "@tabler/icons/outline/search.svg";import SettingsIcon from "@tabler/icons/outline/settings.svg";
import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";
const items = [ { title: "Home", url: "#", icon: HomeIcon }, { title: "Inbox", url: "#", icon: InboxIcon }, { title: "Calendar", url: "#", icon: CalendarIcon }, { title: "Search", url: "#", icon: SearchIcon }, { title: "Settings", url: "#", icon: SettingsIcon },];---
<SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Application</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { items.map((item) => ( <SidebarMenuItem> <SidebarMenuButton href={item.url}> <item.icon /> <span>{item.title}</span> </SidebarMenuButton> </SidebarMenuItem> )) } </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent> </Sidebar>
<main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main></SidebarProvider>import { IconCalendar as CalendarIcon } from "@tabler/icons-react";import { IconCode as CodeIcon } from "@tabler/icons-react";import { IconHome as HomeIcon } from "@tabler/icons-react";import { IconInbox as InboxIcon } from "@tabler/icons-react";import { IconSearch as SearchIcon } from "@tabler/icons-react";import { IconSettings as SettingsIcon } from "@tabler/icons-react";
import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";
const items = [ { title: "Home", url: "#", Icon: HomeIcon }, { title: "Inbox", url: "#", Icon: InboxIcon }, { title: "Calendar", url: "#", Icon: CalendarIcon }, { title: "Search", url: "#", Icon: SearchIcon }, { title: "Settings", url: "#", Icon: SettingsIcon },];
export function Example() { return ( <> <SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div className="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon className="size-5" /> </div> <div className="grid flex-1 text-left text-sm leading-tight"> <span className="truncate font-semibold">Starwind UI</span> <span className="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Application</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> { items.map((item) => ( <SidebarMenuItem key={`${item.url}-${item.title}`}> <SidebarMenuButton href={item.url}> <item.Icon /> <span>{item.title}</span> </SidebarMenuButton> </SidebarMenuItem> )) } </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent> </Sidebar>
<main className="bg-background flex flex-1 flex-col"> <header className="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span className="text-muted-foreground text-sm">Main Content</span> </header> <div className="flex-1 p-6"> <p className="text-muted-foreground text-sm"> Use <kbd className="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main> </SidebarProvider> </> );}<script setup lang="ts">import { IconCalendar as CalendarIcon } from "@tabler/icons-vue";import { IconCode as CodeIcon } from "@tabler/icons-vue";import { IconHome as HomeIcon } from "@tabler/icons-vue";import { IconInbox as InboxIcon } from "@tabler/icons-vue";import { IconSearch as SearchIcon } from "@tabler/icons-vue";import { IconSettings as SettingsIcon } from "@tabler/icons-vue";
import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger,} from "@/components/starwind/sidebar";
const items = [ { title: "Home", url: "#", icon: HomeIcon }, { title: "Inbox", url: "#", icon: InboxIcon }, { title: "Calendar", url: "#", icon: CalendarIcon }, { title: "Search", url: "#", icon: SearchIcon }, { title: "Settings", url: "#", icon: SettingsIcon },];</script>
<template> <SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader>
<SidebarContent> <SidebarGroup> <SidebarGroupLabel>Application</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> <template v-for="item in items" :key="item.title"> <SidebarMenuItem> <SidebarMenuButton :href="item.url"> <component :is="item.icon" /> <span>{{ item.title }}</span> </SidebarMenuButton> </SidebarMenuItem> </template> </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent> </Sidebar>
<main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main> </SidebarProvider></template><script lang="ts"> import { IconCalendar as CalendarIcon } from "@tabler/icons-svelte"; import { IconCode as CodeIcon } from "@tabler/icons-svelte"; import { IconHome as HomeIcon } from "@tabler/icons-svelte"; import { IconInbox as InboxIcon } from "@tabler/icons-svelte"; import { IconSearch as SearchIcon } from "@tabler/icons-svelte"; import { IconSettings as SettingsIcon } from "@tabler/icons-svelte";
import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger, } from "@/components/starwind/sidebar";
const items = [ { title: "Home", url: "#", icon: HomeIcon }, { title: "Inbox", url: "#", icon: InboxIcon }, { title: "Calendar", url: "#", icon: CalendarIcon }, { title: "Search", url: "#", icon: SearchIcon }, { title: "Settings", url: "#", icon: SettingsIcon }, ];</script>
<SidebarProvider> <Sidebar collapsible="icon"> <SidebarHeader> <SidebarMenu> <SidebarMenuItem> <SidebarMenuButton size="lg"> <div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-10 items-center justify-center rounded-lg" > <CodeIcon class="size-5" /> </div> <div class="grid flex-1 text-left text-sm leading-tight"> <span class="truncate font-semibold">Starwind UI</span> <span class="text-sidebar-foreground/70 truncate text-xs">Enterprise</span> </div> </SidebarMenuButton> </SidebarMenuItem> </SidebarMenu> </SidebarHeader> <SidebarContent> <SidebarGroup> <SidebarGroupLabel>Application</SidebarGroupLabel> <SidebarGroupContent> <SidebarMenu> {#each items as item (item.title)} <SidebarMenuItem> <SidebarMenuButton href={item.url}> <item.icon></item.icon> <span>{item.title}</span> </SidebarMenuButton> </SidebarMenuItem> {/each} </SidebarMenu> </SidebarGroupContent> </SidebarGroup> </SidebarContent> </Sidebar> <main class="bg-background flex flex-1 flex-col"> <header class="flex h-12 shrink-0 items-center gap-2 border-b px-4"> <SidebarTrigger /> <span class="text-muted-foreground text-sm">Main Content</span> </header> <div class="flex-1 p-6"> <p class="text-muted-foreground text-sm"> Use <kbd class="bg-muted rounded px-1.5 py-0.5 text-xs font-medium">Ctrl+B</kbd> to toggle the sidebar <br /> after clicking in this window. </p> </div> </main></SidebarProvider>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>import { Sidebar, SidebarInset, SidebarProvider,} from "@/components/starwind/sidebar";
export function Example() { return ( <> <SidebarProvider> <Sidebar variant="inset"> {/* Sidebar content */} </Sidebar> <SidebarInset> <main>{/* Main content */}</main> </SidebarInset> </SidebarProvider> </> );}<script setup lang="ts">import { Sidebar, SidebarInset, SidebarProvider } from "@/components/starwind/sidebar";</script>
<template> <SidebarProvider> <Sidebar variant="inset"> <!-- Sidebar content --> </Sidebar> <SidebarInset> <main><!-- Main content --></main> </SidebarInset> </SidebarProvider></template><script lang="ts"> import { Sidebar, SidebarInset, SidebarProvider } from "@/components/starwind/sidebar";</script>
<SidebarProvider> <Sidebar variant="inset"> <!-- Sidebar content --> </Sidebar> <SidebarInset> <main> <!-- Main content --> </main> </SidebarInset></SidebarProvider>Persist The Sidebar State
Set persistOpen on SidebarProvider to save the desktop open state. It is false by default. When it is on, the sidebar saves "true" or "false" each time the desktop state changes. On the next page load, the saved value replaces defaultOpen. The mobile sheet state is not saved.
persistenceStoragesets where the state is saved. The default is"localStorage". Use"cookie"when your server must read the state. It has no effect whilepersistOpenisfalse.persistenceKeysets the storage key or cookie name. The default isstarwind-sidebar-open.persistenceMaxAgesets the cookie lifetime in seconds. The default is604800, which is 7 days. The cookie usespath=/, so all pages on your site share it.- A controlled
openprop ignores the saved value. It is not available in Astro.
To make the first paint show the saved state, use persistenceStorage="cookie". Then read the cookie on the server and pass the result to defaultOpen. The page must render on demand. In Astro, set prerender = false and use a server adapter. If you set persistenceKey, read the cookie with that name.
---import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger } from "@/components/starwind/sidebar";
export const prerender = false;
const defaultOpen = Astro.cookies.get("starwind-sidebar-open")?.value !== "false";---
<SidebarProvider defaultOpen={defaultOpen} persistOpen persistenceStorage="cookie"> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> </main></SidebarProvider>import type { ReactNode } from "react";import { cookies } from "next/headers";import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger } from "@/components/starwind/sidebar";
export default async function DashboardLayout({ children }: { children: ReactNode }) { const cookieStore = await cookies(); const defaultOpen = cookieStore.get("starwind-sidebar-open")?.value !== "false";
return ( <SidebarProvider defaultOpen={defaultOpen} persistOpen persistenceStorage="cookie"> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> {children} </main> </SidebarProvider> );}<script setup lang="ts">import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger,} from "~/components/starwind/sidebar";import { useCookie } from "#imports";
const sidebarCookie = useCookie<boolean | undefined>("starwind-sidebar-open");const defaultOpen = sidebarCookie.value !== false;</script>
<template> <SidebarProvider :defaultOpen="defaultOpen" persistOpen persistenceStorage="cookie"> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> <NuxtPage /> </main> </SidebarProvider></template>import type { LayoutServerLoad } from "./$types";
export const load: LayoutServerLoad = ({ cookies }) => ({ sidebarOpen: cookies.get("starwind-sidebar-open") !== "false",});<script lang="ts"> import type { Snippet } from "svelte"; import { Sidebar, SidebarContent, SidebarProvider, SidebarTrigger, } from "$lib/starwind/sidebar";
// You can also type these props with LayoutProps from "./$types". let { data, children }: { data?: { sidebarOpen: boolean }; children?: Snippet } = $props();</script>
<SidebarProvider defaultOpen={data?.sidebarOpen} persistOpen persistenceStorage="cookie"> <Sidebar> <SidebarContent>Navigation</SidebarContent> </Sidebar> <main> <SidebarTrigger /> {@render children?.()} </main></SidebarProvider>A static page cannot read cookies. It renders defaultOpen, and the Runtime applies the saved state when the page script starts, so the sidebar can change after the first paint. The server cannot read localStorage. A page that reads the cookie is different for each visitor, so send Vary: Cookie or Cache-Control: private when a shared cache or CDN stores it.
API Reference
Styled Component API
These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.
Sidebar
Inherits div attributes.
Contains the following additional props:
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:
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:
asChild boolean false
- Description
- Preserves the Sidebar Group Label recipe on its existing wrapper while rendering the supplied child inside it.
- Classification
- Wrapper prop
Sidebar Menu Button
Inherits a attributes. Omits `type`.
Inherits button attributes.
Contains the following additional props:
boolean false
- Description
- Merges the component behavior and props into its child element.
- Classification
- Wrapper prop
boolean false
- Description
- Applies the active visual state.
- Classification
- Wrapper prop
"sm" | "md" | "lg" "md"
- Description
- Selects the component's visual size.
- Classification
- Styled variant
string —
- Description
- Provides collapsed-sidebar tooltip text for this menu button.
- Classification
- Wrapper prop
"default" | "outline" "default"
- Description
- Selects the component's visual variant.
- Classification
- Styled variant
Sidebar Menu Action
Inherits Button props.
Contains the following additional props:
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:
boolean false
- Description
- Shows the component's generated icon.
- Classification
- Wrapper prop
string —
- Description
- Sets the component width.
- Classification
- Wrapper prop
Sidebar Menu Sub Button
Inherits a attributes.
Contains the following additional props:
boolean false
- Description
- Applies the active visual state.
- Classification
- Wrapper prop
"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
createSidebarControllerfrom@starwind-ui/runtime/sidebar
Changelog
View version history v2.3.0 7 releases
v2.3.0
- Sidebar controls, rail, and reading-relative spacing follow the current direction.
- When
starwind addinstalls Sidebar, it now adds any missing sidebar color tokens to your CSS file. Colors that you set stay as they are. - A click during the Sidebar tooltip close animation now goes to the page below the tooltip. Before, the closing tooltip caught the click, so a quick click on a control under it did nothing.
- Sidebar tooltips now stay on screen when their trigger is at the edge of the screen, for example on a phone. Before, part of a tooltip could go off screen. Now the tooltip moves along its trigger until it is inside the viewport padding. It stays next to the trigger and keeps its side.
- In Vue, this component now needs Vue 3.5.21 or newer.
- Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.
v2.2.0
- In Astro, an attribute that you set on Sidebar and its parts now wins over the component’s own default for the same attribute, such as
roleoraria-label. - In Svelte, a defined
openormobileOpenthat you pass when SidebarProvider mounts now stays under your control, as in React and Vue. To change it, usebind:or update your state in the change callback. A form reset keeps it. If you passundefinedat mount, SidebarProvider keeps its own state. - In Svelte, a defined
valueonSidebarInputalso stays under your control, and the StyledSidebarMenuButtonkeepshref. - In Vue,
SidebarRailkeeps anaria-labelthat you set, andSidebarMenuButtonwithtooltipkeepsdata-slot="sidebar-menu-button". - In Vue, a Boolean prop that you leave out, such as
persistenceStorageonSidebarProvider, no longer becomesfalse. The default of the underlying component applies.
v2.1.3
- In Astro, a Sidebar that starts collapsed no longer opens for a moment when the page loads. Before, a
SidebarProviderwithdefaultOpen={false}showed the full sidebar first and then animated it closed, so the page content moved. Now the Sidebar is collapsed from the first paint. This also works withcollapsible="offcanvas". - In Astro, you can now show the state that
persistOpensaved on first paint. Read the cookie on the server in a page that renders on demand, and pass it todefaultOpen. - The Astro Sidebar and SidebarProvider no longer put the same attribute on an element two times. For example, the Sidebar had two
data-stateattributes. - Render the Astro Sidebar inside its
SidebarProviderslot. If you render it before the provider, for example withAstro.slots.render, it can show the wrong state until the page script runs. - If one page has more than one
SidebarProviderwith differentdefaultOpenvalues, an Astro Sidebar can still show open until the page script runs.
v2.1.2
- Fixed Svelte headings appearing disabled when they also open a collapsible section. Tooltips remain available in the collapsed sidebar.
- Fixed React Sidebar getting out of sync with saved state and handling nested mobile sheets incorrectly.
v2.1.1
- The default export in
index.tsnow has a name,SidebarParts, so framework tools show a clear name.
v2.1.0
- Renamed the standard
SidebarMenuButtonsize fromdefaulttomd. Omittingsizekeeps the same medium styling.
v2.0.0
- Sidebar now gets its behavior from Starwind Runtime. Runtime handles the provider, collapsed, and mobile states and the controls.
- See the Sidebar Primitive for the unstyled parts and the behavior API.