104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import type { Meta, StoryObj } from "@storybook/react";
|
|
import { useState } from "react";
|
|
import { DemoBadge } from "./_demo-primitives.js";
|
|
|
|
const meta: Meta = {
|
|
title: "UI / Navigation / Sidebar",
|
|
};
|
|
|
|
export default meta;
|
|
|
|
type Story = StoryObj;
|
|
|
|
type NavItem = {
|
|
id: string;
|
|
label: string;
|
|
href: string;
|
|
badge?: { tone: "default" | "warning" | "success"; text: string };
|
|
};
|
|
|
|
const items: ReadonlyArray<NavItem> = [
|
|
{ id: "dashboard", label: "Dashboard", href: "#dashboard" },
|
|
{ id: "projects", label: "Projects", href: "#projects", badge: { tone: "default", text: "12" } },
|
|
{ id: "members", label: "Members", href: "#members" },
|
|
{ id: "billing", label: "Billing", href: "#billing", badge: { tone: "warning", text: "due" } },
|
|
{ id: "settings", label: "Settings", href: "#settings" },
|
|
];
|
|
|
|
function Sidebar({ collapsed }: { collapsed: boolean }) {
|
|
const [active, setActive] = useState("projects");
|
|
return (
|
|
<nav
|
|
aria-label="Primary"
|
|
style={{
|
|
width: collapsed ? 56 : 220,
|
|
background: "var(--color-card)",
|
|
borderRight: "1px solid var(--color-border)",
|
|
padding: collapsed ? "12px 6px" : "16px 12px",
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
gap: 2,
|
|
transition: "width 160ms",
|
|
minHeight: 320,
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
padding: collapsed ? 4 : "4px 8px 12px",
|
|
fontSize: 12,
|
|
letterSpacing: 1,
|
|
textTransform: "uppercase",
|
|
color: "var(--color-muted)",
|
|
}}
|
|
>
|
|
{collapsed ? "T" : "Toolctrl"}
|
|
</div>
|
|
{items.map((item) => (
|
|
<a
|
|
key={item.id}
|
|
href={item.href}
|
|
onClick={(event) => {
|
|
event.preventDefault();
|
|
setActive(item.id);
|
|
}}
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
justifyContent: collapsed ? "center" : "space-between",
|
|
padding: collapsed ? 8 : "8px 10px",
|
|
borderRadius: 6,
|
|
background: active === item.id ? "var(--color-accent)" : "transparent",
|
|
color: active === item.id ? "var(--color-fg)" : "var(--color-muted)",
|
|
textDecoration: "none",
|
|
fontSize: 14,
|
|
fontWeight: active === item.id ? 600 : 500,
|
|
}}
|
|
>
|
|
<span>{collapsed ? item.label.charAt(0) : item.label}</span>
|
|
{!collapsed && item.badge ? (
|
|
<DemoBadge tone={item.badge.tone}>{item.badge.text}</DemoBadge>
|
|
) : null}
|
|
</a>
|
|
))}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
export const Expanded: Story = {
|
|
render: () => <Sidebar collapsed={false} />,
|
|
};
|
|
|
|
export const Collapsed: Story = {
|
|
render: () => <Sidebar collapsed={true} />,
|
|
};
|
|
|
|
export const SideBySide: Story = {
|
|
name: "Side by side",
|
|
render: () => (
|
|
<div style={{ display: "flex", gap: 24 }}>
|
|
<Sidebar collapsed={true} />
|
|
<Sidebar collapsed={false} />
|
|
</div>
|
|
),
|
|
};
|