Skip to content

Commit 69f5a71

Browse files
authored
feat: add extra AppTitle component for sidebar header (#216)
1 parent cc3a247 commit 69f5a71

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/components/layout/app-sidebar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SidebarHeader,
77
SidebarRail,
88
} from '@/components/ui/sidebar'
9+
// import { AppTitle } from './app-title'
910
import { sidebarData } from './data/sidebar-data'
1011
import { NavGroup } from './nav-group'
1112
import { NavUser } from './nav-user'
@@ -17,6 +18,10 @@ export function AppSidebar() {
1718
<Sidebar collapsible={collapsible} variant={variant}>
1819
<SidebarHeader>
1920
<TeamSwitcher teams={sidebarData.teams} />
21+
22+
{/* Replace <TeamSwitch /> with the following <AppTitle />
23+
/* if you want to use the normal app title instead of TeamSwitch dropdown */}
24+
{/* <AppTitle /> */}
2025
</SidebarHeader>
2126
<SidebarContent>
2227
{sidebarData.navGroups.map((props) => (
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Link } from '@tanstack/react-router'
2+
import { Menu, X } from 'lucide-react'
3+
import { cn } from '@/lib/utils'
4+
import {
5+
SidebarMenu,
6+
SidebarMenuButton,
7+
SidebarMenuItem,
8+
useSidebar,
9+
} from '@/components/ui/sidebar'
10+
import { Button } from '../ui/button'
11+
12+
export function AppTitle() {
13+
const { setOpenMobile } = useSidebar()
14+
return (
15+
<SidebarMenu>
16+
<SidebarMenuItem>
17+
<SidebarMenuButton
18+
size='lg'
19+
className='gap-0 py-0 hover:bg-transparent active:bg-transparent'
20+
asChild
21+
>
22+
<div>
23+
<Link
24+
to='/'
25+
onClick={() => setOpenMobile(false)}
26+
className='grid flex-1 text-start text-sm leading-tight'
27+
>
28+
<span className='truncate font-bold'>Shadcn-Admin</span>
29+
<span className='truncate text-xs'>Vite + ShadcnUI</span>
30+
</Link>
31+
<ToggleSidebar />
32+
</div>
33+
</SidebarMenuButton>
34+
</SidebarMenuItem>
35+
</SidebarMenu>
36+
)
37+
}
38+
39+
function ToggleSidebar({
40+
className,
41+
onClick,
42+
...props
43+
}: React.ComponentProps<typeof Button>) {
44+
const { toggleSidebar } = useSidebar()
45+
46+
return (
47+
<Button
48+
data-sidebar='trigger'
49+
data-slot='sidebar-trigger'
50+
variant='ghost'
51+
size='icon'
52+
className={cn('aspect-square size-8 max-md:scale-125', className)}
53+
onClick={(event) => {
54+
onClick?.(event)
55+
toggleSidebar()
56+
}}
57+
{...props}
58+
>
59+
<X className='md:hidden' />
60+
<Menu className='max-md:hidden' />
61+
<span className='sr-only'>Toggle Sidebar</span>
62+
</Button>
63+
)
64+
}

0 commit comments

Comments
 (0)