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

DiffPanelShell.tsx

94 lines3.3 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";
9​
10function getDiffPanelHeaderRowClassName(mode: DiffPanelMode) {
11 const shouldUseDragRegion = isElectron && mode !== "sheet";
12 return cn(
13 "flex items-center justify-between gap-2 px-4 wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]",
14 shouldUseDragRegion
15 ? "drag-region h-[52px] border-b border-border wco:h-[env(titlebar-area-height)]"
16 : "h-12 wco:max-h-[env(titlebar-area-height)]",
17 );
19​
20export function DiffPanelShell(props: {
21 mode: DiffPanelMode;
22 header: ReactNode;
23 children: ReactNode;
24}) {
25 const shouldUseDragRegion = isElectron && props.mode !== "sheet";
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="border-b border-border">
40 <div className={getDiffPanelHeaderRowClassName(props.mode)}>{props.header}</div>
41 </div>
42 )}
43 {props.children}
44 </div>
45 );
47​
48export function DiffPanelHeaderSkeleton() {
49 return (
50 <>
51 <div className="relative min-w-0 flex-1">
52 <Skeleton className="absolute left-0 top-1/2 size-6 -translate-y-1/2 rounded-md border border-border/50" />
53 <Skeleton className="absolute right-0 top-1/2 size-6 -translate-y-1/2 rounded-md border border-border/50" />
54 <div className="flex gap-1 overflow-hidden px-8 py-0.5">
55 <Skeleton className="h-6 w-16 shrink-0 rounded-md" />
56 <Skeleton className="h-6 w-24 shrink-0 rounded-md" />
57 <Skeleton className="h-6 w-24 shrink-0 rounded-md max-sm:hidden" />
58 </div>
59 </div>
60 <div className="flex shrink-0 gap-1">
61 <Skeleton className="size-7 rounded-md" />
62 <Skeleton className="size-7 rounded-md" />
63 </div>
64 </>
65 );
67​
68export function DiffPanelLoadingState(props: { label: string }) {
69 return (
70 <div className="flex min-h-0 flex-1 flex-col p-2">
71 <div
72 className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-md border border-border/60 bg-card/25"
73 role="status"
74 aria-live="polite"
75 aria-label={props.label}
76 >
77 <div className="flex items-center gap-2 border-b border-border/50 px-3 py-2">
78 <Skeleton className="h-4 w-32 rounded-full" />
79 <Skeleton className="ml-auto h-4 w-20 rounded-full" />
80 </div>
81 <div className="flex min-h-0 flex-1 flex-col gap-4 px-3 py-4">
82 <div className="space-y-2">
83 <Skeleton className="h-3 w-full rounded-full" />
84 <Skeleton className="h-3 w-full rounded-full" />
85 <Skeleton className="h-3 w-10/12 rounded-full" />
86 <Skeleton className="h-3 w-11/12 rounded-full" />
87 <Skeleton className="h-3 w-9/12 rounded-full" />
88 </div>
89 <span className="sr-only">{props.label}</span>
90 </div>
91 </div>
92 </div>
93 );