|
1 | | -import { |
2 | | - Sidebar, |
3 | | - SidebarContent, |
4 | | - SidebarFooter, |
5 | | - SidebarGroup, |
6 | | - SidebarGroupContent, |
7 | | - SidebarGroupLabel, |
8 | | - SidebarMenu, |
9 | | - SidebarMenuButton, |
10 | | - SidebarMenuItem, |
11 | | - SidebarMenuSubItem, |
12 | | - SidebarRail, |
13 | | - SidebarSeparator, |
14 | | - SidebarTrigger, |
15 | | - useSidebar, |
16 | | -} from "@/components/ui/sidebar"; |
| 1 | +"use client"; |
| 2 | + |
17 | 3 | import { cn } from "../../lib/utils"; |
18 | | -import { AppFooter } from "../footers/app-footer"; |
19 | | -import { NavLink } from "../ui/NavLink"; |
20 | | -import { Separator } from "../ui/separator"; |
21 | | -import { MobileSidebar, useActiveSidebarLink } from "./MobileSidebar"; |
| 4 | +import { MobileSidebar } from "./MobileSidebar"; |
22 | 5 | import { CustomSidebar, type SidebarLink } from "./Sidebar"; |
23 | 6 |
|
24 | 7 | export function SidebarLayout(props: { |
@@ -51,129 +34,3 @@ export function SidebarLayout(props: { |
51 | 34 | </div> |
52 | 35 | ); |
53 | 36 | } |
54 | | - |
55 | | -export function FullWidthSidebarLayout(props: { |
56 | | - contentSidebarLinks: SidebarLink[]; |
57 | | - footerSidebarLinks?: SidebarLink[]; |
58 | | - children: React.ReactNode; |
59 | | - className?: string; |
60 | | -}) { |
61 | | - const { contentSidebarLinks, children, footerSidebarLinks } = props; |
62 | | - return ( |
63 | | - <div |
64 | | - className={cn( |
65 | | - "relative flex w-full flex-1 overflow-y-hidden", |
66 | | - props.className, |
67 | | - )} |
68 | | - > |
69 | | - {/* left - sidebar */} |
70 | | - <Sidebar className="pt-2" collapsible="icon" side="left"> |
71 | | - <SidebarContent className="p-2"> |
72 | | - <RenderSidebarMenu links={contentSidebarLinks} /> |
73 | | - </SidebarContent> |
74 | | - |
75 | | - {footerSidebarLinks && ( |
76 | | - <SidebarFooter className="pb-3"> |
77 | | - <RenderSidebarMenu links={footerSidebarLinks} /> |
78 | | - </SidebarFooter> |
79 | | - )} |
80 | | - |
81 | | - <SidebarRail /> |
82 | | - </Sidebar> |
83 | | - |
84 | | - {/* right - content */} |
85 | | - <div className="flex h-full flex-grow flex-col overflow-y-auto"> |
86 | | - <MobileSidebarTrigger |
87 | | - links={[...contentSidebarLinks, ...(footerSidebarLinks || [])]} |
88 | | - /> |
89 | | - |
90 | | - <main className="flex min-w-0 grow flex-col max-sm:w-full"> |
91 | | - {children} |
92 | | - </main> |
93 | | - <AppFooter containerClassName="max-w-7xl" /> |
94 | | - </div> |
95 | | - </div> |
96 | | - ); |
97 | | -} |
98 | | - |
99 | | -function RenderSidebarGroup(props: { |
100 | | - sidebarLinks: SidebarLink[]; |
101 | | - groupName: string; |
102 | | -}) { |
103 | | - return ( |
104 | | - <SidebarGroup className="p-0"> |
105 | | - <SidebarMenuItem> |
106 | | - <SidebarGroupLabel> {props.groupName}</SidebarGroupLabel> |
107 | | - <SidebarGroupContent> |
108 | | - <RenderSidebarMenu links={props.sidebarLinks} /> |
109 | | - </SidebarGroupContent> |
110 | | - </SidebarMenuItem> |
111 | | - </SidebarGroup> |
112 | | - ); |
113 | | -} |
114 | | - |
115 | | -function RenderSidebarMenu(props: { links: SidebarLink[] }) { |
116 | | - const sidebar = useSidebar(); |
117 | | - return ( |
118 | | - <SidebarMenu className="gap-1.5"> |
119 | | - {props.links.map((link, idx) => { |
120 | | - // link |
121 | | - if ("href" in link) { |
122 | | - return ( |
123 | | - <SidebarMenuSubItem key={link.href}> |
124 | | - <SidebarMenuButton asChild> |
125 | | - <NavLink |
126 | | - activeClassName="text-foreground bg-accent" |
127 | | - className="flex items-center gap-2 text-muted-foreground text-sm hover:bg-accent" |
128 | | - exactMatch={link.exactMatch} |
129 | | - href={link.href} |
130 | | - isActive={link.isActive} |
131 | | - onClick={() => { |
132 | | - sidebar.setOpenMobile(false); |
133 | | - }} |
134 | | - > |
135 | | - {link.icon && <link.icon className="size-4" />} |
136 | | - <span>{link.label}</span> |
137 | | - </NavLink> |
138 | | - </SidebarMenuButton> |
139 | | - </SidebarMenuSubItem> |
140 | | - ); |
141 | | - } |
142 | | - |
143 | | - // separator |
144 | | - if ("separator" in link) { |
145 | | - return ( |
146 | | - <SidebarSeparator |
147 | | - className="my-1" |
148 | | - key={`separator-${ |
149 | | - // biome-ignore lint/suspicious/noArrayIndexKey: index is fine here |
150 | | - idx |
151 | | - }`} |
152 | | - /> |
153 | | - ); |
154 | | - } |
155 | | - |
156 | | - // group |
157 | | - return ( |
158 | | - <RenderSidebarGroup |
159 | | - groupName={link.group} |
160 | | - key={link.group} |
161 | | - sidebarLinks={link.links} |
162 | | - /> |
163 | | - ); |
164 | | - })} |
165 | | - </SidebarMenu> |
166 | | - ); |
167 | | -} |
168 | | - |
169 | | -function MobileSidebarTrigger(props: { links: SidebarLink[] }) { |
170 | | - const activeLink = useActiveSidebarLink(props.links); |
171 | | - |
172 | | - return ( |
173 | | - <div className="flex items-center gap-3 border-b px-4 py-4 lg:hidden"> |
174 | | - <SidebarTrigger className="size-4" /> |
175 | | - <Separator className="h-4" orientation="vertical" /> |
176 | | - {activeLink && <span className="text-sm">{activeLink.label}</span>} |
177 | | - </div> |
178 | | - ); |
179 | | -} |
0 commit comments