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

DiffPanelShell.tsx

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