Open History to see the last commit
1import type { ReactNode } from "react";
2
3import { isElectron } from "~/env";
4import { cn } from "~/lib/utils";
5
6import { Skeleton } from "./ui/skeleton";
7
8export type DiffPanelMode = "inline" | "sheet" | "sidebar" | "embedded";
9
10function getDiffPanelHeaderRowClassName(mode: DiffPanelMode) {
11 const shouldUseDragRegion = isElectron && mode !== "sheet" && mode !== "embedded";
12 return cn(
13 "flex items-center justify-between gap-2 px-4",
14 shouldUseDragRegion
15 ? "drag-region h-[52px] border-b border-border wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]"
16 : "surface-subheader",
17 );
18}
19
20export function DiffPanelShell(props: {
21 mode: DiffPanelMode;
22 header: ReactNode;
23 children: ReactNode;
24}) {
25 const shouldUseDragRegion = isElectron && props.mode !== "sheet" && props.mode !== "embedded";
26
27 return (
28 <div
29 className={cn(
30 "flex h-full min-w-0 flex-col bg-background",
31 props.mode === "inline"
32 ? "w-[42vw] min-w-[360px] max-w-[560px] shrink-0 border-l border-border"
33 : "w-full",
34 )}
35 >
36 {shouldUseDragRegion ? (
37 <div className={getDiffPanelHeaderRowClassName(props.mode)}>{props.header}</div>
38 ) : (
39 <div className={getDiffPanelHeaderRowClassName(props.mode)} data-surface-subheader>
40 {props.header}
41 </div>
42 )}
43 {props.children}
44 </div>
45 );
46}
47
48export function DiffPanelHeaderSkeleton() {
49 return (
50 <>
51 <div className="min-w-0 flex-1">
52 <Skeleton className="h-8 w-32 rounded-lg" />
53 </div>
54 <div className="flex shrink-0 gap-1">
55 <Skeleton className="size-7 rounded-md" />
56 <Skeleton className="size-7 rounded-md" />
57 </div>
58 </>
59 );
60}
61
62export function DiffPanelLoadingState(props: { label: string }) {
63 return (
64 <div className="flex min-h-0 flex-1 flex-col p-2">
65 <div
66 className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-md border border-border/60 bg-card/25"
67 role="status"
68 aria-live="polite"
69 aria-label={props.label}
70 >
71 <div className="flex items-center gap-2 border-b border-border/50 px-3 py-2">
72 <Skeleton className="h-4 w-32 rounded-full" />
73 <Skeleton className="ml-auto h-4 w-20 rounded-full" />
74 </div>
75 <div className="flex min-h-0 flex-1 flex-col gap-4 px-3 py-4">
76 <div className="space-y-2">
77 <Skeleton className="h-3 w-full rounded-full" />
78 <Skeleton className="h-3 w-full rounded-full" />
79 <Skeleton className="h-3 w-10/12 rounded-full" />
80 <Skeleton className="h-3 w-11/12 rounded-full" />
81 <Skeleton className="h-3 w-9/12 rounded-full" />
82 </div>
83 <span className="sr-only">{props.label}</span>
84 </div>
85 </div>
86 </div>
87 );
88}