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

DiffPanelShell.tsx

112 lines3.6 KB

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-[52px] border-b border-border wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]"
17 : "surface-subheader",
18 );
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 );
48​
49export function DiffPanelHeaderSkeleton() {
50 return (
51 <>
52 <div className="min-w-0 flex-1">
53 <Skeleton className="h-8 w-32 rounded-lg" />
54 </div>
55 <div className="flex shrink-0 gap-1">
56 <Skeleton className="size-7 rounded-md" />
57 <Skeleton className="size-7 rounded-md" />
58 </div>
59 </>
60 );
62​
63function DiffFileHeaderSkeleton({ titleClassName }: { titleClassName: string }) {
64 return (
65 <div className="flex h-8 items-center gap-2 px-2 pr-3">
66 <div className="flex size-5 shrink-0 items-center justify-center">
67 <Skeleton className="size-2.5 rounded-[2px]" />
68 </div>
69 <Skeleton className="size-5 shrink-0 rounded-md" />
70 <Skeleton className={cn("h-3 rounded-full", titleClassName)} />
71 <div className="ml-auto flex shrink-0 items-center gap-2">
72 <Skeleton className="h-3 w-5 rounded-full" />
73 <Skeleton className="h-3 w-5 rounded-full" />
74 </div>
75 </div>
76 );
78​
79function DiffCodeLineSkeleton({ contentClassName }: { contentClassName: string }) {
80 return (
81 <div className="flex items-center gap-3">
82 <Skeleton className="h-2.5 w-5 shrink-0 rounded-full" />
83 <Skeleton className={cn("h-2.5 rounded-full", contentClassName)} />
84 </div>
85 );
87​
88export function DiffPanelLoadingState(props: { label: string }) {
89 return (
90 <div
91 className="min-h-0 flex-1 overflow-hidden bg-background"
92 role="status"
93 aria-live="polite"
94 aria-label={props.label}
95 >
96 <DiffFileHeaderSkeleton titleClassName="w-1/2 max-w-64" />
97 <div className="flex h-6 items-center gap-2 px-2 pr-3">
98 <div className="h-px flex-1 bg-border/40" />
99 <Skeleton className="h-2.5 w-24 rounded-full" />
100 <div className="h-px flex-1 bg-border/40" />
101 </div>
102 <div className="space-y-2 px-3 py-2">
103 <DiffCodeLineSkeleton contentClassName="w-2/3" />
104 <DiffCodeLineSkeleton contentClassName="w-4/5" />
105 <DiffCodeLineSkeleton contentClassName="w-3/5" />
106 </div>
107 <DiffFileHeaderSkeleton titleClassName="w-2/5 max-w-52" />
108 <DiffFileHeaderSkeleton titleClassName="w-3/5 max-w-72" />
109 <span className="sr-only">{props.label}</span>
110 </div>
111 );