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",
14 mode === "embedded" ? "px-2" : "px-4",
15 shouldUseDragRegion
16 ? "drag-region h-[var(--workspace-topbar-height)] border-b border-border wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]"
17 : "flex h-10 min-h-10 shrink-0 items-center border-b border-border/60 bg-background in-data-[preview-panel-mode=inline]:mb-3 in-data-[preview-panel-mode=inline]:h-7 in-data-[preview-panel-mode=inline]:min-h-7 in-data-[preview-panel-mode=inline]:border-b-transparent",
18 );
19}
20
21export function DiffPanelShell(props: {
22 mode: DiffPanelMode;
23 header: ReactNode;
24 children: ReactNode;
25}) {
26 const shouldUseDragRegion = isElectron && props.mode !== "sheet" && props.mode !== "embedded";
27
28 return (
29 <div
30 className={cn(
31 "flex h-full min-w-0 flex-col bg-background",
32 props.mode === "inline"
33 ? "w-[42vw] min-w-[360px] max-w-[560px] shrink-0 border-l border-border"
34 : "w-full",
35 )}
36 >
37 {shouldUseDragRegion ? (
38 <div className={getDiffPanelHeaderRowClassName(props.mode)}>{props.header}</div>
39 ) : (
40 <div className={getDiffPanelHeaderRowClassName(props.mode)} data-surface-subheader>
41 {props.header}
42 </div>
43 )}
44 {props.children}
45 </div>
46 );
47}
48
49export function DiffFileHeaderSkeleton({ titleClassName }: { titleClassName: string }) {
50 return (
51 <div className="flex h-8 items-center gap-2 px-2 pr-3">
52 <div className="flex size-5 shrink-0 items-center justify-center">
53 <Skeleton className="size-2.5" />
54 </div>
55 <Skeleton className="size-5 shrink-0" />
56 <Skeleton shape="pill" className={cn("h-3", titleClassName)} />
57 <div className="ml-auto flex shrink-0 items-center gap-2">
58 <Skeleton shape="pill" className="h-3 w-5" />
59 <Skeleton shape="pill" className="h-3 w-5" />
60 </div>
61 </div>
62 );
63}
64
65function DiffCodeLineSkeleton({ contentClassName }: { contentClassName: string }) {
66 return (
67 <div className="flex items-center gap-3">
68 <Skeleton shape="pill" className="h-2.5 w-5 shrink-0" />
69 <Skeleton shape="pill" className={cn("h-2.5", contentClassName)} />
70 </div>
71 );
72}
73
74export function DiffPanelLoadingState(props: { label: string }) {
75 return (
76 <div
77 className="min-h-0 flex-1 overflow-hidden bg-background"
78 role="status"
79 aria-live="polite"
80 aria-label={props.label}
81 >
82 <DiffFileHeaderSkeleton titleClassName="w-1/2 max-w-64" />
83 <div className="flex h-6 items-center gap-2 px-2 pr-3">
84 <div className="h-px flex-1 bg-border/40" />
85 <Skeleton shape="pill" className="h-2.5 w-24" />
86 <div className="h-px flex-1 bg-border/40" />
87 </div>
88 <div className="space-y-2 px-3 py-2">
89 <DiffCodeLineSkeleton contentClassName="w-2/3" />
90 <DiffCodeLineSkeleton contentClassName="w-4/5" />
91 <DiffCodeLineSkeleton contentClassName="w-3/5" />
92 </div>
93 <DiffFileHeaderSkeleton titleClassName="w-2/5 max-w-52" />
94 <DiffFileHeaderSkeleton titleClassName="w-3/5 max-w-72" />
95 <span className="sr-only">{props.label}</span>
96 </div>
97 );
98}