Skip to content

Commit 22be35c

Browse files
committed
feat: implement SidebarNav component with routing support and integrate into layout; update package dependencies
1 parent d1fa379 commit 22be35c

File tree

6 files changed

+67
-45
lines changed

6 files changed

+67
-45
lines changed
Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
import React from 'react';
2-
import { NavLink, useLocation } from 'react-router-dom';
3-
import { cn } from '@object-ui/components';
42
import {
53
LayoutDashboard,
64
Users,
75
Settings,
86
Package,
97
FileText
108
} from 'lucide-react';
11-
import {
12-
Sidebar,
13-
SidebarContent,
14-
SidebarGroup,
15-
SidebarGroupLabel,
16-
SidebarGroupContent,
17-
SidebarMenu,
18-
SidebarMenuItem,
19-
SidebarMenuButton,
20-
} from '@object-ui/components';
21-
22-
export interface NavItem {
23-
title: string;
24-
href: string;
25-
icon?: React.ComponentType<{ className?: string }>;
26-
}
9+
import { SidebarNav as SidebarNavLayout, NavItem } from '@object-ui/layout';
2710

2811
export const mainNavItems: NavItem[] = [
2912
{
@@ -54,30 +37,9 @@ export const mainNavItems: NavItem[] = [
5437
];
5538

5639
export function SidebarNav({ items = mainNavItems }: { items?: NavItem[] }) {
57-
const location = useLocation();
58-
5940
return (
60-
<Sidebar>
61-
<SidebarContent>
62-
<SidebarGroup>
63-
<SidebarGroupLabel>Application</SidebarGroupLabel>
64-
<SidebarGroupContent>
65-
<SidebarMenu>
66-
{items.map((item) => (
67-
<SidebarMenuItem key={item.href}>
68-
<SidebarMenuButton asChild isActive={location.pathname === item.href}>
69-
<NavLink to={item.href}>
70-
{item.icon && <item.icon />}
71-
<span>{item.title}</span>
72-
</NavLink>
73-
</SidebarMenuButton>
74-
</SidebarMenuItem>
75-
))}
76-
</SidebarMenu>
77-
</SidebarGroupContent>
78-
</SidebarGroup>
79-
</SidebarContent>
80-
</Sidebar>
41+
<SidebarNavLayout items={items} />
8142
);
8243
}
8344

45+

packages/layout/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
},
2929
"peerDependencies": {
3030
"react": "^18.0.0 || ^19.0.0",
31-
"react-dom": "^18.0.0 || ^19.0.0"
31+
"react-dom": "^18.0.0 || ^19.0.0",
32+
"react-router-dom": "^6.0.0 || ^7.0.0"
3233
},
3334
"devDependencies": {
35+
"react-router-dom": "^7.13.0",
3436
"@vitejs/plugin-react": "^4.2.1",
3537
"vite": "^7.3.1",
3638
"vite-plugin-dts": "^4.5.4"

packages/layout/src/SidebarNav.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import { NavLink, useLocation } from 'react-router-dom';
3+
import {
4+
Sidebar,
5+
SidebarContent,
6+
SidebarGroup,
7+
SidebarGroupLabel,
8+
SidebarGroupContent,
9+
SidebarMenu,
10+
SidebarMenuItem,
11+
SidebarMenuButton,
12+
} from '@object-ui/components';
13+
14+
export interface NavItem {
15+
title: string;
16+
href: string;
17+
icon?: React.ComponentType<{ className?: string }>;
18+
}
19+
20+
export interface SidebarNavProps {
21+
items: NavItem[];
22+
title?: string;
23+
className?: string;
24+
}
25+
26+
export function SidebarNav({ items, title = "Application", className }: SidebarNavProps) {
27+
const location = useLocation();
28+
29+
return (
30+
<Sidebar className={className}>
31+
<SidebarContent>
32+
<SidebarGroup>
33+
<SidebarGroupLabel>{title}</SidebarGroupLabel>
34+
<SidebarGroupContent>
35+
<SidebarMenu>
36+
{items.map((item) => (
37+
<SidebarMenuItem key={item.href}>
38+
<SidebarMenuButton asChild isActive={location.pathname === item.href}>
39+
<NavLink to={item.href}>
40+
{item.icon && <item.icon />}
41+
<span>{item.title}</span>
42+
</NavLink>
43+
</SidebarMenuButton>
44+
</SidebarMenuItem>
45+
))}
46+
</SidebarMenu>
47+
</SidebarGroupContent>
48+
</SidebarGroup>
49+
</SidebarContent>
50+
</Sidebar>
51+
);
52+
}

packages/layout/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { ComponentRegistry } from '@object-ui/core';
77
import { PageHeader } from './PageHeader';
88
import { AppShell } from './AppShell';
99
import { Page } from './Page';
10+
import { SidebarNav } from './SidebarNav';
1011

1112
export * from './PageHeader';
1213
export * from './AppShell';
1314
export * from './Page';
15+
export * from './SidebarNav';
1416

1517
export function registerLayout() {
1618
ComponentRegistry.register('page-header', PageHeader, {

packages/layout/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default defineConfig({
2626
'@object-ui/types',
2727
'clsx',
2828
'tailwind-merge',
29-
'lucide-react'
29+
'lucide-react',
30+
'react-router-dom'
3031
],
3132
},
3233
},

pnpm-lock.yaml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)