Overview
One place to find your way.
Try a page, open a group, or collapse the sidebar.
A home for your navigation. Collapsible groups, an icon rail, and a mobile drawer, built with Base UI.
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/sidebar.jsonCopies Sidebar and the components it uses (Input, Separator, and Tooltip) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/sidebar. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/react @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the cn() helper and the design tokens.
lib/sprout/classes.tsCopy and paste the following code into your project.
'use client';
import { ChevronRightIcon } from '@/lib/sprout/icons/chevron-right-icon';
import {
createContext,
useContext,
useEffect,
useId,
useRef,
useState,
useSyncExternalStore,
type ComponentProps,
type ReactNode,
type RefObject,
type SetStateAction,
} from 'react';
import { Button } from '@base-ui/react/button';
import { Dialog } from '@base-ui/react/dialog';
import type { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip';
import { Collapsible } from '@base-ui/react/collapsible';
import { cn, stateClassName } from '@/lib/sprout/classes';
import { Pressable } from '@/lib/sprout/pressable';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, type TooltipContentProps } from '@/components/ui/tooltip';
import { Input, type InputProps, type InputState } from '@/components/ui/input';
import { Separator, type SeparatorLineProps } from '@/components/ui/separator';
type TooltipContentState = TooltipPrimitive.Popup.State;
interface SidebarContextValue {
open: boolean;
setOpen: (open: SetStateAction<boolean>) => void;
openMobile: boolean;
setOpenMobile: (open: SetStateAction<boolean>) => void;
isMobile: boolean;
state: 'expanded' | 'collapsed';
toggleSidebar: () => void;
panelId: string;
triggerRef: RefObject<HTMLElement | null>;
}
const SidebarContext = createContext<SidebarContextValue | null>(null);
const PanelContext = createContext<{
collapsed: boolean;
side: 'left' | 'right';
portalContainer?: Dialog.Portal.Props['container'];
} | null>(null);
export function useSidebar() {
const context = useContext(SidebarContext);
if (!context) throw new Error('Sidebar parts must be inside SidebarProvider.');
return context;
}
function usePanel() {
const context = useContext(PanelContext);
if (!context) throw new Error('Sidebar navigation parts must be inside Sidebar.');
return context;
}
function subscribeMobile(callback: () => void) {
const media = window.matchMedia('(max-width: 767px)');
media.addEventListener('change', callback);
return () => media.removeEventListener('change', callback);
}
export interface SidebarProviderProps extends Omit<ComponentProps<'div'>, 'ref'> {
defaultOpen?: boolean;
open?: boolean;
onOpenChange?: (open: boolean) => void;
openMobile?: boolean;
onOpenMobileChange?: (open: boolean) => void;
keyboardShortcut?: boolean;
}
export function SidebarProvider({
defaultOpen = true,
open: controlledOpen,
onOpenChange,
openMobile: controlledMobile,
onOpenMobileChange,
keyboardShortcut = true,
className,
children,
...props
}: SidebarProviderProps) {
const [localOpen, setLocalOpen] = useState(defaultOpen);
const [localMobile, setLocalMobile] = useState(false);
const isMobile = useSyncExternalStore(
subscribeMobile,
() => window.matchMedia('(max-width: 767px)').matches,
() => false,
);
const open = controlledOpen ?? localOpen;
const openMobile = controlledMobile ?? localMobile;
const panelId = useId();
const triggerRef = useRef<HTMLElement | null>(null);
const wrapperRef = useRef<HTMLDivElement>(null);
function setOpen(value: SetStateAction<boolean>) {
const next = typeof value === 'function' ? value(open) : value;
if (controlledOpen === undefined) setLocalOpen(next);
onOpenChange?.(next);
}
function setOpenMobile(value: SetStateAction<boolean>) {
const next = typeof value === 'function' ? value(openMobile) : value;
if (controlledMobile === undefined) setLocalMobile(next);
onOpenMobileChange?.(next);
}
function toggleSidebar() {
if (isMobile) setOpenMobile(value => !value);
else setOpen(value => !value);
}
useEffect(() => {
if (!keyboardShortcut) return;
function onKeyDown(event: KeyboardEvent) {
if (
event.defaultPrevented ||
event.repeat ||
event.altKey ||
!(event.metaKey || event.ctrlKey) ||
event.key.toLowerCase() !== 'b'
)
return;
const target = event.target;
if (target instanceof Element) {
if (
target.closest(
'input, textarea, select, [role=combobox], [role=listbox], [role=menu], [aria-haspopup=menu], [contenteditable]:not([contenteditable=false])',
)
)
return;
const owner = target.closest('[data-sprout-sidebar-provider]');
if (owner && owner !== wrapperRef.current) return;
}
event.preventDefault();
toggleSidebar();
}
document.addEventListener('keydown', onKeyDown);
return () => document.removeEventListener('keydown', onKeyDown);
});
return (
<SidebarContext.Provider
value={{
open,
setOpen,
openMobile,
setOpenMobile,
isMobile,
state: open ? 'expanded' : 'collapsed',
toggleSidebar,
panelId,
triggerRef,
}}
>
<TooltipProvider delay={200}>
<div
{...props}
ref={wrapperRef}
data-sprout-sidebar-provider=""
className={cn('sprout-sidebar-layout font-sprout text-sprout-text', className)}
>
{children}
</div>
</TooltipProvider>
</SidebarContext.Provider>
);
}
export interface SidebarProps extends ComponentProps<'aside'> {
side?: 'left' | 'right';
collapsible?: 'icon' | 'offcanvas' | 'none';
label?: string;
portalContainer?: Dialog.Portal.Props['container'];
}
export function Sidebar({
side = 'left',
collapsible = 'icon',
label = 'Navigation',
portalContainer,
className,
children,
...props
}: SidebarProps) {
const { open, openMobile, setOpenMobile, isMobile, panelId, triggerRef } = useSidebar();
const mobile = isMobile && collapsible !== 'none';
const collapsed = !mobile && !open && collapsible === 'icon';
const offcanvas = !open && collapsible === 'offcanvas';
const content = (
<PanelContext.Provider value={{ collapsed, side, portalContainer }}>{children}</PanelContext.Provider>
);
if (mobile) {
return (
<Dialog.Root open={openMobile} onOpenChange={setOpenMobile}>
<Dialog.Portal container={portalContainer}>
<Dialog.Backdrop className="sprout-sidebar-backdrop" />
<Dialog.Popup
id={panelId}
data-side={side}
className="sprout-sidebar-drawer font-sprout text-sprout-text"
finalFocus={triggerRef}
>
<div className="sprout-sidebar-drawer-heading">
<Dialog.Title>{label}</Dialog.Title>
<Dialog.Close className="sprout-sidebar-close">Close</Dialog.Close>
</div>
<aside
{...props}
aria-label={label}
data-sprout-sidebar=""
data-state="expanded"
className={cn('sprout-sidebar-panel sprout-sidebar-mobile bg-sprout-canvas', className)}
>
{content}
</aside>
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>
);
}
return (
<aside
{...props}
id={panelId}
aria-label={label}
data-sprout-sidebar=""
data-state={collapsed ? 'collapsed' : 'expanded'}
data-side={side}
data-collapsible={collapsible}
data-offcanvas={offcanvas ? '' : undefined}
aria-hidden={offcanvas || undefined}
inert={offcanvas}
className={cn('sprout-sidebar-panel bg-sprout-canvas', className)}
>
{content}
</aside>
);
}
export function SidebarTrigger({ className, onClick, children = 'Toggle sidebar', ...props }: Button.Props) {
const { isMobile, open, openMobile, toggleSidebar, panelId, triggerRef } = useSidebar();
return (
<Button
aria-label="Toggle sidebar"
aria-expanded={isMobile ? openMobile : open}
aria-controls={panelId}
{...props}
className={stateClassName<Button.State>('sprout-sidebar-trigger', className)}
onClick={event => {
onClick?.(event);
if (event.defaultPrevented) return;
triggerRef.current = event.currentTarget;
toggleSidebar();
}}
>
{children}
</Button>
);
}
export function SidebarHeader({ className, ...props }: ComponentProps<'div'>) {
return <div {...props} className={cn('sprout-sidebar-header', className)} />;
}
export function SidebarInput({ className, ...props }: InputProps) {
return (
<Input
data-slot="sidebar-input"
data-sidebar="input"
{...props}
className={stateClassName<InputState>('sprout-sidebar-input', className)}
/>
);
}
export function SidebarFooter({ className, ...props }: ComponentProps<'div'>) {
return <div {...props} className={cn('sprout-sidebar-footer', className)} />;
}
export function SidebarSeparator({ className, ...props }: SeparatorLineProps) {
return (
<Separator data-sidebar="separator" {...props} className={stateClassName('sprout-sidebar-separator', className)} />
);
}
export function SidebarContent({ className, ...props }: ComponentProps<'div'>) {
return <div {...props} className={cn('sprout-sidebar-content', className)} />;
}
export function SidebarGroup({ className, ...props }: ComponentProps<'div'>) {
return <div {...props} className={cn('sprout-sidebar-group', className)} />;
}
export function SidebarGroupLabel({ className, ...props }: ComponentProps<'div'>) {
return <div {...props} className={cn('sprout-sidebar-group-label', className)} />;
}
export function SidebarMenu({ className, ...props }: ComponentProps<'ul'>) {
return <ul {...props} className={cn('sprout-sidebar-menu', className)} />;
}
export function SidebarMenuItem({ className, ...props }: ComponentProps<'li'>) {
return <li {...props} className={cn('sprout-sidebar-menu-item', className)} />;
}
export interface SidebarMenuButtonProps extends Button.Props {
icon?: ReactNode;
badge?: ReactNode;
isActive?: boolean;
tooltip?: string | TooltipContentProps;
}
export function SidebarMenuButton({
icon,
badge,
isActive = false,
tooltip,
className,
children,
onClick,
...props
}: SidebarMenuButtonProps) {
const { collapsed, side, portalContainer } = usePanel();
const { setOpenMobile } = useSidebar();
const content = typeof tooltip === 'string' ? { children: tooltip } : tooltip;
const { hidden: hideTooltip = !collapsed, ...contentProps } = content ?? {};
const accessibleLabel =
props['aria-label'] ??
(typeof content?.children === 'string' ? content.children : undefined) ??
(typeof children === 'string' ? children : undefined);
return (
<Tooltip disabled={hideTooltip || props.disabled}>
<TooltipTrigger
render={
<Pressable
{...props}
aria-label={accessibleLabel}
aria-current={props['aria-current'] ?? (isActive && props.nativeButton === false ? 'page' : undefined)}
data-active={isActive ? '' : undefined}
className={stateClassName<Button.State>('sprout-sidebar-menu-button', className)}
onClick={event => {
onClick?.(event);
if (
!event.defaultPrevented &&
props.nativeButton === false &&
!event.metaKey &&
!event.ctrlKey &&
!event.shiftKey &&
!event.altKey
)
setOpenMobile(false);
}}
/>
}
>
{icon && (
<span className="sprout-sidebar-icon" aria-hidden="true">
{icon}
</span>
)}
<span className="sprout-sidebar-label">{children}</span>
{badge != null && <span className="sprout-sidebar-badge">{badge}</span>}
</TooltipTrigger>
<TooltipContent
side={side === 'left' ? 'right' : 'left'}
sideOffset={8}
container={portalContainer}
{...contentProps}
className={stateClassName<TooltipContentState>('sprout-sidebar-tooltip', contentProps.className)}
>
{contentProps.children ?? children}
</TooltipContent>
</Tooltip>
);
}
export function SidebarMenuAction({ className, ...props }: Button.Props) {
usePanel();
return <Button {...props} className={stateClassName<Button.State>('sprout-sidebar-menu-action', className)} />;
}
export function SidebarMenuSub({ className, ...props }: ComponentProps<'ul'>) {
return <ul {...props} className={cn('sprout-sidebar-menu sprout-sidebar-sub', className)} />;
}
export const SidebarMenuSubItem = SidebarMenuItem;
export function SidebarMenuSubButton({ className, ...props }: SidebarMenuButtonProps) {
return (
<SidebarMenuButton {...props} className={stateClassName<Button.State>('sprout-sidebar-sub-button', className)} />
);
}
export interface SidebarSectionProps extends Omit<SidebarMenuButtonProps, 'onChange'> {
label: string;
children: ReactNode;
open?: boolean;
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
}
export function SidebarSection({
label,
children,
open: controlledOpen,
defaultOpen = false,
onOpenChange,
...props
}: SidebarSectionProps) {
const [localOpen, setLocalOpen] = useState(defaultOpen);
const { collapsed } = usePanel();
const open = !collapsed && (controlledOpen ?? localOpen);
return (
<SidebarMenuItem>
<Collapsible.Root
open={open}
onOpenChange={value => {
if (controlledOpen === undefined) setLocalOpen(value);
onOpenChange?.(value);
}}
>
<div className="sprout-sidebar-section-heading">
<SidebarMenuButton {...props}>{label}</SidebarMenuButton>
<Collapsible.Trigger render={<SidebarMenuAction aria-label={`${open ? 'Collapse' : 'Expand'} ${label}`} />}>
<ChevronRightIcon size="md" aria-hidden="true" className="sprout-sidebar-chevron" />
</Collapsible.Trigger>
</div>
<Collapsible.Panel className="sprout-sidebar-section-content" inert={!open}>
<SidebarMenuSub>{children}</SidebarMenuSub>
</Collapsible.Panel>
</Collapsible.Root>
</SidebarMenuItem>
);
}
export function SidebarMenuSkeleton({ className, ...props }: ComponentProps<'div'>) {
return (
<div {...props} aria-hidden="true" className={cn('sprout-sidebar-skeleton', className)}>
<span />
<span />
</div>
);
}And the files it imports:
lib/sprout/icons/chevron-right-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/pressable.tsxAdd the styles to your global CSS, after @import "tailwindcss".
@layer components {
.sprout-sidebar-layout {
isolation: isolate;
min-width: 0;
display: flex;
}
.sprout-sidebar-panel {
width: var(--sprout-sidebar-width, 15.25rem);
min-height: 0;
color: var(--sprout-text);
border-inline-end: 1px solid var(--sprout-line);
flex-direction: column;
flex: none;
display: flex;
}
.sprout-sidebar-panel[hidden] {
display: none;
}
.sprout-sidebar-panel[data-side="right"] {
border-inline-end: 0;
border-inline-start: 1px solid var(--sprout-line);
}
.sprout-sidebar-panel[data-state="collapsed"] {
width: var(--sprout-sidebar-icon-width, 3.5rem);
}
.sprout-sidebar-panel[data-collapsible="icon"], .sprout-sidebar-panel[data-collapsible="offcanvas"] {
overflow: clip;
}
.sprout-sidebar-panel[data-offcanvas] {
opacity: 0;
visibility: hidden;
border-inline-width: 0;
width: 0;
}
.sprout-sidebar-header, .sprout-sidebar-footer {
flex-shrink: 0;
padding: 12px 8px;
}
.sprout-sidebar-header {
box-sizing: border-box;
min-height: var(--sprout-bar-height);
flex-direction: column;
justify-content: center;
padding-block: 0;
display: flex;
}
.sprout-input.sprout-sidebar-input:not(:disabled) {
background-color: var(--sprout-canvas);
}
.sprout-sidebar-footer {
margin-top: auto;
}
.sprout-sidebar-content {
overscroll-behavior: contain;
scrollbar-width: thin;
flex: 1;
min-height: 0;
overflow: auto;
}
.sprout-sidebar-group {
padding: 20px 8px 0;
}
.sprout-separator.sprout-sidebar-separator {
width: auto;
margin-inline: 8px;
}
.sprout-sidebar-content > .sprout-sidebar-separator, .sprout-sidebar-content > * > .sprout-sidebar-separator {
margin-top: 16px;
}
.sprout-sidebar-group:last-child {
padding-bottom: 16px;
}
.sprout-sidebar-group-label {
color: var(--sprout-muted);
padding: 0 12px 6px;
font-size: .875rem;
line-height: 20px;
}
.sprout-sidebar-menu {
gap: 2px;
margin: 0;
padding: 0;
list-style: none;
display: grid;
}
.sprout-sidebar-menu-item {
min-width: 0;
position: relative;
}
.sprout-sidebar-menu-button, .sprout-sidebar-menu-action, .sprout-sidebar-trigger, .sprout-sidebar-close {
box-sizing: border-box;
font: inherit;
color: var(--sprout-text);
border-radius: var(--sprout-radius-control);
cursor: pointer;
background: none;
border: 0;
outline: none;
}
.sprout-sidebar-menu-button {
text-align: start;
width: 100%;
min-width: 0;
min-height: 34px;
color: var(--sprout-text);
align-items: center;
gap: 10px;
padding: 6px 12px;
font-size: .875rem;
font-weight: 400;
line-height: 20px;
text-decoration: none;
display: flex;
}
@media (hover: hover) {
.sprout-sidebar-menu-button:hover, .sprout-sidebar-menu-action:hover, .sprout-sidebar-trigger:hover, .sprout-sidebar-close:hover {
background: var(--sprout-hover);
color: var(--sprout-text);
}
}
.sprout-sidebar-menu-button[data-active] {
background: var(--sprout-active);
color: var(--sprout-text);
font-weight: 500;
}
.sprout-sidebar-menu-button:focus-visible, .sprout-sidebar-menu-action:focus-visible, .sprout-sidebar-trigger:focus-visible, .sprout-sidebar-close:focus-visible {
outline: var(--sprout-focus-width) solid var(--sprout-focus-ring);
outline-offset: -1px;
}
.sprout-sidebar-menu-button:disabled, .sprout-sidebar-menu-button[data-disabled] {
opacity: .5;
cursor: not-allowed;
background: none;
}
.sprout-sidebar-icon {
flex-shrink: 0;
justify-content: center;
align-items: center;
width: 18px;
height: 20px;
display: inline-flex;
}
.sprout-sidebar-icon > svg {
width: 18px;
height: 18px;
}
.sprout-sidebar-label {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.sprout-sidebar-badge {
background: var(--sprout-surface);
color: var(--sprout-muted);
font-size: var(--sprout-text-xs);
font-variant-numeric: tabular-nums;
border-radius: 4px;
margin-inline-start: auto;
padding-inline: 5px;
}
.sprout-sidebar-menu-action {
inset-inline-end: 4px;
width: calc(var(--sprout-control-height) - 8px);
height: calc(var(--sprout-control-height) - 8px);
place-items: center;
display: grid;
position: absolute;
top: 5px;
}
.sprout-sidebar-menu-item:has(.sprout-sidebar-menu-action) > .sprout-sidebar-menu-button, .sprout-sidebar-section-heading > .sprout-sidebar-menu-button {
padding-inline-end: 36px;
}
.sprout-sidebar-section-heading {
position: relative;
}
.sprout-sidebar-chevron {
display: block;
}
.sprout-sidebar-menu-action[data-panel-open] .sprout-sidebar-chevron {
transform: rotate(90deg);
}
.sprout-sidebar-sub {
border-left: 1px solid var(--sprout-line);
margin: 4px 0 6px 18px;
padding-left: 8px;
}
.sprout-sidebar-sub-button {
min-height: calc(var(--sprout-control-height) - 4px);
font-size: var(--sprout-text-xs);
line-height: 16px;
}
.sprout-sidebar-section-content {
height: var(--collapsible-panel-height);
overflow: hidden;
}
.sprout-sidebar-section-content[data-starting-style], .sprout-sidebar-section-content[data-ending-style] {
opacity: 0;
height: 0;
}
.sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-label, .sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-badge, .sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-group-label, .sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-menu-action {
display: none;
}
.sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-menu-button {
justify-content: center;
padding-inline: 0;
}
.sprout-sidebar-trigger {
min-width: var(--sprout-control-height);
min-height: var(--sprout-control-height);
font-size: var(--sprout-text-xs);
justify-content: center;
align-items: center;
gap: 8px;
padding: 6px;
display: inline-flex;
}
.sprout-sidebar-skeleton {
box-sizing: border-box;
min-height: var(--sprout-control-height);
align-items: center;
gap: 10px;
padding: 6px 10px;
display: flex;
}
.sprout-sidebar-skeleton span {
background: var(--sprout-line);
border-radius: 4px;
height: 12px;
display: block;
}
.sprout-sidebar-skeleton span:first-child {
flex-shrink: 0;
width: 18px;
height: 18px;
}
.sprout-sidebar-skeleton span:last-child {
width: 65%;
}
.sprout-sidebar-panel[data-state="collapsed"] .sprout-sidebar-skeleton span:last-child {
display: none;
}
.sprout-sidebar-backdrop {
z-index: 40;
background: var(--sprout-overlay);
position: fixed;
inset: 0;
}
.sprout-sidebar-drawer {
inset-block: 0;
z-index: 50;
width: min(var(--sprout-sidebar-mobile-width, 18rem), calc(100vw - 2rem));
background: var(--sprout-sidebar);
box-shadow: var(--sprout-shadow-overlay);
outline: none;
flex-direction: column;
display: flex;
position: fixed;
left: 0;
}
.sprout-sidebar-drawer[data-side="right"] {
left: auto;
right: 0;
}
.sprout-sidebar-drawer-heading {
border-bottom: 1px solid var(--sprout-line);
min-height: 56px;
font-size: var(--sprout-text-sm);
flex-shrink: 0;
justify-content: space-between;
align-items: center;
padding: 8px 16px;
font-weight: 550;
display: flex;
}
.sprout-sidebar-close {
min-height: 40px;
font-size: var(--sprout-text-xs);
padding: 8px;
}
.sprout-sidebar-mobile {
border: 0;
flex: 1;
width: 100%;
overflow: hidden;
}
@media (width <= 767px) {
.sprout-sidebar-menu-button, .sprout-sidebar-menu-action, .sprout-sidebar-trigger {
min-height: 44px;
}
.sprout-sidebar-menu-action {
width: 36px;
top: 0;
}
}
@media (prefers-reduced-motion: no-preference) {
.sprout-sidebar-panel[data-collapsible="icon"], .sprout-sidebar-panel[data-collapsible="offcanvas"] {
transition: width var(--sprout-motion-normal) var(--sprout-motion-ease),
opacity var(--sprout-motion-fast) ease-out,
visibility 0s;
}
.sprout-sidebar-panel[data-offcanvas] {
transition-delay: 0s, 0s, var(--sprout-motion-normal);
}
.sprout-sidebar-chevron {
transition: transform var(--sprout-motion-fast) var(--sprout-motion-ease);
}
.sprout-sidebar-section-content {
transition: height var(--sprout-motion-normal) var(--sprout-motion-ease),
opacity var(--sprout-motion-fast) ease-out;
}
.sprout-sidebar-section-content[data-ending-style] {
transition-duration: var(--sprout-motion-fast);
}
.sprout-sidebar-menu-button, .sprout-sidebar-menu-action, .sprout-sidebar-trigger, .sprout-sidebar-close {
transition: background-color var(--sprout-motion-fast) ease-out,
color var(--sprout-motion-fast) ease-out;
}
.sprout-sidebar-drawer {
transition: transform var(--sprout-motion-normal) var(--sprout-motion-ease);
}
.sprout-sidebar-drawer[data-ending-style] {
transition-duration: var(--sprout-motion-fast);
}
.sprout-sidebar-drawer[data-starting-style], .sprout-sidebar-drawer[data-ending-style] {
transform: translateX(-100%);
}
.sprout-sidebar-drawer[data-side="right"][data-starting-style], .sprout-sidebar-drawer[data-side="right"][data-ending-style] {
transform: translateX(100%);
}
.sprout-sidebar-backdrop {
transition: opacity var(--sprout-motion-fast) ease-out;
}
.sprout-sidebar-backdrop[data-starting-style], .sprout-sidebar-backdrop[data-ending-style] {
opacity: 0;
}
}
.sprout-chat-split {
flex: 1;
min-width: 0;
height: 100%;
min-height: 0;
display: flex;
overflow: hidden;
}
.sprout-chat-split-pane, .sprout-canvas-host {
box-sizing: border-box;
flex-direction: column;
width: 100%;
min-width: 0;
height: 100%;
min-height: 0;
display: flex;
overflow: hidden;
}
.sprout-canvas-sheet {
overflow: hidden;
}
.sprout-canvas {
box-sizing: border-box;
background: var(--sprout-surface);
min-width: 0;
height: 100%;
min-height: 0;
color: var(--sprout-text);
font-family: var(--sprout-font);
font-size: var(--sprout-text-sm);
flex-direction: column;
line-height: 1.25rem;
display: flex;
}
.sprout-canvas-back {
border-bottom: 1px solid var(--sprout-line);
flex-shrink: 0;
padding: 4px 8px;
}
.sprout-canvas-header {
box-sizing: border-box;
border-bottom: 1px solid var(--sprout-line);
flex-shrink: 0;
align-items: center;
gap: 4px;
height: 44px;
padding: 0 8px 0 4px;
display: flex;
}
.sprout-canvas-heading {
min-width: 0;
color: var(--sprout-text);
font-size: var(--sprout-text-sm);
outline: none;
flex: 1;
margin: 0;
padding: 0 8px;
font-weight: 500;
line-height: 1.25rem;
}
.sprout-canvas-tabs {
scrollbar-width: none;
flex: 1;
align-items: center;
min-width: 0;
display: flex;
position: relative;
overflow-x: auto;
}
.sprout-canvas-tabs::-webkit-scrollbar {
display: none;
}
.sprout-canvas-tablist {
display: contents;
}
.sprout-canvas-tab, .sprout-canvas-tab-close {
height: 32px;
color: var(--sprout-muted);
cursor: pointer;
transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease),
color var(--sprout-motion-fast) var(--sprout-motion-ease),
opacity var(--sprout-motion-fast) var(--sprout-motion-ease);
background: none;
border: 0;
outline: none;
flex-shrink: 0;
margin: 0;
}
.sprout-canvas-tab {
border-radius: var(--sprout-radius-control) 0 0 var(--sprout-radius-control);
min-width: 0;
max-width: 10.5rem;
font: inherit;
align-items: center;
gap: 6px;
padding: 0 2px 0 8px;
font-size: .8125rem;
font-weight: 500;
line-height: 1.25rem;
display: flex;
}
.sprout-canvas-tab-close {
border-radius: 0 var(--sprout-radius-control) var(--sprout-radius-control) 0;
justify-content: center;
align-items: center;
width: 28px;
margin-right: 2px;
padding: 0;
display: flex;
position: relative;
}
.sprout-canvas-tab-close > svg {
opacity: 0;
transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease);
position: relative;
}
.sprout-canvas-tab-close:before {
border-radius: calc(var(--sprout-radius-control) - 2px);
content: "";
transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease);
position: absolute;
inset: 6px 4px;
}
.sprout-canvas-tab[data-hover], .sprout-canvas-tab-close[data-hover] {
background: color-mix(in srgb, var(--sprout-hover) 70%, transparent);
color: var(--sprout-text);
}
.sprout-canvas-tab[data-active], .sprout-canvas-tab-close[data-active] {
background: var(--sprout-hover);
color: var(--sprout-text);
}
.sprout-canvas-tab-close[data-hover] > svg, .sprout-canvas-tab-close[data-active] > svg, .sprout-canvas-tab-close:focus-visible > svg {
opacity: 1;
}
.sprout-canvas-tab-close:hover:before {
background: var(--sprout-surface);
}
.sprout-canvas-tab:focus-visible, .sprout-canvas-tab-close:focus-visible {
outline: var(--sprout-focus-width) solid var(--sprout-focus-ring);
outline-offset: -1px;
}
.sprout-canvas-tab-icon {
flex-shrink: 0;
display: inline-flex;
}
.sprout-canvas-tab-title {
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
overflow: hidden;
}
.sprout-canvas-body {
outline: none;
flex-direction: column;
flex: 1;
min-height: 0;
display: flex;
overflow: auto;
}
.sprout-canvas-body:focus-visible {
outline: var(--sprout-focus-width) solid var(--sprout-focus-ring);
outline-offset: -1px;
}
.sprout-canvas-toggle-count {
box-sizing: border-box;
background: var(--sprout-secondary);
min-width: 16px;
color: var(--sprout-text);
font-variant-numeric: tabular-nums;
text-align: center;
border-radius: 999px;
padding: 0 4px;
font-size: .6875rem;
line-height: 1rem;
}
@media (width <= 639px) {
.sprout-canvas-toggle-label {
clip-path: inset(50%);
white-space: nowrap;
width: 1px;
height: 1px;
position: absolute;
overflow: hidden;
}
}
.sprout-canvas-section {
box-sizing: border-box;
min-width: 0;
min-height: 0;
color: var(--sprout-text);
font-family: var(--sprout-font);
font-size: var(--sprout-text-sm);
flex-direction: column;
flex: 1;
gap: 16px;
padding: 16px;
line-height: 1.25rem;
display: flex;
}
.sprout-canvas-section-header {
flex-wrap: wrap;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
display: flex;
}
.sprout-canvas-section-text {
min-width: 0;
}
.sprout-canvas-section-title {
color: var(--sprout-text);
font-size: var(--sprout-text-base);
overflow-wrap: anywhere;
margin: 0;
font-weight: 500;
line-height: 1.5rem;
}
.sprout-canvas-section-meta {
color: var(--sprout-muted);
font-size: var(--sprout-text-xs);
overflow-wrap: anywhere;
margin: 2px 0 0;
line-height: 1rem;
}
.sprout-canvas-section-actions {
flex-wrap: wrap;
flex-shrink: 0;
align-items: center;
gap: 8px;
display: flex;
}
@media (width >= 640px) {
.sprout-canvas-section {
padding: 20px;
}
}
.sprout-canvas-frame {
border: 1px solid var(--sprout-line);
border-radius: var(--sprout-radius-panel);
background: var(--sprout-canvas);
flex: 1;
min-height: 20rem;
display: flex;
overflow: hidden;
}
.sprout-canvas-frame > iframe {
border: 0;
flex: 1;
width: 100%;
height: 100%;
min-height: 20rem;
}
.sprout-canvas-sr-only {
clip-path: inset(50%);
white-space: nowrap;
border: 0;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
position: absolute;
overflow: hidden;
}
@media (pointer: coarse) {
.sprout-canvas-tab-close {
width: 32px;
}
.sprout-canvas-tab-close > svg {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {
.sprout-canvas-tab, .sprout-canvas-tab-close, .sprout-canvas-tab-close > svg, .sprout-canvas-tab-close:before {
transition: none;
}
}
@media (forced-colors: active) {
.sprout-canvas-tab[data-active], .sprout-canvas-tab-close[data-active] {
border-block: 1px solid canvastext;
}
.sprout-canvas-tab-close > svg {
opacity: 1;
}
}
}Import it from @/components/ui/sidebar. Update the paths if your @/ alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/sidebar.
import {
Sidebar, SidebarProvider, SidebarContent,
SidebarGroup, SidebarMenu, SidebarMenuItem,
SidebarMenuButton, SidebarTrigger,
} from "@tulipfarm/sprout/sidebar";
<SidebarProvider className="min-h-dvh">
<Sidebar label="Main navigation">
<SidebarContent>
<SidebarGroup>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
icon={<HomeIcon />}
nativeButton={false}
render={<a href="/overview" />}
isActive
>
Overview
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
</Sidebar>
<main className="min-w-0 flex-1">
<SidebarTrigger />
{children}
</main>
</SidebarProvider>Supply icons from your own icon library. Use the render prop with your router's link and nativeButton= for navigation. Use a normal button for actions.
SidebarProvider owns open state. Sidebar handles the panel and mobile drawer. SidebarHeader and SidebarFooter stay visible while SidebarContent scrolls. Put aSidebarInput in the header to search or filter the menu; it is an Input on the canvas color.
SidebarGroup and SidebarGroupLabel organize a SidebarMenu. Each SidebarMenuItem contains a SidebarMenuButton, with optional icon, badge, isActive, and tooltip props. Give complex labels an explicit aria-label or tooltip.
SidebarMenuAction adds a separate action. SidebarSection combines a navigation link with an independent disclosure button. Put SidebarMenuSubItem and SidebarMenuSubButton inside it. For a custom composition, use SidebarMenuSub directly.
<SidebarSection
label="Projects"
icon={<FolderIcon />}
nativeButton={false}
render={<a href="/projects" />}
defaultOpen
>
<SidebarMenuSubItem>
<SidebarMenuSubButton
nativeButton={false}
render={<a href="/projects/website" />}
>
Website refresh
</SidebarMenuSubButton>
</SidebarMenuSubItem>
</SidebarSection>The label navigates; the arrow expands. Collapsing the whole sidebar hides nested links without forgetting which sections were open. Sections also accept open and onOpenChange.
Sidebar supports side="left" or "right", and collapsible="icon", "offcanvas", or "none". Put a right sidebar after your content in the DOM. The provider follows its container's height; give it a viewport height or a bounded preview height.
SidebarProvider accepts defaultOpen, or controlled open / onOpenChange. Mobile state is separate through openMobile / onOpenMobileChange. useSidebar() exposes these states, their setters, isMobile, state, and toggleSidebar().
Saving preferences belongs to the application. This preview stores its open state in local storage; the package never writes cookies or storage. For server rendering, pass your saved preference as defaultOpen.
Below 768px, collapsible sidebars become modal drawers. Base UI handles focus trapping, Escape dismissal, and scroll locking. Links close the drawer; custom navigation handlers can call setOpenMobile(false). A visible Close action is always provided.
Tab follows normal link order. Enter activates links; Enter or Space toggles disclosures. Icon-only items keep accessible names and show tooltips on hover or focus. Set keyboardShortcut= on the provider to disable Cmd/Ctrl+B. The shortcut does not run inside editable fields.
SidebarMenuSkeleton provides a static loading row. SidebarSeparator draws an inset line between groups. Your application supplies loading announcements, empty messages, error messages, and retry actions. Routes, permissions, workspace switchers, account menus, and data fetching are not part of the package.