Skip to content

Commit 0f363e8

Browse files
authored
feat: revamps and refactors the sidebar (#1)
* fix: lag in sidebar collapse * updated sidebar and added more menu * first steps for settings
1 parent 1df2ccd commit 0f363e8

File tree

17 files changed

+88
-154
lines changed

17 files changed

+88
-154
lines changed

resources/js/components/layout/page-layout.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { usePage } from '@inertiajs/react'
1+
import { Head, usePage } from '@inertiajs/react'
22
import { type PropsWithChildren } from 'react'
33

44
import { type SharedProps, type BreadcrumbItem as BreadcrumbItemType } from '@/types'
5-
6-
import { AppContent } from '../common/app-content'
7-
import { AppSidebar } from '../navigation/app-sidebar'
8-
import { AppSidebarHeader } from '../navigation/app-sidebar-header'
95
import { SidebarProvider } from '../ui/sidebar'
6+
import { AppSidebar } from '../sidebar/app-sidebar'
7+
import { AppSidebarHeader } from '../sidebar/app-sidebar-header'
8+
import { AppContent } from '../common/app-content'
109

1110
export const PageLayout = ({
1211
children,
12+
pageTitle,
1313
breadcrumbs = [],
14-
}: PropsWithChildren & { breadcrumbs?: BreadcrumbItemType[] }) => {
14+
}: PropsWithChildren & { pageTitle: string; breadcrumbs?: BreadcrumbItemType[] }) => {
1515
const isOpen = usePage<SharedProps>().props.sidebarOpen
1616

1717
return (
1818
<SidebarProvider defaultOpen={isOpen}>
1919
<AppSidebar />
20-
<AppContent variant="sidebar" className="overflow-x-hidden">
20+
<Head title={pageTitle} />
21+
<AppContent variant="sidebar">
2122
<AppSidebarHeader breadcrumbs={breadcrumbs} />
2223
{children}
2324
</AppContent>

resources/js/components/navigation/nav-projects.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

resources/js/components/navigation/app-sidebar.tsx renamed to resources/js/components/sidebar/app-sidebar.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,82 @@
1-
import { BookOpenIcon, GithubIcon, Settings2Icon, SquareTerminal } from 'lucide-react'
21
import * as React from 'react'
2+
import {
3+
BookOpenIcon,
4+
GithubIcon,
5+
LifeBuoy,
6+
SendIcon,
7+
Settings2Icon,
8+
SquareTerminal,
9+
} from 'lucide-react'
310

411
import {
512
Sidebar,
613
SidebarContent,
714
SidebarFooter,
815
SidebarHeader,
9-
SidebarMenu,
10-
SidebarMenuButton,
11-
SidebarMenuItem,
1216
SidebarRail,
1317
} from '@/components/ui/sidebar'
14-
import { type NavItem } from '@/types'
15-
import { Link } from '@inertiajs/react'
16-
import { AppLogo } from '../common/app-logo'
18+
import { TeamSwitcher } from './team-switcher'
1719
import { NavMain } from './nav-main'
1820
import { NavSecondary } from './nav-secondary'
1921
import { NavUser } from './nav-user'
22+
import { type NavItem } from '@/types'
2023

2124
// This is sample data.
2225
const mainNavItems: NavItem[] = [
2326
{
2427
title: 'Dashboard',
2528
href: '/dashboard', // needs to match path.url for it to be active based on the page you are on
2629
icon: SquareTerminal,
30+
type: 'internal',
2731
},
2832
{
2933
title: 'Settings',
3034
href: '/settings',
3135
icon: Settings2Icon,
36+
type: 'internal',
3237
},
33-
]
34-
35-
const secondaryNavItems: NavItem[] = [
3638
{
3739
title: 'Documentation',
3840
href: 'https://wsameer.github.io/adonisjs-react-starter-kit/intro.html',
3941
icon: BookOpenIcon,
42+
type: 'external',
4043
},
4144
{
4245
title: 'Repository',
43-
href: 'https://wsameer.github.io/adonisjs-react-starter-kit/',
46+
href: 'https://github.com/wsameer/adonisjs-react-starter-kit',
4447
icon: GithubIcon,
48+
type: 'external',
49+
},
50+
]
51+
52+
const secondaryNavItems: NavItem[] = [
53+
{
54+
title: 'Support',
55+
href: 'https://github.com/wsameer/adonisjs-react-starter-kit/issues/new',
56+
icon: LifeBuoy,
57+
type: 'external',
58+
},
59+
{
60+
title: 'Feedback',
61+
href: 'mailto:someone@example.com',
62+
icon: SendIcon,
63+
type: 'external',
4564
},
4665
]
4766

4867
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
4968
return (
50-
<Sidebar collapsible="icon" variant="inset" {...props}>
69+
<Sidebar collapsible="icon" {...props}>
5170
<SidebarHeader>
52-
<SidebarMenu>
53-
<SidebarMenuItem>
54-
<SidebarMenuButton
55-
size="lg"
56-
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
57-
asChild
58-
>
59-
<Link href="/dashboard" prefetch>
60-
<div className="flex size-8 items-center justify-center text-sidebar-primary-foreground">
61-
<AppLogo size="small" />
62-
</div>
63-
<div className="grid flex-1 text-left text-sm leading-tight">
64-
<span className="truncate font-medium">App name</span>
65-
<span className="truncate text-xs">Enterprise</span>
66-
</div>
67-
</Link>
68-
</SidebarMenuButton>
69-
</SidebarMenuItem>
70-
</SidebarMenu>
71+
<TeamSwitcher />
7172
</SidebarHeader>
72-
7373
<SidebarContent>
7474
<NavMain items={mainNavItems} />
7575
<NavSecondary items={secondaryNavItems} className="mt-auto" />
7676
</SidebarContent>
77-
7877
<SidebarFooter>
7978
<NavUser />
8079
</SidebarFooter>
81-
8280
<SidebarRail />
8381
</Sidebar>
8482
)

resources/js/components/navigation/nav-main.tsx renamed to resources/js/components/sidebar/nav-main.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import {
77
} from '@/components/ui/sidebar'
88
import { type SharedProps, type NavItem } from '@/types'
99
import { Link, usePage } from '@inertiajs/react'
10+
import { Icon } from '../common/icon'
1011

11-
export function NavMain({ items = [] }: { items: NavItem[] }) {
12+
export function NavMain({ items }: { items: NavItem[] }) {
1213
const page = usePage<SharedProps>()
1314
return (
14-
<SidebarGroup className="px-2 py-0">
15+
<SidebarGroup>
1516
<SidebarGroupLabel>Platform</SidebarGroupLabel>
1617
<SidebarMenu>
1718
{items.map((item) => (
@@ -21,10 +22,17 @@ export function NavMain({ items = [] }: { items: NavItem[] }) {
2122
isActive={page.url.startsWith(item.href)}
2223
tooltip={{ children: item.title }}
2324
>
24-
<Link href={item.href} prefetch>
25-
{item.icon && <item.icon />}
26-
<span>{item.title}</span>
27-
</Link>
25+
{item.type === 'internal' ? (
26+
<Link href={item.href} prefetch>
27+
{item.icon && <Icon iconNode={item.icon} className="h-5 w-5" />}
28+
<span>{item.title}</span>
29+
</Link>
30+
) : (
31+
<a href={item.href} target="_blank" rel="noopener noreferrer">
32+
{item.icon && <Icon iconNode={item.icon} className="h-5 w-5" />}
33+
<span>{item.title}</span>
34+
</a>
35+
)}
2836
</SidebarMenuButton>
2937
</SidebarMenuItem>
3038
))}

resources/js/components/navigation/nav-secondary.tsx renamed to resources/js/components/sidebar/nav-secondary.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as React from 'react'
2-
31
import {
42
SidebarGroup,
53
SidebarGroupContent,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { GalleryVerticalEnd } from 'lucide-react'
2+
3+
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/components/ui/sidebar'
4+
import { Link } from '@inertiajs/react'
5+
6+
export function TeamSwitcher() {
7+
return (
8+
<SidebarMenu>
9+
<SidebarMenuItem>
10+
<SidebarMenuButton
11+
size="lg"
12+
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
13+
asChild
14+
>
15+
<Link href="/dashboard" prefetch>
16+
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
17+
<GalleryVerticalEnd className="size-4" />
18+
</div>
19+
<div className="grid flex-1 text-left text-sm leading-tight">
20+
<span className="truncate font-medium">App Name</span>
21+
<span className="truncate text-xs">Enterprise</span>
22+
</div>
23+
</Link>
24+
</SidebarMenuButton>
25+
</SidebarMenuItem>
26+
</SidebarMenu>
27+
)
28+
}

resources/js/components/ui/dialog.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client'
2-
31
import * as React from 'react'
42
import * as DialogPrimitive from '@radix-ui/react-dialog'
53
import { XIcon } from 'lucide-react'

resources/js/components/ui/label.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client'
2-
31
import * as React from 'react'
42
import * as LabelPrimitive from '@radix-ui/react-label'
53

0 commit comments

Comments
 (0)