|
| 1 | +import type { Meta, StoryObj } from '@storybook/react'; |
| 2 | +import React from 'react'; |
| 3 | +import { MemoryRouter } from 'react-router-dom'; |
| 4 | +import { SidebarNav, type NavItem, type NavGroup } from '../SidebarNav'; |
| 5 | +import { SidebarProvider } from '@object-ui/components'; |
| 6 | +import { |
| 7 | + Home, |
| 8 | + Users, |
| 9 | + FolderOpen, |
| 10 | + BarChart, |
| 11 | + Settings, |
| 12 | + HelpCircle, |
| 13 | + Mail, |
| 14 | + Calendar, |
| 15 | + FileText, |
| 16 | + Shield, |
| 17 | +} from 'lucide-react'; |
| 18 | + |
| 19 | +/** |
| 20 | + * SidebarNav stories demonstrating badges, nested items, search, and NavGroups. |
| 21 | + * |
| 22 | + * Part of Console integration: consume new engine schema capabilities |
| 23 | + * (HeaderBar, ViewSwitcher, SidebarNav, Airtable UX). |
| 24 | + */ |
| 25 | +const meta = { |
| 26 | + title: 'Layout/SidebarNav', |
| 27 | + component: SidebarNav, |
| 28 | + decorators: [ |
| 29 | + (Story) => ( |
| 30 | + <MemoryRouter initialEntries={['/dashboard']}> |
| 31 | + <SidebarProvider defaultOpen style={{ height: '600px', border: '1px solid hsl(var(--border))' }}> |
| 32 | + <Story /> |
| 33 | + </SidebarProvider> |
| 34 | + </MemoryRouter> |
| 35 | + ), |
| 36 | + ], |
| 37 | + parameters: { |
| 38 | + layout: 'fullscreen', |
| 39 | + docs: { |
| 40 | + description: { |
| 41 | + component: |
| 42 | + 'Navigation sidebar with React Router integration. Supports badges, nested collapsible items, grouped navigation, and built-in search filtering.', |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + tags: ['autodocs'], |
| 47 | +} satisfies Meta<typeof SidebarNav>; |
| 48 | + |
| 49 | +export default meta; |
| 50 | +type Story = StoryObj<typeof meta>; |
| 51 | + |
| 52 | +// --------------------------------------------------------------------------- |
| 53 | +// Basic flat items |
| 54 | +// --------------------------------------------------------------------------- |
| 55 | +const basicItems: NavItem[] = [ |
| 56 | + { title: 'Dashboard', href: '/dashboard', icon: Home }, |
| 57 | + { title: 'Contacts', href: '/contacts', icon: Users }, |
| 58 | + { title: 'Projects', href: '/projects', icon: FolderOpen }, |
| 59 | + { title: 'Reports', href: '/reports', icon: BarChart }, |
| 60 | + { title: 'Settings', href: '/settings', icon: Settings }, |
| 61 | +]; |
| 62 | + |
| 63 | +export const Default: Story = { |
| 64 | + args: { |
| 65 | + items: basicItems, |
| 66 | + title: 'My App', |
| 67 | + }, |
| 68 | +}; |
| 69 | + |
| 70 | +// --------------------------------------------------------------------------- |
| 71 | +// With Badges |
| 72 | +// --------------------------------------------------------------------------- |
| 73 | +const itemsWithBadges: NavItem[] = [ |
| 74 | + { title: 'Dashboard', href: '/dashboard', icon: Home }, |
| 75 | + { title: 'Inbox', href: '/inbox', icon: Mail, badge: 12, badgeVariant: 'destructive' }, |
| 76 | + { title: 'Contacts', href: '/contacts', icon: Users, badge: 342 }, |
| 77 | + { title: 'Projects', href: '/projects', icon: FolderOpen, badge: '3 new', badgeVariant: 'outline' }, |
| 78 | + { title: 'Calendar', href: '/calendar', icon: Calendar }, |
| 79 | + { title: 'Settings', href: '/settings', icon: Settings }, |
| 80 | +]; |
| 81 | + |
| 82 | +export const WithBadges: Story = { |
| 83 | + args: { |
| 84 | + items: itemsWithBadges, |
| 85 | + title: 'CRM App', |
| 86 | + }, |
| 87 | +}; |
| 88 | + |
| 89 | +// --------------------------------------------------------------------------- |
| 90 | +// Nested Items (collapsible children) |
| 91 | +// --------------------------------------------------------------------------- |
| 92 | +const nestedItems: NavItem[] = [ |
| 93 | + { title: 'Dashboard', href: '/dashboard', icon: Home }, |
| 94 | + { |
| 95 | + title: 'Projects', |
| 96 | + href: '/projects', |
| 97 | + icon: FolderOpen, |
| 98 | + badge: 5, |
| 99 | + children: [ |
| 100 | + { title: 'Active', href: '/projects/active' }, |
| 101 | + { title: 'Archived', href: '/projects/archived' }, |
| 102 | + { title: 'Templates', href: '/projects/templates', badge: 2 }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + { |
| 106 | + title: 'Reports', |
| 107 | + href: '/reports', |
| 108 | + icon: BarChart, |
| 109 | + children: [ |
| 110 | + { title: 'Sales', href: '/reports/sales' }, |
| 111 | + { title: 'Marketing', href: '/reports/marketing', badge: 'New', badgeVariant: 'outline' }, |
| 112 | + { title: 'Finance', href: '/reports/finance' }, |
| 113 | + ], |
| 114 | + }, |
| 115 | + { title: 'Settings', href: '/settings', icon: Settings }, |
| 116 | +]; |
| 117 | + |
| 118 | +export const NestedItems: Story = { |
| 119 | + args: { |
| 120 | + items: nestedItems, |
| 121 | + title: 'Enterprise App', |
| 122 | + }, |
| 123 | +}; |
| 124 | + |
| 125 | +// --------------------------------------------------------------------------- |
| 126 | +// NavGroup — grouped navigation |
| 127 | +// --------------------------------------------------------------------------- |
| 128 | +const groupedItems: NavGroup[] = [ |
| 129 | + { |
| 130 | + label: 'Main', |
| 131 | + items: [ |
| 132 | + { title: 'Dashboard', href: '/dashboard', icon: Home }, |
| 133 | + { title: 'Inbox', href: '/inbox', icon: Mail, badge: 5, badgeVariant: 'destructive' }, |
| 134 | + ], |
| 135 | + }, |
| 136 | + { |
| 137 | + label: 'Content', |
| 138 | + items: [ |
| 139 | + { title: 'Documents', href: '/documents', icon: FileText, badge: 23 }, |
| 140 | + { title: 'Projects', href: '/projects', icon: FolderOpen }, |
| 141 | + { title: 'Calendar', href: '/calendar', icon: Calendar }, |
| 142 | + ], |
| 143 | + }, |
| 144 | + { |
| 145 | + label: 'Admin', |
| 146 | + items: [ |
| 147 | + { title: 'Users', href: '/admin/users', icon: Users }, |
| 148 | + { title: 'Permissions', href: '/admin/permissions', icon: Shield }, |
| 149 | + { title: 'Settings', href: '/settings', icon: Settings }, |
| 150 | + ], |
| 151 | + }, |
| 152 | +]; |
| 153 | + |
| 154 | +export const GroupedNavigation: Story = { |
| 155 | + args: { |
| 156 | + items: groupedItems, |
| 157 | + }, |
| 158 | +}; |
| 159 | + |
| 160 | +// --------------------------------------------------------------------------- |
| 161 | +// Search Enabled |
| 162 | +// --------------------------------------------------------------------------- |
| 163 | +export const WithSearch: Story = { |
| 164 | + args: { |
| 165 | + items: groupedItems, |
| 166 | + searchEnabled: true, |
| 167 | + searchPlaceholder: 'Filter navigation...', |
| 168 | + }, |
| 169 | +}; |
| 170 | + |
| 171 | +// --------------------------------------------------------------------------- |
| 172 | +// Full featured: badges + nested + groups + search |
| 173 | +// --------------------------------------------------------------------------- |
| 174 | +const fullFeaturedGroups: NavGroup[] = [ |
| 175 | + { |
| 176 | + label: 'Workspace', |
| 177 | + items: [ |
| 178 | + { title: 'Dashboard', href: '/dashboard', icon: Home }, |
| 179 | + { title: 'Inbox', href: '/inbox', icon: Mail, badge: 8, badgeVariant: 'destructive' }, |
| 180 | + { |
| 181 | + title: 'Projects', |
| 182 | + href: '/projects', |
| 183 | + icon: FolderOpen, |
| 184 | + badge: 3, |
| 185 | + children: [ |
| 186 | + { title: 'Design System', href: '/projects/design' }, |
| 187 | + { title: 'API v2', href: '/projects/api', badge: 'WIP', badgeVariant: 'outline' }, |
| 188 | + { title: 'Mobile App', href: '/projects/mobile' }, |
| 189 | + ], |
| 190 | + }, |
| 191 | + ], |
| 192 | + }, |
| 193 | + { |
| 194 | + label: 'Analytics', |
| 195 | + items: [ |
| 196 | + { |
| 197 | + title: 'Reports', |
| 198 | + href: '/reports', |
| 199 | + icon: BarChart, |
| 200 | + children: [ |
| 201 | + { title: 'Revenue', href: '/reports/revenue' }, |
| 202 | + { title: 'Users', href: '/reports/users', badge: 'New', badgeVariant: 'outline' }, |
| 203 | + ], |
| 204 | + }, |
| 205 | + { title: 'Calendar', href: '/calendar', icon: Calendar }, |
| 206 | + ], |
| 207 | + }, |
| 208 | + { |
| 209 | + label: 'System', |
| 210 | + items: [ |
| 211 | + { title: 'Settings', href: '/settings', icon: Settings }, |
| 212 | + { title: 'Help', href: '/help', icon: HelpCircle }, |
| 213 | + ], |
| 214 | + }, |
| 215 | +]; |
| 216 | + |
| 217 | +export const FullFeatured: Story = { |
| 218 | + args: { |
| 219 | + items: fullFeaturedGroups, |
| 220 | + searchEnabled: true, |
| 221 | + searchPlaceholder: 'Search navigation...', |
| 222 | + }, |
| 223 | +}; |
0 commit comments