Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PullRequestGhosts.tsx

144 lines5.7 KB

1/**
2 * Loading states specific to the pull request surface — the first list, a search under way,
3 * and a detail panel opening — use bars in the geometry of the content they stand for, pulsing
4 * on one composited layer. Diff loading uses the shared diff-panel skeleton instead.
5 *
6 * Deliberately not the app's shimmer skeleton. The sweep is a `transform` animation per bar —
7 * compositor-safe, but a layer for every bar on screen — and its white highlight over the
8 * near-white `muted` base all but disappears in light mode. Here one `animate-ghost-pulse` on the
9 * container is a single opacity animation however many bars sit under it, and the bars take
10 * their tone from `muted-foreground` at low alpha, which reads on both themes.
11 */
12import { cn } from "~/lib/utils";
13​
14function GhostBar({ className }: { className?: string | undefined }) {
15 return <div aria-hidden className={cn("h-3 rounded bg-muted-foreground/15", className)} />;
17​
18/** Widths cycle rather than randomize, so the ghost renders the same on every pass. */
19const TITLE_WIDTHS = ["w-3/5", "w-2/5", "w-1/2", "w-2/3", "w-2/5", "w-3/5", "w-1/2"];
20const META_WIDTHS = ["w-2/5", "w-1/3", "w-2/5", "w-1/4", "w-1/3", "w-2/5", "w-1/3"];
21​
22/** Rows in the list's own grid — glyph, title over meta, time over diffstat. */
23export function PullRequestListGhost({
24 rows = 7,
25 caption,
26}: {
27 rows?: number;
28 /** Said where the group headers speak, for the states with something to say — a search. */
29 caption?: string;
30}) {
31 return (
32 <div
33 role="status"
34 aria-label={caption ?? "Loading pull requests"}
35 className="animate-ghost-pulse space-y-0.5"
36 >
37 {caption ? (
38 <p className="px-3 pb-1 text-xs font-medium text-muted-foreground/70">{caption}</p>
39 ) : null}
40 {Array.from({ length: rows }, (_, index) => (
41 <div
42 key={index}
43 className="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg px-3 py-2"
44 >
45 <GhostBar className="size-4 rounded-full" />
46 <div className="min-w-0 space-y-1.5">
47 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
48 <GhostBar
49 className={cn("bg-muted-foreground/10", META_WIDTHS[index % META_WIDTHS.length])}
50 />
51 </div>
52 <div className="flex flex-col items-end gap-1.5">
53 <GhostBar className="w-12" />
54 <GhostBar className="w-16 bg-muted-foreground/10" />
55 </div>
56 </div>
57 ))}
58 </div>
59 );
61​
62/** The summary's own shape: a title, a byline, the facts rows, the description. */
63export function PullRequestDetailGhost() {
64 return (
65 <div
66 role="status"
67 aria-label="Loading pull request"
68 className="animate-ghost-pulse space-y-6 px-4 py-5"
69 >
70 <div className="space-y-2">
71 <GhostBar className="h-5 w-4/5" />
72 <GhostBar className="w-2/5 bg-muted-foreground/10" />
73 </div>
74 <div className="space-y-3">
75 {Array.from({ length: 4 }, (_, index) => (
76 <div key={index} className="flex items-center gap-3">
77 <GhostBar className="size-3.5 rounded-full" />
78 <GhostBar className="w-20 bg-muted-foreground/10" />
79 <GhostBar className={TITLE_WIDTHS[(index + 1) % TITLE_WIDTHS.length]} />
80 </div>
81 ))}
82 </div>
83 <div className="space-y-2 pt-1">
84 <GhostBar className="w-full bg-muted-foreground/10" />
85 <GhostBar className="w-11/12 bg-muted-foreground/10" />
86 <GhostBar className="w-4/5 bg-muted-foreground/10" />
87 <GhostBar className="w-2/3 bg-muted-foreground/10" />
88 </div>
89 </div>
90 );
92​
93/** People-shaped: an avatar and a name, in the reviewer picker's own row height. */
94export function PullRequestPeopleGhost({ rows = 4 }: { rows?: number }) {
95 return (
96 <div role="status" aria-label="Loading people" className="animate-ghost-pulse space-y-1 p-1">
97 {Array.from({ length: rows }, (_, index) => (
98 <div key={index} className="flex h-7 items-center gap-2 rounded-md px-2">
99 <GhostBar className="size-4 rounded-full" />
100 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
101 </div>
102 ))}
103 </div>
104 );
106​
107/** The timeline's own shape: dots on the rail, a line and a date to each. */
108export function PullRequestTimelineGhost({ rows = 6 }: { rows?: number }) {
109 return (
110 <div role="status" aria-label="Loading timeline" className="animate-ghost-pulse px-4 py-5">
111 <div className="relative ml-2 border-l border-border/70 pl-5">
112 {Array.from({ length: rows }, (_, index) => (
113 <div key={index} className="relative pb-5">
114 <GhostBar className="absolute -left-[1.55rem] top-1 size-2 rounded-full" />
115 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
116 <GhostBar className="mt-1.5 w-16 bg-muted-foreground/10" />
117 </div>
118 ))}
119 </div>
120 </div>
121 );
123​
124/** A compact placeholder for the conversation while the core detail is already readable. */
125export function PullRequestConversationGhost({ rows = 3 }: { rows?: number }) {
126 return (
127 <div
128 role="status"
129 aria-label="Loading pull request conversation"
130 className="animate-ghost-pulse space-y-4 py-2"
131 >
132 {Array.from({ length: rows }, (_, index) => (
133 <div key={index} className="flex items-start gap-2">
134 <GhostBar className="size-5 shrink-0 rounded-full" />
135 <div className="flex-1 space-y-1.5">
136 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
137 <GhostBar className="w-full bg-muted-foreground/10" />
138 <GhostBar className="w-3/4 bg-muted-foreground/10" />
139 </div>
140 </div>
141 ))}
142 </div>
143 );