Refactored mobile-nav component

This commit is contained in:
Zhenya Goroh
2024-10-08 21:23:27 +03:00
parent d77b0419b0
commit 6018a2235a
2 changed files with 43 additions and 31 deletions

View File

@@ -12,6 +12,37 @@ import Logo from "./logo";
import { ny } from "@/lib/utils"; import { ny } from "@/lib/utils";
import { components } from "./navigation"; import { components } from "./navigation";
interface MobileLinkProps
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
onOpenChange?: (open: boolean) => void;
children: React.ReactNode;
className?: string;
href: string;
}
function MobileLink({
href,
onOpenChange,
className,
children,
...props
}: MobileLinkProps) {
const router = useRouter();
return (
<a
href={href}
onClick={() => {
router.push(href);
onOpenChange?.(false);
}}
className={ny(className, "my-4")}
{...props}
>
{children}
</a>
);
}
export function MobileNav() { export function MobileNav() {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
@@ -60,12 +91,18 @@ export function MobileNav() {
<MobileLink <MobileLink
href="https://patreon.com/zen_browser?utm_medium=unknown&utm_source=join_link&utm_campaign=creatorshare_creator&utm_content=copyLink" href="https://patreon.com/zen_browser?utm_medium=unknown&utm_source=join_link&utm_campaign=creatorshare_creator&utm_content=copyLink"
onOpenChange={setOpen} onOpenChange={setOpen}
target="_blank"
> >
<div>Donate {"<"}3</div> <div>Donate {"<"}3</div>
<p className="text-xs opacity-60">Support the project</p> <p className="text-xs opacity-60">Support the project</p>
</MobileLink> </MobileLink>
{components.map(({ title, href, description }) => ( {components.map(({ title, href, description, isTargetBlank }) => (
<MobileLink href={href} key={href} onOpenChange={setOpen}> <MobileLink
href={href}
key={href}
target={isTargetBlank ? "_blank" : "_self"}
onOpenChange={setOpen}
>
<div>{title}</div> <div>{title}</div>
<p className="text-xs opacity-60">{description}</p> <p className="text-xs opacity-60">{description}</p>
</MobileLink> </MobileLink>
@@ -76,32 +113,3 @@ export function MobileNav() {
</Sheet> </Sheet>
); );
} }
interface MobileLinkProps extends LinkProps {
onOpenChange?: (open: boolean) => void;
children: React.ReactNode;
className?: string;
}
function MobileLink({
href,
onOpenChange,
className,
children,
...props
}: MobileLinkProps) {
const router = useRouter();
return (
<a
href={href.toString()}
onClick={() => {
router.push(href.toString());
onOpenChange?.(false);
}}
className={ny(className, "my-4")}
{...props}
>
{children}
</a>
);
}

View File

@@ -21,6 +21,7 @@ export const components: {
title: string; title: string;
href: string; href: string;
description: string; description: string;
isTargetBlank?: boolean;
}[] = [ }[] = [
{ {
title: "Privacy Policy", title: "Privacy Policy",
@@ -33,12 +34,14 @@ export const components: {
href: "https://discord.gg/zen-browser", href: "https://discord.gg/zen-browser",
description: description:
"Join our Discord server to chat with the community and get support.", "Join our Discord server to chat with the community and get support.",
isTargetBlank: true,
}, },
{ {
title: "Source Code", title: "Source Code",
href: "https://github.com/zen-browser", href: "https://github.com/zen-browser",
description: description:
"View the source code on GitHub and contribute to the project.", "View the source code on GitHub and contribute to the project.",
isTargetBlank: true,
}, },
{ {
title: "Branding Assets", title: "Branding Assets",
@@ -55,6 +58,7 @@ export const components: {
title: "Documentation", title: "Documentation",
href: "https://docs.zen-browser.app/", href: "https://docs.zen-browser.app/",
description: "Read the documentation to learn more about Zen Browser.", description: "Read the documentation to learn more about Zen Browser.",
isTargetBlank: true,
}, },
]; ];