Open History to see the last commit
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 * The bars share the app-wide `Skeleton` tone (`muted-foreground` at low alpha, which reads on
7 * both themes) and the single `animate-skeleton` pulse, applied once on the container so any
8 * number of bars costs one opacity animation.
9 */
10import { cn } from "~/lib/utils";
11
12function GhostBar({ className }: { className?: string | undefined }) {
13 return <div aria-hidden className={cn("h-3 rounded bg-muted-foreground/15", className)} />;
14}
15
16/** Widths cycle rather than randomize, so the ghost renders the same on every pass. */
17const TITLE_WIDTHS = ["w-3/5", "w-2/5", "w-1/2", "w-2/3", "w-2/5", "w-3/5", "w-1/2"];
18const META_WIDTHS = ["w-2/5", "w-1/3", "w-2/5", "w-1/4", "w-1/3", "w-2/5", "w-1/3"];
19
20/** Rows in the list's own grid — glyph, title over meta, time over diffstat. */
21export function PullRequestListGhost({
22 rows = 7,
23 caption,
24}: {
25 rows?: number;
26 /** Said where the group headers speak, for the states with something to say — a search. */
27 caption?: string;
28}) {
29 return (
30 <div
31 role="status"
32 aria-label={caption ?? "Loading pull requests"}
33 className="motion-safe:animate-skeleton space-y-0.5"
34 >
35 {caption ? (
36 <p className="px-3 pb-1 text-xs font-medium text-muted-foreground/70">{caption}</p>
37 ) : null}
38 {Array.from({ length: rows }, (_, index) => (
39 <div
40 key={index}
41 className="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg px-3 py-2"
42 >
43 <GhostBar className="size-4 rounded-full" />
44 <div className="min-w-0 space-y-1.5">
45 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
46 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
47 </div>
48 <div className="flex flex-col items-end gap-1.5">
49 <GhostBar className="w-12" />
50 <GhostBar className="w-16" />
51 </div>
52 </div>
53 ))}
54 </div>
55 );
56}
57
58/**
59 * The detail panel's current expanded shape. Keeping the chrome, summary facts, and description
60 * boundaries in the ghost prevents the loaded pull request from replacing one layout with
61 * another a moment later.
62 */
63export function PullRequestDetailGhost() {
64 return (
65 <div
66 role="status"
67 aria-label="Loading pull request"
68 className="motion-safe:animate-skeleton flex h-full min-h-0 flex-col overflow-hidden bg-background"
69 >
70 <div className="shrink-0 border-b border-border/60">
71 <div className="flex h-7 items-center justify-between gap-3 px-4">
72 <div className="flex min-w-0 flex-1 items-center gap-1.5">
73 <GhostBar className="w-24" />
74 <GhostBar className="w-9" />
75 </div>
76 <div className="flex shrink-0 items-center gap-1">
77 <GhostBar className="h-5 w-16 rounded-md" />
78 <GhostBar className="size-5 rounded-md" />
79 </div>
80 </div>
81
82 <div className="px-4 pb-4 pt-1">
83 <GhostBar className="h-5 w-4/5 max-w-md" />
84 <div className="mt-2 flex items-center gap-1.5">
85 <GhostBar className="size-4 rounded-full" />
86 <GhostBar className="w-24" />
87 </div>
88 <div className="mt-4 flex min-w-0 items-center gap-2">
89 <GhostBar className="h-6 w-24 rounded-md" />
90 <GhostBar className="size-3 rounded-full" />
91 <GhostBar className="h-6 w-32 rounded-md" />
92 <div className="ml-auto flex shrink-0 items-center gap-2">
93 <GhostBar className="w-10" />
94 <GhostBar className="w-20" />
95 </div>
96 </div>
97 </div>
98
99 <div className="flex min-h-10 items-center justify-between gap-3 border-t border-border/60 px-4 py-2">
100 <div className="flex items-center gap-1 p-0.5">
101 <GhostBar className="h-6 w-16 rounded-md" />
102 <GhostBar className="h-6 w-16 rounded-md" />
103 <GhostBar className="h-6 w-12 rounded-md" />
104 </div>
105 <GhostBar className="w-20" />
106 </div>
107 </div>
108
109 <div className="min-h-0 flex-1 overflow-hidden">
110 <section className="px-4 py-3">
111 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
112 <div className="flex items-center gap-1.5">
113 <GhostBar className="size-3.5 rounded-full" />
114 <GhostBar className="w-14" />
115 </div>
116 <div className="flex items-center gap-1">
117 <GhostBar className="size-4 rounded-full" />
118 <GhostBar className="size-4 rounded-full" />
119 <GhostBar className="ml-1 size-5 rounded-md" />
120 </div>
121 </div>
122 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
123 <div className="flex items-center gap-1.5">
124 <GhostBar className="size-3.5 rounded-full" />
125 <GhostBar className="w-10" />
126 </div>
127 <div className="flex items-center gap-1">
128 <GhostBar className="h-5 w-24 rounded-full" />
129 <GhostBar className="h-5 w-20 rounded-full" />
130 </div>
131 </div>
132 <div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
133 <div className="flex items-center gap-1.5">
134 <GhostBar className="size-3.5 rounded-full" />
135 <GhostBar className="w-14" />
136 </div>
137 <GhostBar className="w-20" />
138 </div>
139 </section>
140
141 <section className="border-t border-border/60">
142 <div className="flex min-h-11 items-center gap-1.5 px-4 py-3">
143 <GhostBar className="h-4 w-24" />
144 <GhostBar className="size-3.5 rounded-full" />
145 </div>
146 <div className="space-y-2 px-4 pb-4">
147 <GhostBar className="w-full" />
148 <GhostBar className="w-11/12" />
149 <GhostBar className="w-4/5" />
150 <GhostBar className="w-2/3" />
151 </div>
152 </section>
153 </div>
154 </div>
155 );
156}
157
158/** People-shaped: an avatar and a name, in the reviewer picker's own row height. */
159export function PullRequestPeopleGhost({ rows = 4 }: { rows?: number }) {
160 return (
161 <div
162 role="status"
163 aria-label="Loading people"
164 className="motion-safe:animate-skeleton space-y-1 p-1"
165 >
166 {Array.from({ length: rows }, (_, index) => (
167 <div key={index} className="flex h-7 items-center gap-2 rounded-md px-2">
168 <GhostBar className="size-4 rounded-full" />
169 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
170 </div>
171 ))}
172 </div>
173 );
174}
175
176/** The timeline's own shape: dots on the rail, a line and a date to each. */
177export function PullRequestTimelineGhost({ rows = 6 }: { rows?: number }) {
178 return (
179 <div
180 role="status"
181 aria-label="Loading timeline"
182 className="motion-safe:animate-skeleton px-4 py-5"
183 >
184 <div className="relative ml-2 border-l border-border/70 pl-5">
185 {Array.from({ length: rows }, (_, index) => (
186 <div key={index} className="relative pb-5">
187 <GhostBar className="absolute -left-[1.55rem] top-1 size-2 rounded-full" />
188 <GhostBar className={cn("h-3.5", TITLE_WIDTHS[index % TITLE_WIDTHS.length])} />
189 <GhostBar className="mt-1.5 w-16" />
190 </div>
191 ))}
192 </div>
193 </div>
194 );
195}
196
197/** A compact placeholder for the conversation while the core detail is already readable. */
198export function PullRequestConversationGhost({ rows = 3 }: { rows?: number }) {
199 return (
200 <div
201 role="status"
202 aria-label="Loading pull request conversation"
203 className="motion-safe:animate-skeleton space-y-4 py-2"
204 >
205 {Array.from({ length: rows }, (_, index) => (
206 <div key={index} className="flex items-start gap-2">
207 <GhostBar className="size-5 shrink-0 rounded-full" />
208 <div className="flex-1 space-y-1.5">
209 <GhostBar className={META_WIDTHS[index % META_WIDTHS.length]} />
210 <GhostBar className="w-full" />
211 <GhostBar className="w-3/4" />
212 </div>
213 </div>
214 ))}
215 </div>
216 );
217}