Sidebar
App navigation along the left edge, from a full collapsible sidebar to a single rail or a menu behind a button. Eight variants, each one file.
Collapsible
An app sidebar with sections that folds down to an icon rail. The active item’s surface glides between rows.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui/sidebarOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/sidebar
import { AnimatePresence, motion, MotionConfig, useReducedMotion, type Variants } from "motion/react";
import { useEffect, useId, useState, type ElementType, type MouseEvent, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const OPEN_WIDTH = 240;
const CLOSED_WIDTH = 60;
const EASE_OUT = [0.16, 1, 0.3, 1] as const;
// Damped just past critical: the width settles against the rail without overshooting it.
const WIDTH_SPRING = { type: "spring", stiffness: 380, damping: 36, mass: 0.8 } as const;
// The surfaces that follow the active page and the pointer.
const GLIDE = { type: "spring", stiffness: 520, damping: 42 } as const;
// Pages under a group unfold in height, so rows below glide down instead of jumping,
// then arrive one after another. Closing runs the stagger in reverse, quicker.
const SUBMENU: Variants = {
closed: { height: 0, opacity: 0, transition: { duration: 0.18, ease: EASE_OUT, staggerChildren: 0.02, staggerDirection: -1 } },
open: { height: "auto", opacity: 1, transition: { duration: 0.26, ease: EASE_OUT, delayChildren: 0.03, staggerChildren: 0.04 } },
};
const SUBMENU_ROW: Variants = {
closed: { opacity: 0, y: -4, filter: "blur(2px)" },
open: { opacity: 1, y: 0, filter: "blur(0px)", transition: { duration: 0.2, ease: EASE_OUT } },
};
export type SidebarPage = { value: string; label: string; href?: string };
export type SidebarItem = {
value: string;
label: string;
icon: ReactNode;
href?: string;
/** Pages tucked under this item. The item becomes a group that unfolds. */
children?: SidebarPage[];
};
export type SidebarSection = { title?: string; items: SidebarItem[] };
type SidebarProps = {
/** Name shown at the top, e.g. the workspace. */
title: ReactNode;
/** A small mark shown at the top, which is all that remains when collapsed. */
logo: ReactNode;
sections: SidebarSection[];
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
defaultCollapsed?: boolean;
/** Groups open at first. Defaults to the group holding the current page. */
defaultOpen?: string[];
/** Renders page links, e.g. Next.js Link, so navigation stays client-side. Defaults to <a>. */
linkComponent?: ElementType;
className?: string;
};
/**
* An app sidebar that folds down to an icon rail. Labels slide away and back, groups unfold
* their pages one after another, and the active surface glides wherever the current page is.
*/
export function Sidebar({
title,
logo,
sections,
value,
defaultValue,
onValueChange,
defaultCollapsed = false,
defaultOpen,
linkComponent: Link = "a",
className,
}: SidebarProps) {
const reduce = useReducedMotion() ?? false;
const ids = useId();
const [internal, setInternal] = useState(defaultValue ?? sections[0]?.items[0]?.value);
const [collapsed, setCollapsed] = useState(defaultCollapsed);
const [hovered, setHovered] = useState<string | null>(null);
const current = value ?? internal;
const items = sections.flatMap((s) => s.items);
const [open, setOpen] = useState<string[]>(
() => defaultOpen ?? items.filter((i) => i.children?.some((c) => c.value === current)).map((i) => i.value),
);
// Ctrl+B or ⌘B folds and unfolds the sidebar, except while writing rich text.
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (event.key.toLowerCase() !== "b" || !(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey) return;
if (event.target instanceof Element && event.target.closest("[contenteditable='true']")) return;
event.preventDefault();
setCollapsed((c) => !c);
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
const select = (page: SidebarPage) => (event: MouseEvent) => {
if (!page.href) event.preventDefault();
if (value === undefined) setInternal(page.value);
onValueChange?.(page.value);
};
const toggleGroup = (group: string) => {
// From the rail, a group can't show its pages: unfold the sidebar and open the group there.
if (collapsed) {
setCollapsed(false);
setOpen((o) => (o.includes(group) ? o : [...o, group]));
return;
}
setOpen((o) => (o.includes(group) ? o.filter((g) => g !== group) : [...o, group]));
};
const surfaces = (row: string, active: boolean) => (
<>
<AnimatePresence>
{hovered === row && !active ? (
<motion.span
layoutId={`${ids}-hover`}
aria-hidden
className="absolute inset-0 rounded-lg bg-background/60"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0, transition: { duration: 0.1 } }}
/>
) : null}
</AnimatePresence>
{active ? <motion.span layoutId={`${ids}-active`} aria-hidden className="absolute inset-0 rounded-lg bg-background shadow-raised" /> : null}
</>
);
const rowClass = (active: boolean) =>
cn(
"relative flex h-9 w-full items-center gap-2.5 rounded-lg px-[11px] text-left text-sm transition-colors duration-150 [&_svg]:size-[18px] [&_svg]:shrink-0",
active ? "font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
);
const press = reduce ? undefined : { scale: 0.98 };
return (
<MotionConfig transition={reduce ? { duration: 0 } : GLIDE}>
<motion.aside
className={cn("flex h-full shrink-0 flex-col gap-4 overflow-hidden bg-muted p-2.5", className)}
initial={false}
animate={{ width: collapsed ? CLOSED_WIDTH : OPEN_WIDTH }}
transition={reduce ? { duration: 0 } : WIDTH_SPRING}
>
<div className="flex h-10 items-center gap-2.5 pl-[7px]">
<span className="grid size-[26px] shrink-0 place-items-center rounded-md bg-primary text-primary-foreground [&_svg]:size-4" aria-hidden>
{logo}
</span>
<Label show={!collapsed} reduce={reduce} className="flex-1 text-sm font-semibold">
{title}
</Label>
</div>
<nav aria-label="Main" className="grid flex-1 content-start gap-4" onPointerLeave={() => setHovered(null)}>
{sections.map((section, i) => (
<div key={section.title ?? i} className="grid gap-0.5">
{section.title ? (
<div className="flex h-6 items-center px-[11px]">
<Label show={!collapsed} reduce={reduce} className="text-[12px] font-medium text-muted-foreground">
{section.title}
</Label>
</div>
) : null}
{section.items.map((item) => {
const isOpen = open.includes(item.value) && !collapsed;
const holdsCurrent = item.children?.some((c) => c.value === current) ?? false;
// A closed group stands in for the page inside it, so the rail still says where you are.
const active = item.value === current || (holdsCurrent && !isOpen);
const content = (
<>
{surfaces(item.value, active)}
<span className="relative">{item.icon}</span>
<Label show={!collapsed} reduce={reduce} className="relative flex-1">
{item.label}
</Label>
{item.children ? (
<motion.svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="relative !size-3.5 text-muted-foreground"
initial={false}
animate={{ rotate: isOpen ? 90 : 0, opacity: collapsed ? 0 : 1 }}
aria-hidden
>
<path d="M6 4l4 4-4 4" />
</motion.svg>
) : null}
</>
);
return (
<div key={item.value}>
{item.children ? (
<motion.button
type="button"
onClick={() => toggleGroup(item.value)}
onPointerEnter={() => setHovered(item.value)}
aria-expanded={isOpen}
aria-label={collapsed ? item.label : undefined}
title={collapsed ? item.label : undefined}
whileTap={press}
className={rowClass(active)}
>
{content}
</motion.button>
) : (
<motion.div whileTap={press}>
<Link
href={item.href ?? "#"}
onClick={select(item)}
onPointerEnter={() => setHovered(item.value)}
aria-current={item.value === current ? "page" : undefined}
aria-label={collapsed ? item.label : undefined}
title={collapsed ? item.label : undefined}
className={rowClass(active)}
>
{content}
</Link>
</motion.div>
)}
{item.children ? (
<AnimatePresence initial={false}>
{isOpen ? (
<motion.ul
key="pages"
className="grid gap-0.5 overflow-hidden pt-0.5"
variants={reduce ? undefined : SUBMENU}
initial={reduce ? false : "closed"}
animate="open"
exit={reduce ? undefined : "closed"}
>
{item.children.map((page) => {
const pageActive = page.value === current;
return (
<motion.li key={page.value} variants={reduce ? undefined : SUBMENU_ROW} whileTap={press}>
<Link
href={page.href ?? "#"}
onClick={select(page)}
onPointerEnter={() => setHovered(page.value)}
aria-current={pageActive ? "page" : undefined}
className={cn(rowClass(pageActive), "h-8 pl-[40px] text-[13px]")}
>
{surfaces(page.value, pageActive)}
<span className="relative truncate">{page.label}</span>
</Link>
</motion.li>
);
})}
</motion.ul>
) : null}
</AnimatePresence>
) : null}
</div>
);
})}
</div>
))}
</nav>
<motion.button
type="button"
onClick={() => setCollapsed((c) => !c)}
aria-expanded={!collapsed}
aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
aria-keyshortcuts="Control+B Meta+B"
title={collapsed ? "Expand (Ctrl or ⌘ B)" : "Collapse (Ctrl or ⌘ B)"}
whileTap={press}
className="flex h-9 shrink-0 items-center gap-2.5 rounded-lg px-[11px] text-sm text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground"
>
<motion.svg
viewBox="0 0 18 18"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="size-[18px] shrink-0"
initial={false}
animate={{ rotate: collapsed ? 180 : 0 }}
aria-hidden
>
<path d="M3 3.5h12v11H3zM7 3.5v11M12 7l-2 2 2 2" />
</motion.svg>
<Label show={!collapsed} reduce={reduce}>
Collapse
</Label>
</motion.button>
</motion.aside>
</MotionConfig>
);
}
/**
* Text that slides away as the sidebar narrows and back once it has room. It stays mounted,
* so nothing reflows mid-animation: leaving is quick, arriving waits for the width to open.
*/
function Label({ show, reduce, className, children }: { show: boolean; reduce: boolean; className?: string; children: ReactNode }) {
return (
<motion.span
aria-hidden={!show}
className={cn("truncate whitespace-nowrap", !show && "pointer-events-none", className)}
initial={false}
animate={show ? { opacity: 1, x: 0 } : { opacity: 0, x: -4 }}
transition={reduce ? { duration: 0 } : show ? { duration: 0.2, delay: 0.08, ease: EASE_OUT } : { duration: 0.1, ease: EASE_OUT }}
>
{children}
</motion.span>
);
}States
- Expanded
- Logo and name, section titles, and items with icons and labels.
- Active
- A raised surface sits behind the current page and glides to the next one.
- Collapsing
- Width springs down to 60 px; labels fade first so text never squashes.
- Collapsed
- Icons only. Each link keeps its name for screen readers and as a native tooltip.
- Links
- Items are real links with aria-current="page", so they work with any router.
- Reduced motion
- Width and surface change instantly.
Notes
Pass href on items to navigate; leave it off to handle selection yourself, as the demo does.
On phones, show the expanded sidebar in a sheet instead of collapsing it.
Rail
A narrow icon rail that opens into a full sidebar. Closed, names slide out beside each icon on hover or focus; open, they sit beside the icons.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui-pro/sidebar-railA paid component. The command needs the token from your account in STILLUI_TOKEN; your account page shows the one-time setup.
This is a paid component. Its source and install come with access.
States
- Open and closed
- The button under the logo widens the rail to show each name and the title, and folds it back. Pass expanded and onExpandedChange to remember it.
- Active
- A raised tile sits behind the current icon and glides to the next one.
- Hover
- While closed, the name slides out to the right after a short pause, so sweeping the rail stays quiet.
- Keyboard focus
- The name shows at once when an icon is focused.
- Unread
- A small dot on the icon, also added to its accessible name.
- Groups
- Pass groups instead of items to split the list. Open, each run has a small title; closed, a gap separates them and the icons stay put.
- Footer
- Optional items pinned to the bottom, in their own labelled nav.
- Many items
- The list scrolls between the logo and the footer; names shown on hover still hang outside the rail.
- Reduced motion
- The rail opens at once, the tile jumps and names appear without sliding.
Notes
Rails suit apps with a handful of top-level places that people already know.
The aside carries data-expanded, so a layout can make room for it, e.g. body:has([data-expanded=true]) to pad the page.
Tree
Grouped pages hanging from a thin guide line, for docs and settings. The active page lights up its stretch of the line.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui/sidebar-treeOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/sidebar#tree
import { AnimatePresence, motion, MotionConfig, useReducedMotion } from "motion/react";
import { useId, useState, type ElementType, type MouseEvent, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const SPRING = { type: "spring", stiffness: 420, damping: 40 } as const;
export type TreeLink = { value: string; label: string; href?: string };
export type TreeGroup = { value: string; label: string; icon: ReactNode; children: TreeLink[] };
type SidebarTreeProps = {
groups: TreeGroup[];
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
defaultOpen?: string[];
/** Renders page links, e.g. Next.js Link, so navigation stays client-side. Defaults to <a>. */
linkComponent?: ElementType;
className?: string;
};
/** Grouped pages hanging from a thin guide line. The active page lights up its stretch of the line. */
export function SidebarTree({ groups, value, defaultValue, onValueChange, defaultOpen, linkComponent: Link = "a", className }: SidebarTreeProps) {
const reduce = useReducedMotion();
const markerId = useId();
const [internal, setInternal] = useState(defaultValue ?? groups[0]?.children[0]?.value);
const [open, setOpen] = useState<string[]>(defaultOpen ?? groups.slice(0, 1).map((g) => g.value));
const current = value ?? internal;
const select = (link: TreeLink) => (event: MouseEvent) => {
if (!link.href) event.preventDefault();
if (value === undefined) setInternal(link.value);
onValueChange?.(link.value);
};
const toggle = (group: string) => setOpen((o) => (o.includes(group) ? o.filter((g) => g !== group) : [...o, group]));
return (
<MotionConfig transition={reduce ? { duration: 0 } : SPRING}>
<nav aria-label="Docs" className={cn("h-full w-60 shrink-0 overflow-y-auto bg-muted p-3", className)}>
<ul className="grid gap-1">
{groups.map((group) => {
const expanded = open.includes(group.value);
const holdsActive = group.children.some((c) => c.value === current);
return (
<li key={group.value}>
<button
type="button"
onClick={() => toggle(group.value)}
aria-expanded={expanded}
className={cn(
"flex h-9 w-full items-center gap-2.5 rounded-lg px-2.5 text-sm transition-[color,background-color,box-shadow,scale] active:scale-[0.98] hover:bg-background/60 [&>svg:first-child]:size-[18px]",
holdsActive ? "font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
)}
>
{group.icon}
<span className="flex-1 text-left">{group.label}</span>
<motion.svg
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="size-3.5 text-faint-foreground"
animate={{ rotate: expanded ? 90 : 0 }}
aria-hidden
>
<path d="M6 4l4 4-4 4" />
</motion.svg>
</button>
<AnimatePresence initial={false}>
{expanded ? (
<motion.ul
className="relative ml-[19px] overflow-hidden"
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
>
{/* The guide line every child hangs from. */}
<span aria-hidden className="absolute bottom-1 left-0 top-1 w-px bg-input" />
{group.children.map((link) => {
const active = link.value === current;
return (
<li key={link.value} className="relative">
{active ? (
<motion.span layoutId={markerId} aria-hidden className="absolute bottom-1.5 left-[-0.5px] top-1.5 w-0.5 rounded-full bg-foreground" />
) : null}
<Link
href={link.href ?? "#"}
onClick={select(link)}
aria-current={active ? "page" : undefined}
className={cn(
"flex h-8 items-center pl-4 pr-2 text-[13px] transition-[color,background-color,box-shadow,scale] active:scale-[0.98]",
active ? "font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
)}
>
{link.label}
</Link>
</li>
);
})}
</motion.ul>
) : null}
</AnimatePresence>
</li>
);
})}
</ul>
</nav>
</MotionConfig>
);
}States
- Group closed
- An icon, the group name and a small arrow.
- Group open
- Pages unfold under a thin guide line; the arrow turns down.
- Active page
- A darker segment on the guide line glides to the current page, even across groups.
- Active group
- The group holding the current page keeps a stronger title, even when closed.
- Keyboard
- Group titles are buttons with aria-expanded; pages are links with aria-current.
- Reduced motion
- Groups open and the marker moves without animating.
Notes
Pass linkComponent={Link} from your router so moving between pages doesn’t reload.
Two levels is the limit. If you need a third, the information wants a different structure, not a deeper tree.
Dot
A quiet text list where the current page steps aside for a dot. The dot runs between pages, stretching with its speed.
Open this page on a wider screen to see the site’s sidebar change.Try it in the navigation on the left.
Installation
$npx shadcn@latest add @stillui/sidebar-dotOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/sidebar#dot
import { animate, motion, useMotionValue, useReducedMotion, useTransform, useVelocity } from "motion/react";
import { useLayoutEffect, useRef, useState, type ElementType, type MouseEvent, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const DOT = 6;
const TRAVEL = { type: "spring", stiffness: 520, damping: 38, mass: 0.6 } as const;
export type DotLink = { value: string; label: string; href?: string };
export type DotGroup = { value: string; label: string; icon?: ReactNode; links: DotLink[] };
type SidebarDotProps = {
groups: DotGroup[];
/** Shown above the groups: a logo and an action, or a search field. */
header?: ReactNode;
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
/** Renders page links, e.g. Next.js Link, so navigation stays client-side. Defaults to <a>. */
linkComponent?: ElementType;
className?: string;
};
/**
* A quiet text list where the current page steps aside for a dot. Moving to another page,
* the dot runs down the gutter, stretching with its speed, and settles round when it lands.
*/
export function SidebarDot({ groups, header, value, defaultValue, onValueChange, linkComponent: Link = "a", className }: SidebarDotProps) {
const reduce = useReducedMotion();
const [internal, setInternal] = useState(defaultValue ?? groups[0]?.links[0]?.value);
const current = value ?? internal;
const listRef = useRef<HTMLDivElement>(null);
const rows = useRef(new Map<string, HTMLElement>());
const placed = useRef(false);
// The dot stretches along its path the faster it moves, and thins to keep its volume.
const y = useMotionValue(0);
const speed = useVelocity(y);
const scaleY = useTransform(speed, (v) => 1 + Math.min(Math.abs(v) / 900, 2.2));
const scaleX = useTransform(scaleY, (s) => 1 / Math.sqrt(s));
const opacity = useMotionValue(0);
useLayoutEffect(() => {
const list = listRef.current;
if (!list) return;
const targetFor = () => {
const row = current ? rows.current.get(current) : undefined;
if (!row) return null;
return row.getBoundingClientRect().top - list.getBoundingClientRect().top + (row.offsetHeight - DOT) / 2;
};
const target = targetFor();
if (target === null) {
opacity.set(0);
return;
}
opacity.set(1);
// First placement and reduced motion jump; every later change travels.
const controls = placed.current && !reduce ? animate(y, target, TRAVEL) : (y.set(target), undefined);
placed.current = true;
// Groups above can change height (fonts loading, a resize): keep the dot on its row.
const observer = new ResizeObserver(() => {
const next = targetFor();
if (next !== null && !y.isAnimating()) y.set(next);
});
observer.observe(list);
return () => {
controls?.stop();
observer.disconnect();
};
}, [current, reduce, y, opacity]);
const select = (link: DotLink) => (event: MouseEvent) => {
if (!link.href) event.preventDefault();
if (value === undefined) setInternal(link.value);
onValueChange?.(link.value);
};
return (
<nav aria-label="Docs" className={cn("w-56 shrink-0", className)}>
{header ? <div className="pb-4">{header}</div> : null}
<div ref={listRef} className="relative grid gap-4">
<motion.span
aria-hidden
className="pointer-events-none absolute left-1 top-0 rounded-full bg-foreground"
style={{ y, scaleX, scaleY, opacity, width: DOT, height: DOT }}
/>
{groups.map((group) => (
<section key={group.value} aria-label={group.label}>
<p className="flex h-8 items-center gap-2 text-[13px] font-medium text-foreground [&_svg]:size-4 [&_svg]:text-muted-foreground">
{group.icon}
{group.label}
</p>
<ul>
{group.links.map((link) => {
const active = link.value === current;
return (
<li key={link.value}>
<Link
ref={(node: HTMLElement | null) => {
if (node) rows.current.set(link.value, node);
else rows.current.delete(link.value);
}}
href={link.href ?? "#"}
onClick={select(link)}
aria-current={active ? "page" : undefined}
className={cn(
"flex h-[30px] items-center text-sm transition-[color,background-color,box-shadow,scale] active:scale-[0.98] duration-200",
active ? "text-foreground" : "text-muted-foreground hover:text-foreground",
)}
>
{/* The name steps aside to make room for the dot; the old one steps back as it leaves. */}
<span
className={cn(
"transition-[translate] duration-300 ease-[cubic-bezier(0.2,0.8,0.2,1)] motion-reduce:transition-none",
active ? "translate-x-4 delay-75" : "translate-x-0",
)}
>
{link.label}
</span>
</Link>
</li>
);
})}
</ul>
</section>
))}
</div>
</nav>
);
}States
- Resting
- Group titles with a small icon, and plain page names underneath. No surfaces, no lines.
- Current page
- Its name slides right to make room, and a dot sits in the space it left.
- Moving
- The dot runs down or up the gutter and stretches into a droplet the faster it goes, then lands round. The old name slides back as it leaves.
- Across groups
- One dot for the whole list, so it travels past group titles too.
- Header
- An optional slot above the groups, for a logo, an action or a search field.
- Reduced motion
- The dot and the names jump to their places.
Notes
This site’s own sidebar is this component. Pass linkComponent={Link} from your router so moving between pages doesn’t reload.
Best for long lists of pages, like docs, where surfaces on every row would get heavy.
Floating
A compact menu card that floats off the edge, with counts for new items. A soft highlight follows the pointer row to row.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui/sidebar-floatingOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/sidebar#floating
import { AnimatePresence, motion, MotionConfig, useReducedMotion } from "motion/react";
import { useId, useState, type ElementType, type MouseEvent, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const GLIDE = { type: "spring", stiffness: 520, damping: 42 } as const;
export type FloatingItem = { value: string; label: string; icon: ReactNode; href?: string; count?: number };
type SidebarFloatingProps = {
/** Shown at the top: an avatar and a name, for example. */
header: ReactNode;
items: FloatingItem[];
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
/** Renders page links, e.g. Next.js Link, so navigation stays client-side. Defaults to <a>. */
linkComponent?: ElementType;
className?: string;
};
/** A compact menu that floats off the edge. A soft highlight follows the pointer from row to row. */
export function SidebarFloating({ header, items, value, defaultValue, onValueChange, linkComponent: Link = "a", className }: SidebarFloatingProps) {
const reduce = useReducedMotion();
const hoverId = useId();
const [internal, setInternal] = useState(defaultValue ?? items[0]?.value);
const [hovered, setHovered] = useState<string | null>(null);
const current = value ?? internal;
const select = (item: FloatingItem) => (event: MouseEvent) => {
if (!item.href) event.preventDefault();
if (value === undefined) setInternal(item.value);
onValueChange?.(item.value);
};
return (
<MotionConfig transition={reduce ? { duration: 0 } : GLIDE}>
<aside className={cn("m-3 flex w-56 shrink-0 flex-col gap-3 self-start rounded-2xl bg-popover p-2 text-popover-foreground shadow-overlay", className)}>
<div className="px-2 pt-1">{header}</div>
<nav aria-label="Main" onPointerLeave={() => setHovered(null)}>
<ul className="grid gap-0.5">
{items.map((item) => {
const active = item.value === current;
return (
<li key={item.value} className="relative">
<AnimatePresence>
{hovered === item.value && !active ? (
<motion.span
layoutId={hoverId}
aria-hidden
className="absolute inset-0 rounded-lg bg-secondary/70"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0, transition: { duration: 0.12 } }}
/>
) : null}
</AnimatePresence>
<Link
href={item.href ?? "#"}
onClick={select(item)}
onPointerEnter={() => setHovered(item.value)}
onFocus={() => setHovered(item.value)}
aria-current={active ? "page" : undefined}
className={cn(
"relative flex h-9 items-center gap-2.5 rounded-lg px-2.5 text-sm outline-offset-0 transition-[color,background-color,box-shadow,scale] active:scale-[0.98] [&_svg]:size-[18px] [&_svg]:shrink-0",
active ? "bg-secondary font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
)}
>
{item.icon}
<span className="flex-1 truncate">{item.label}</span>
{item.count ? (
<span className="grid h-5 min-w-5 place-items-center rounded-full bg-destructive px-1.5 text-[11px] font-semibold tabular-nums text-white">
{item.count}
<span className="sr-only"> new</span>
</span>
) : null}
</Link>
</li>
);
})}
</ul>
</nav>
</aside>
</MotionConfig>
);
}States
- Active
- The current page sits on a solid surface with stronger text.
- Hover
- A lighter surface glides between rows under the pointer, and fades when it leaves the menu.
- Counts
- A small red count for new items, read as “3 new” by screen readers.
- Keyboard
- Focus moves the same highlight, so keyboard and pointer feel alike.
- Reduced motion
- The highlight jumps between rows.
Notes
Sized by its content, not the window height, so it suits small apps and tools with few destinations.
Two-level
Two levels side by side: an icon rail picks the section and a panel lists its pages. Press the section again to fold the panel.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui-pro/sidebar-panelsA paid component. The command needs the token from your account in STILLUI_TOKEN; your account page shows the one-time setup.
This is a paid component. Its source and install come with access.
States
- Section
- A raised tile marks the chosen section and glides to the next one.
- Panel change
- Pages slide up or down depending on whether the new section is below or above.
- Folded
- Pressing the open section again closes the panel to just the rail.
- Current page
- When browsing another section, a dot under its icon shows where the current page lives.
- Keyboard
- Section buttons report pressed and expanded; pages are links with aria-current.
- Reduced motion
- Panels swap and fold instantly.
Notes
Good for large apps with a few areas that each hold several pages, like work, people and finance.
Stretch line
A text-only list with a line on the left. Moving pages, the line stretches to cover both rows, then lets go of the old one.
Open this page on a wider screen to see the site’s sidebar change.The navigation on the left becomes this component.
Installation
$npx shadcn@latest add @stillui/sidebar-stretchOr copy the source into your project. It needs the shadcn color tokens and the cn helper.
"use client";
// stillui.dev/components/sidebar#stretch
import { motion, useReducedMotion } from "motion/react";
import { useState, type ElementType, type MouseEvent, type ReactNode } from "react";
import { cn } from "@/lib/utils";
const ROW = 36;
const GAP = 2;
export type StretchItem = { value: string; label: string; href?: string };
type SidebarStretchProps = {
title?: ReactNode;
items: StretchItem[];
value?: string;
defaultValue?: string;
onValueChange?: (value: string) => void;
/** Renders page links, e.g. Next.js Link, so navigation stays client-side. Defaults to <a>. */
linkComponent?: ElementType;
className?: string;
};
/**
* A text-only list with a line on the left. Moving to another page, the line first stretches
* to cover both rows, then lets go of the old one, like an inchworm.
*/
export function SidebarStretch({ title, items, value, defaultValue, onValueChange, linkComponent: Link = "a", className }: SidebarStretchProps) {
const reduce = useReducedMotion();
const [internal, setInternal] = useState(defaultValue ?? items[0]?.value);
const current = value ?? internal;
const index = Math.max(0, items.findIndex((i) => i.value === current));
const [from, setFrom] = useState(index);
const top = (i: number) => i * (ROW + GAP) + 8;
const height = ROW - 16;
const select = (item: StretchItem) => (event: MouseEvent) => {
if (!item.href) event.preventDefault();
setFrom(index);
if (value === undefined) setInternal(item.value);
onValueChange?.(item.value);
};
// Stretch from the old row to the new one, then shrink onto the new row.
const span = Math.abs(index - from);
const lead = Math.min(top(from), top(index));
const keyframes = reduce || span === 0
? { top: top(index), height }
: { top: [top(from), lead, top(index)], height: [height, span * (ROW + GAP) + height, height] };
return (
<nav aria-label="Main" className={cn("h-full w-52 shrink-0 bg-muted px-3 py-4", className)}>
{title ? <p className="px-4 pb-4 text-[15px] font-semibold tracking-tight text-foreground">{title}</p> : null}
<div className="relative">
<span aria-hidden className="absolute bottom-0 left-0 top-0 w-px bg-input" />
<motion.span
aria-hidden
className="absolute left-[-0.5px] w-0.5 rounded-full bg-foreground"
initial={false}
animate={keyframes}
transition={{ duration: reduce ? 0 : 0.42, times: [0, 0.45, 1], ease: [0.65, 0, 0.35, 1] }}
/>
<ul className="grid" style={{ gap: GAP }}>
{items.map((item) => {
const active = item.value === current;
return (
<li key={item.value}>
<Link
href={item.href ?? "#"}
onClick={select(item)}
aria-current={active ? "page" : undefined}
className={cn(
"flex items-center px-4 text-sm transition-[color,background-color,box-shadow,scale] active:scale-[0.98] duration-200",
active ? "font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
)}
style={{ height: ROW }}
>
{item.label}
</Link>
</li>
);
})}
</ul>
</div>
</nav>
);
}States
- Resting
- A short dark segment on the guide line beside the current page.
- Moving
- The segment reaches toward the new page until it spans both, then lets go of the old one.
- Long jumps
- The stretch covers every row in between, so the eye follows the distance travelled.
- Keyboard
- Plain links with aria-current; the line is decoration only.
- Reduced motion
- The segment jumps straight to the new page.
Notes
Made for settings pages and docs where labels carry the meaning and icons would be noise.