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

PullRequestGhosts.tsx

211 lines8.5 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 className={META_WIDTHS[index % META_WIDTHS.length]} />
49 </div>
50 <div className="flex flex-col items-end gap-1.5">
51 <GhostBar className="w-12" />
52 <GhostBar className="w-16" />
53 </div>
54 </div>
55 ))}
56 </div>
57 );
59​
60/**
61 * The detail panel's current expanded shape. Keeping the chrome, summary facts, and description
62 * boundaries in the ghost prevents the loaded pull request from replacing one layout with
63 * another a moment later.
64 */
65export function PullRequestDetailGhost() {
66 return (
67 <div
68 role="status"
69 aria-label="Loading pull request"
70 className="animate-ghost-pulse flex h-full min-h-0 flex-col overflow-hidden bg-background"
71 >
72 <div className="shrink-0 border-b border-border/60">
73 <div className="flex h-7 items-center justify-between gap-3 px-4">
74 <div className="flex min-w-0 flex-1 items-center gap-1.5">
75 <GhostBar className="w-24" />
76 <GhostBar className="w-9" />
77 </div>
78 <div className="flex shrink-0 items-center gap-1">
79 <GhostBar className="h-5 w-16 rounded-md" />
80 <GhostBar className="size-5 rounded-md" />
81 </div>
82 </div>
83​
84 <div className="px-4 pb-4 pt-1">
85 <GhostBar className="h-5 w-4/5 max-w-md" />
86 <div className="mt-2 flex items-center gap-1.5">
87 <GhostBar className="size-4 rounded-full" />
88 <GhostBar className="w-24" />
89 </div>
90 <div className="mt-4 flex min-w-0 items-center gap-2">
91 <GhostBar className="h-6 w-24 rounded-md" />
92 <GhostBar className="size-3 rounded-full" />
93 <GhostBar className="h-6 w-32 rounded-md" />
94 <div className="ml-auto flex shrink-0 items-center gap-2">
95 <GhostBar className="w-10" />
96 <GhostBar className="w-20" />
97 </div>
98 </div>
99 </div>
100​
101 <div className="flex min-h-10 items-center justify-between gap-3 border-t border-border/60 px-4 py-2">
102 <div className="flex items-center gap-1 p-0.5">
103 <GhostBar className="h-6 w-16 rounded-md" />
104 <GhostBar className="h-6 w-16 rounded-md" />
105 <GhostBar className="h-6 w-12 rounded-md" />
106 </div>
107 <GhostBar className="w-20" />
108 </div>
109 </div>
110​
111 <div className="min-h-0 flex-1 overflow-hidden">
112 <section className="px-4 py-3">
113 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
114 <div className="flex items-center gap-1.5">
115 <GhostBar className="size-3.5 rounded-full" />
116 <GhostBar className="w-14" />
117 </div>
118 <div className="flex items-center gap-1">
119 <GhostBar className="size-4 rounded-full" />
120 <GhostBar className="size-4 rounded-full" />
121 <GhostBar className="ml-1 size-5 rounded-md" />
122 </div>
123 </div>
124 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
125 <div className="flex items-center gap-1.5">
126 <GhostBar className="size-3.5 rounded-full" />
127 <GhostBar className="w-10" />
128 </div>
129 <div className="flex items-center gap-1">
130 <GhostBar className="h-5 w-24 rounded-full" />
131 <GhostBar className="h-5 w-20 rounded-full" />
132 </div>
133 </div>
134 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
135 <div className="flex items-center gap-1.5">
136 <GhostBar className="size-3.5 rounded-full" />
137 <GhostBar className="w-14" />
138 </div>
139 <GhostBar className="w-20" />
140 </div>
141 </section>
142​
143 <section className="border-t border-border/60">
144 <div className="flex min-h-11 items-center gap-1.5 px-4 py-3">
145 <GhostBar className="h-4 w-24" />
146 <GhostBar className="size-3.5 rounded-full" />
147 </div>
148 <div className="space-y-2 px-4 pb-4">
149 <GhostBar className="w-full" />
150 <GhostBar className="w-11/12" />
151 <GhostBar className="w-4/5" />
152 <GhostBar className="w-2/3" />
153 </div>
154 </section>
155 </div>
156 </div>
157 );
159​
160/** People-shaped: an avatar and a name, in the reviewer picker's own row height. */
161export function PullRequestPeopleGhost({ rows = 4 }: { rows?: number }) {
162 return (
163 <div role="status" aria-label="Loading people" className="animate-ghost-pulse space-y-1 p-1">
164 {Array.from({ length: rows }, (_, index) => (
165 <div key={index} className="flex h-7 items-center gap-2 rounded-md px-2">
166 <GhostBar className="size-4 rounded-full" />
167 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
168 </div>
169 ))}
170 </div>
171 );
173​
174/** The timeline's own shape: dots on the rail, a line and a date to each. */
175export function PullRequestTimelineGhost({ rows = 6 }: { rows?: number }) {
176 return (
177 <div role="status" aria-label="Loading timeline" className="animate-ghost-pulse px-4 py-5">
178 <div className="relative ml-2 border-l border-border/70 pl-5">
179 {Array.from({ length: rows }, (_, index) => (
180 <div key={index} className="relative pb-5">
181 <GhostBar className="absolute -left-[1.55rem] top-1 size-2 rounded-full" />
182 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
183 <GhostBar className="mt-1.5 w-16" />
184 </div>
185 ))}
186 </div>
187 </div>
188 );
190​
191/** A compact placeholder for the conversation while the core detail is already readable. */
192export function PullRequestConversationGhost({ rows = 3 }: { rows?: number }) {
193 return (
194 <div
195 role="status"
196 aria-label="Loading pull request conversation"
197 className="animate-ghost-pulse space-y-4 py-2"
198 >
199 {Array.from({ length: rows }, (_, index) => (
200 <div key={index} className="flex items-start gap-2">
201 <GhostBar className="size-5 shrink-0 rounded-full" />
202 <div className="flex-1 space-y-1.5">
203 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
204 <GhostBar className="w-full" />
205 <GhostBar className="w-3/4" />
206 </div>
207 </div>
208 ))}
209 </div>
210 );