File tree Expand file tree Collapse file tree 6 files changed +67
-45
lines changed
examples/crm-app/src/components Expand file tree Collapse file tree 6 files changed +67
-45
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import { NavLink , useLocation } from 'react-router-dom' ;
3- import { cn } from '@object-ui/components' ;
42import {
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
2811export const mainNavItems : NavItem [ ] = [
2912 {
@@ -54,30 +37,9 @@ export const mainNavItems: NavItem[] = [
5437] ;
5538
5639export 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+
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -7,10 +7,12 @@ import { ComponentRegistry } from '@object-ui/core';
77import { PageHeader } from './PageHeader' ;
88import { AppShell } from './AppShell' ;
99import { Page } from './Page' ;
10+ import { SidebarNav } from './SidebarNav' ;
1011
1112export * from './PageHeader' ;
1213export * from './AppShell' ;
1314export * from './Page' ;
15+ export * from './SidebarNav' ;
1416
1517export function registerLayout ( ) {
1618 ComponentRegistry . register ( 'page-header' , PageHeader , {
Original file line number Diff line number Diff 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 } ,
You can’t perform that action at this time.
0 commit comments