Skip to content

Commit

Permalink
refactor(layout): ♻️ add sidebar to mosaic
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydrichards committed Jan 1, 2025
1 parent 0abac5f commit 22838f0
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 177 deletions.
4 changes: 4 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ const nextConfig = {

const withMDX = createMDX({
options: {
// @ts-expect-error wrong types
remarkPlugins: [["remark-gfm", { strict: true, throwOnError: true }]],
rehypePlugins: [
// @ts-expect-error wrong types
["rehype-pretty-code", { strict: true, throwOnError: true }],
// @ts-expect-error wrong types
["rehype-slug", { strict: true, throwOnError: true }],
[
// @ts-expect-error wrong types
"rehype-autolink-headings",
{
strict: true,
Expand Down
7 changes: 2 additions & 5 deletions src/app/lab/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ const LabLayout: FC<{
const content = await getAllLabs();
const allLabs = content.map(({ frontmatter }) => frontmatter);
return (
<Mosaic>
<LabNavigation
labs={allLabs}
className="md:col-span-2 md:col-start-1 lg:col-span-6 lg:col-start-1"
/>
<Mosaic sidebar>
<LabNavigation labs={allLabs} />
<LabInfoCard labs={allLabs} />
<LabContent labs={allLabs}>{children}</LabContent>
</Mosaic>
Expand Down
4 changes: 2 additions & 2 deletions src/app/lab/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FC } from "react";
const LabOverviewPage: FC = async () => {
const allLabs = await getAllLabs();
return (
<>
<article className="mosaic-rows col-span-full grid grid-flow-dense grid-cols-subgrid">
{allLabs.map(({ frontmatter }) => (
<Tile
key={frontmatter.slug}
Expand All @@ -15,7 +15,7 @@ const LabOverviewPage: FC = async () => {
<LabCard lab={frontmatter} asLink />
</Tile>
))}
</>
</article>
);
};

Expand Down
16 changes: 3 additions & 13 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "@/styles/globals.css";
import { inter, josefin_sans, roboto_mono } from "@/styles/fonts";

import "@/styles/globals.css";

import { Navbar } from "@/components/organism/navbar";
import { Footer } from "@/components/organism/footer";
import { cn } from "@/lib/utils";
import { ThemeProvider } from "next-themes";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata = {
title: "Lloyd Richards Design",
description:
Expand Down Expand Up @@ -59,7 +49,7 @@ export default function RootLayout({
className={cn(
"min-h-dvh w-full lg:max-w-6xl",
"mosaic-columns grid grid-flow-dense",
"justify-self-center",
"justify-self-center p-2",
)}
>
<ThemeProvider attribute="class" enableSystem>
Expand Down
8 changes: 3 additions & 5 deletions src/app/project/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const ProjectPage = async ({

return (
<>
<section className="col-span-full row-span-2 md:col-[3/-1] lg:col-[7/-1]">
<section className="mosaic-rows col-span-full grid">
<h1>{frontmatter.title}</h1>
<p>{frontmatter.description}</p>
<p className="row-span-2">{frontmatter.description}</p>
</section>
<article className="col-span-full row-span-10 md:col-[3/-1] md:row-span-24 lg:col-[7/-1]">
{content}
</article>
<article className="col-span-full mb-16">{content}</article>
</>
);
};
Expand Down
7 changes: 2 additions & 5 deletions src/app/project/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ const ProjectLayout: FC<{
const content = await getAllProjects();
const allProjects = content.map(({ frontmatter }) => frontmatter);
return (
<Mosaic>
<ProjectNavigation
projects={allProjects}
className="md:col-span-2 md:col-start-1 lg:col-span-6 lg:col-start-1"
/>
<Mosaic sidebar>
<ProjectNavigation projects={allProjects} />
{children}
</Mosaic>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/project/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FC } from "react";
const ProjectOverviewPage: FC = async () => {
const allProjects = await getAllProjects();
return (
<>
<article className="mosaic-rows col-span-full grid grid-flow-dense grid-cols-subgrid">
{allProjects.map(({ frontmatter }, idx) => (
<Tile
key={frontmatter.slug}
Expand All @@ -15,7 +15,7 @@ const ProjectOverviewPage: FC = async () => {
<ProjectCard project={frontmatter} asLink />
</Tile>
))}
</>
</article>
);
};

Expand Down
8 changes: 7 additions & 1 deletion src/components/atom/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { typefaceBody2, typefaceMeta1 } from "../tokens/typeface";

const badgeVariants = cva(
"focus:ring-ring inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-hidden",
"focus:ring-ring inline-flex items-center rounded-full border px-2.5 py-0.5 transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-hidden",
{
variants: {
variant: {
Expand All @@ -16,9 +17,14 @@ const badgeVariants = cva(
"bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent",
outline: "text-foreground border-foreground",
},
size: {
sm: typefaceMeta1(),
md: typefaceBody2(),
},
},
defaultVariants: {
variant: "default",
size: "md",
},
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecule/lab-info-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const LabInfoCard: FC<LabInfoCardProps> = ({ labs, className }) => {
return null;
}
return (
<Tile size="unset" className="col-[3/-1] row-span-4 lg:col-[7/-1]">
<Tile size="unset" className="col-span-full">
<Card className={className}>
<CardHeader className="flex-row justify-between pb-0">
<div className="flex items-center gap-2 opacity-60">
Expand Down
38 changes: 22 additions & 16 deletions src/components/molecule/nav_list_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ import {
NavigationMenuLink,
navigationMenuTriggerStyle,
} from "@/components/atom/navigation-menu";
import { cn } from "@/lib/utils";
import Link from "next/link";
import { FC } from "react";
import { usePathname } from "next/navigation";
import { FC, ReactNode } from "react";
import { Tile } from "../atom/tile";

interface PostsListItemProps {
export const NavListItem: FC<{
children: ReactNode;
href: string;
children?: React.ReactNode;
exact?: boolean;
className?: string;
}

export const NavListItem: FC<PostsListItemProps> = ({ children, href }) => {
}> = ({ children, href, exact, className }) => {
const pathname = usePathname();
return (
<NavigationMenuItem className="w-full">
<Link href={href} legacyBehavior passHref>
<NavigationMenuLink
className={cn(navigationMenuTriggerStyle(), "group w-full gap-1")}
>
{children}
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
<Tile key={href} size="box-xxs" outline={false} className={className}>
<NavigationMenuItem>
<Link href={href} legacyBehavior passHref>
<NavigationMenuLink
className={navigationMenuTriggerStyle({
active: exact ? pathname == href : pathname.includes(href),
className: "flex gap-2 @min-[120px]:justify-start",
})}
>
{children}
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
</Tile>
);
};
89 changes: 27 additions & 62 deletions src/components/organism/lab_navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,39 @@
"use client";

import Link from "next/link";
import { FC, ReactNode } from "react";
import { FC } from "react";
import { Lab } from "@/types/domain";
import { usePathname } from "next/navigation";
import {
NavigationMenu,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
navigationMenuTriggerStyle,
} from "../atom/navigation-menu";
import { Tile } from "../atom/tile";
import { NavigationMenu, NavigationMenuList } from "../atom/navigation-menu";
import { cn } from "@/lib/utils";
import { NavListItem } from "../molecule/nav_list_item";
import { Badge } from "../atom/badge";

interface LabNavigationProps {
labs: Array<Lab>;
className?: string;
}
export const LabNavigation: FC<LabNavigationProps> = ({ labs, className }) => {
return (
<aside className="hidden md:contents">
<NavigationMenu aria-label="Lab Navigation" orientation="vertical">
<NavigationMenuList className="contents">
<LabNavItem href="/Labs" exact className={className}>
All Labs
</LabNavItem>

{labs
.filter((d) => d.isPublished)
.map((p) => (
<LabNavItem
key={p.slug}
href={p.pathname}
className={cn("overflow-visible", className)}
>
{p.id}
<span className="hidden lg:line-clamp-1"> - {p.title}</span>
</LabNavItem>
))}
</NavigationMenuList>
</NavigationMenu>
{labs.length % 2 == 0 ? (
<Tile size="box-xxs" outline={false} className={className} />
) : null}
</aside>
);
};
<NavigationMenu
aria-label="Lab Navigation"
orientation="vertical"
className="hidden md:contents"
>
<NavigationMenuList className="contents">
<NavListItem href="/Labs" exact className={className}>
All Labs
</NavListItem>

const LabNavItem: FC<{
children: ReactNode;
href: string;
exact?: boolean;
className?: string;
}> = ({ children, href, exact, className }) => {
const pathname = usePathname();
return (
<Tile key={href} size="box-xxs" outline={false} className={className}>
<NavigationMenuItem>
<Link href={href} legacyBehavior passHref>
<NavigationMenuLink
className={navigationMenuTriggerStyle({
active: exact ? pathname == href : pathname.includes(href),
className: "@min-[120px]:justify-start",
})}
>
{children}
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
</Tile>
{labs
.filter((d) => d.isPublished)
.map((p) => (
<NavListItem
key={p.slug}
href={p.pathname}
className={cn("overflow-visible", className)}
>
<Badge variant="outline">{p.id}</Badge>
<span className="hidden lg:line-clamp-1">{p.title}</span>
</NavListItem>
))}
</NavigationMenuList>
</NavigationMenu>
);
};
Loading

0 comments on commit 22838f0

Please sign in to comment.