Repository navigation
Expand file tree
/
Copy pathDiffPanelShell.tsx
More file actions
116 lines (107 loc) · 3.7 KB
/
Copy pathDiffPanelShell.tsx
File metadata and controls
116 lines (107 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import type { ReactNode } from "react";
import { isElectron } from "~/env";
import { cn } from "~/lib/utils";
import { Skeleton } from "./ui/skeleton";
export type DiffPanelMode = "inline" | "sheet" | "sidebar" | "embedded";
function getDiffPanelHeaderRowClassName(mode: DiffPanelMode) {
const shouldUseDragRegion = isElectron && mode !== "sheet" && mode !== "embedded";
return cn(
"flex items-center justify-between gap-2",
mode === "embedded" ? "px-2" : "px-4",
shouldUseDragRegion
? "drag-region h-[var(--workspace-topbar-height)] border-b border-border wco:pr-(--workspace-native-controls-inset)"
: "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",
);
}
export function DiffPanelShell(props: {
mode: DiffPanelMode;
header: ReactNode;
children: ReactNode;
}) {
const shouldUseDragRegion = isElectron && props.mode !== "sheet" && props.mode !== "embedded";
return (
<div
className={cn(
"flex h-full min-w-0 flex-col bg-background",
props.mode === "inline"
? "w-[42vw] min-w-[360px] max-w-[560px] shrink-0 border-l border-border"
: "w-full",
)}
>
{shouldUseDragRegion ? (
<div className={getDiffPanelHeaderRowClassName(props.mode)}>{props.header}</div>
) : (
<div className={getDiffPanelHeaderRowClassName(props.mode)} data-surface-subheader>
{props.header}
</div>
)}
{props.children}
</div>
);
}
export function DiffFileHeaderSkeleton({
titleWidth,
}: {
titleWidth: "short" | "medium" | "long";
}) {
return (
<div className="flex h-8 items-center gap-2 px-2 pr-3">
<div className="flex size-5 shrink-0 items-center justify-center">
<Skeleton className="size-2.5" />
</div>
<Skeleton className="size-5 shrink-0" />
<Skeleton
shape="pill"
className={
titleWidth === "short"
? "h-3 w-2/5 max-w-52"
: titleWidth === "medium"
? "h-3 w-1/2 max-w-64"
: "h-3 w-3/5 max-w-72"
}
/>
<div className="ml-auto flex shrink-0 items-center gap-2">
<Skeleton shape="pill" className="h-3 w-5" />
<Skeleton shape="pill" className="h-3 w-5" />
</div>
</div>
);
}
function DiffCodeLineSkeleton({ width }: { width: "short" | "medium" | "long" }) {
return (
<div className="flex items-center gap-3">
<Skeleton shape="pill" className="h-2.5 w-5 shrink-0" />
<Skeleton
shape="pill"
className={
width === "short" ? "h-2.5 w-3/5" : width === "medium" ? "h-2.5 w-2/3" : "h-2.5 w-4/5"
}
/>
</div>
);
}
export function DiffPanelLoadingState(props: { label: string }) {
return (
<div
className="min-h-0 flex-1 overflow-hidden bg-background"
role="status"
aria-live="polite"
aria-label={props.label}
>
<DiffFileHeaderSkeleton titleWidth="medium" />
<div className="flex h-6 items-center gap-2 px-2 pr-3">
<div className="h-px flex-1 bg-border/40" />
<Skeleton shape="pill" className="h-2.5 w-24" />
<div className="h-px flex-1 bg-border/40" />
</div>
<div className="space-y-2 px-3 py-2">
<DiffCodeLineSkeleton width="medium" />
<DiffCodeLineSkeleton width="long" />
<DiffCodeLineSkeleton width="short" />
</div>
<DiffFileHeaderSkeleton titleWidth="short" />
<DiffFileHeaderSkeleton titleWidth="long" />
<span className="sr-only">{props.label}</span>
</div>
);
}