deno.land / x / netzo@0.5.16 / components / blocks / nav.tsx

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import { signal } from "@preact/signals";import type { ComponentChildren, JSX } from "preact";import type { NetzoState } from "../../mod.ts";import { Avatar, AvatarFallback, AvatarImage } from "../avatar.tsx";import { buttonVariants } from "../button.tsx";import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger,} from "../dropdown-menu.tsx";import { Separator } from "../separator.tsx";import { Sheet, SheetContent, SheetTrigger } from "../sheet.tsx";import { Switch } from "../switch.tsx";import { useDarkMode } from "../use-dark-mode.ts";import { cn } from "../utils.ts";
export const open = signal<boolean>(false);
type NavRootProps = JSX.IntrinsicElements["nav"] & { state?: NetzoState; children?: ComponentChildren;};
export function NavRoot({ className, ...props }: NavRootProps) { const { denoJson } = props.state ?? {}; const darkMode = useDarkMode();
const logoSrc = darkMode.value ? `https://netzo.io/logos/built-with-netzo-dark.svg` : `https://netzo.io/logos/built-with-netzo-light.svg`;
const NavFooter = () => ( <footer className="w-full flex items-center justify-between p-3 b-t-1"> <a href="https://netzo.io/" target="_blank" className="mx-auto"> <img src={logoSrc} alt="Built with Netzo" className="h-[32px]" /> </a> </footer> );
const NavProjectVersion = () => { if (!denoJson) return null; // NOTE: uses style instead of className+unocss to avoid style flashing return ( <> <NavSeparator /> <div title={denoJson.description} style={{ textAlign: "center", fontSize: "10px", color: "hsl(var(--muted-foreground))", }} > {denoJson.name}@{denoJson.version} </div> </> ); };
return ( <> {/* MOBILE */} <Sheet className={cn("!md:hidden", open.value ? "w-[250px]" : "w-[28px]")} open={open.value} onOpenChange={(e) => open.value = e} > <SheetTrigger asChild> <div variant="outline" size="icon" className={cn( "h-full w-[28px]", "fixed top-0 left-0 z-1000", "hover:bg-background hover:bg-opacity-80 hover:cursor-pointer", "flex items-center justify-center", open.value ? "!hidden" : "!md:hidden", )} onClick={() => open.value = !open.value} > <i className="mdi-menu-open rotate-180 h-[1.2rem] w-[1.2rem]" /> <span className="sr-only">Toggle navigation</span> </div> </SheetTrigger> <SheetContent side="left" className="w-[250px] p-0"> <nav f-client-nav className={cn( "h-screen overflow-y-auto group flex flex-col bg-primary-foreground", className, )} > {props.children} <NavFooter /> <NavProjectVersion /> </nav> </SheetContent> </Sheet>
{/* DESKTOP */} <nav f-client-nav className={cn( "!hidden !md:flex md:b-r-1", "h-screen overflow-y-auto group flex flex-col bg-primary-foreground", className, )} > {props.children} <NavFooter /> <NavProjectVersion /> </nav> </> );}
type NavHeaderProps = JSX.IntrinsicElements["header"] & { /** A short title for the app at the navigation drawer. */ title?: string; /** An https or data URL of a cover image at the navigation drawer */ image?: string;};
export function NavHeader({ className, ...props }: NavHeaderProps) { return ( <header className={cn("flex items-center py-3 px-2", className)}> {props?.image && ( <img src={props?.image} className="w-auto h-9 my-auto mr-2" /> )} {props?.title && <h2 className="text-xl font-bold">{props?.title}</h2>} </header> );}
export function NavSeparator(props: JSX.IntrinsicElements["div"]) { return <Separator {...props} />;}
export function NavSpacer( { className, ...props }: JSX.IntrinsicElements["div"],) { return <div {...props} className={cn("flex-1", className)} />;}
type NavItemHeaderProps = JSX.IntrinsicElements["h3"] & { /** A short title for the app at the navigation drawer. */ text: string;};
export function NavItemHeader({ className, ...props }: NavItemHeaderProps) { return ( <h3 className={cn( "mt-3 mb-1 mx-4 text-xs font-medium text-muted-foreground", className, )} > {props.text} </h3> );}
type NavItemProps = JSX.IntrinsicElements["a"] & { /** An https or data URL of an icon to be shown at the navigation item. */ icon?: string; /** A short title for the app at the navigation drawer. */ text: string; /** An absolute or relative URL of the page to navigate to. */ href?: string; /** An optional target to open the link in. */ target?: string; /** Whether link active state should be exact or not (useful to disable ancestor link styles). */ exact?: boolean;};
export function NavItem({ className, ...props }: NavItemProps) { return ( <div> <a className={cn( buttonVariants({ variant: "ghost", className: "rounded-none" }), "flex w-full justify-start h-[40px]", "hover:cursor-pointer hover:bg-muted", // hover props.exact ? "" : `aria-[current='true']:bg-border`, // ancestor links `aria-[current='page']:bg-border`, // current page className, )} href={props.href} target={props.target} > {props.icon && (props.icon.startsWith("http") ? <img {...props} src={props.icon} className="w-4 h-4 mr-3" /> : <div {...props} className={cn("w-4 h-4 mr-3", props.icon)} />)} {props.text} </a> </div> );}
export function NavItemUser(props: { state: NetzoState }) { const { auth } = props.state ?? {};
const darkMode = useDarkMode();
const { name, authId, email } = auth?.sessionUser ?? {}; const initials = name || authId || email || "?"; const initial = initials?.[0]?.toUpperCase();
return ( <DropdownMenu> <DropdownMenuTrigger asChild> <div className={cn( buttonVariants({ variant: "ghost", className: "rounded-none" }), "flex w-full items-center justify-start h-[56px] pl-2 pr-3", "hover:cursor-pointer hover:bg-muted", // hover )} > {auth?.sessionUser ? ( <> <Avatar className="h-9 w-9 mr-2"> <AvatarImage src={auth?.sessionUser?.avatar} alt={`@${auth?.sessionUser?.authId}}`} /> <AvatarFallback>{initial}</AvatarFallback> </Avatar> <div className="flex flex-col space-y-1"> <p className="text-sm font-medium leading-none"> {auth?.sessionUser?.name} </p> {auth?.sessionUser?.email && ( <p className="text-xs leading-none text-muted-foreground"> {auth?.sessionUser?.email} </p> )} </div> </> ) : ( <> <i className="mdi-account-circle h-7 w-7 ml-0.5 mr-1.5" /> <div className="flex flex-col space-y-1"> <p className="text-sm font-medium leading-none"> User Settings </p> </div> </> )} <i className="mdi-unfold-more-horizontal h-6 w-6 ml-auto" /> </div> </DropdownMenuTrigger> <DropdownMenuContent side="right" align="end" forceMount> {auth?.sessionUser?.name && ( <> <DropdownMenuLabel className="font-normal"> <div className="flex flex-col space-y-1"> <p className="text-sm font-medium leading-none"> {auth?.sessionUser?.name} </p> {auth?.sessionUser?.email && ( <p className="text-xs leading-none text-muted-foreground"> {auth?.sessionUser?.email} </p> )} </div> </DropdownMenuLabel> <DropdownMenuSeparator /> </> )} <DropdownMenuItem> <div className="flex gap-4 w-full items-center justify-between"> Dark mode <Switch checked={darkMode.value} onCheckedChange={(value) => darkMode.value = value} /> </div> </DropdownMenuItem> {auth?.sessionUser?.name && ( <> <DropdownMenuSeparator /> <DropdownMenuItem> <a href="/auth/signout" title="Sign out" className="w-full"> Log out </a> </DropdownMenuItem> </> )} </DropdownMenuContent> </DropdownMenu> );}
netzo

Version Info

Tagged at
a year ago