summaryrefslogtreecommitdiff
path: root/apps/web/src/app/changelog/components/release.tsx
blob: 0da74bf40b3f2003e9a4a83f1f5b9bc97dd5012b (plain) (blame)
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
import type { ReactNode } from "react";
import Link from "next/link";
import { cn } from "@/utils/ui";
import {
	getSectionTitle,
	groupAndOrderChanges,
	isSectionCollapsible,
	type Change,
	type Release,
} from "../utils";
import { ArrowRightIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";

export function ReleaseArticle({
	variant,
	isLatest,
	children,
}: {
	variant: "list" | "detail";
	isLatest?: boolean;
	children: ReactNode;
}) {
	if (variant === "list") {
		return (
			<article className="relative sm:pl-10">
				<div aria-hidden className="absolute left-0 top-[3px] hidden sm:block">
					<div
						className={cn(
							"size-[11px] rounded-full border-[1.5px]",
							isLatest
								? "border-foreground bg-foreground"
								: "border-muted-foreground/30 bg-background",
						)}
					/>
				</div>
				<div className="flex flex-col gap-5">{children}</div>
			</article>
		);
	}

	return <article className="flex flex-col gap-8">{children}</article>;
}

export function ReleaseMeta({ release }: { release: Release }) {
	return (
		<span className="text-sm font-medium tracking-widest text-muted-foreground">
			{release.version} — {release.date}
		</span>
	);
}

const titleSizes: Record<"h1" | "h2", string> = {
	h1: "text-4xl",
	h2: "text-2xl",
};

export function ReleaseTitle({
	as: As,
	href,
	children,
}: {
	as: "h1" | "h2";
	href?: string;
	children: ReactNode;
}) {
	return (
		<As className={cn("font-bold tracking-tight", titleSizes[As])}>
			{href ? (
				<Link href={href} className="hover:underline underline-offset-4">
					{children}
				</Link>
			) : (
				children
			)}
		</As>
	);
}

export function ReleaseDescription({ children }: { children: ReactNode }) {
	return (
		<p className="text-base text-foreground leading-relaxed max-w-xl">
			{children}
		</p>
	);
}

export function ReleaseChanges({ release }: { release: Release }) {
	const { grouped, orderedTypes } = groupAndOrderChanges({
		changes: release.changes,
	});

	return (
		<div className="flex flex-col gap-4">
			{orderedTypes.map((type) => (
				<ReleaseChangeSection key={type} type={type} changes={grouped[type]} />
			))}
		</div>
	);
}

function ReleaseChangeSection({
	type,
	changes,
}: {
	type: string;
	changes: Change[];
}) {
	const title = getSectionTitle({ type });

	if (isSectionCollapsible({ type })) {
		return (
			<details className="group flex flex-col gap-1.5">
				<summary className="flex w-fit cursor-pointer list-none items-center gap-1.5 text-base font-semibold text-foreground [&::-webkit-details-marker]:hidden">
					<span>{title}:</span>
					<HugeiconsIcon
						icon={ArrowRightIcon}
						className="size-3 shrink-0 text-muted-foreground group-open:rotate-90"
					/>
				</summary>
				<ReleaseChangeList changes={changes} />
			</details>
		);
	}

	return (
		<div className="flex flex-col gap-1.5">
			<h3 className="text-base font-semibold text-foreground">{title}:</h3>
			<ReleaseChangeList changes={changes} />
		</div>
	);
}

function ReleaseChangeList({
	changes,
	className,
}: {
	changes: Change[];
	className?: string;
}) {
	return (
		<ul className={cn("list-disc space-y-1.5 pl-5", className)}>
			{changes.map((change) => (
				<li
					key={change.text}
					className="text-base leading-relaxed text-foreground"
				>
					{change.text}
				</li>
			))}
		</ul>
	);
}