-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathfireHeader.tsx
More file actions
84 lines (80 loc) · 2.81 KB
/
Copy pathfireHeader.tsx
File metadata and controls
84 lines (80 loc) · 2.81 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
import { Repository } from "@/lib/types";
import { getRepoCodeHostInfo } from "@/lib/utils";
import { LaptopIcon } from "@radix-ui/react-icons";
import clsx from "clsx";
import Image from "next/image";
import Link from "next/link";
interface FileHeaderProps {
repo?: Repository;
fileName: string;
fileNameHighlightRange?: {
from: number;
to: number;
}
branchDisplayName?: string;
branchDisplayTitle?: string;
}
export const FileHeader = ({
repo,
fileName,
fileNameHighlightRange,
branchDisplayName,
branchDisplayTitle,
}: FileHeaderProps) => {
const info = getRepoCodeHostInfo(repo);
return (
<div className="flex flex-row gap-2 items-center w-full overflow-hidden">
{info?.icon ? (
<Image
src={info.icon}
alt={info.codeHostName}
className={`w-4 h-4 ${info.iconClassName}`}
/>
): (
<LaptopIcon className="w-4 h-4" />
)}
<Link
className={clsx("font-medium", {
"cursor-pointer hover:underline": info?.repoLink,
})}
href={info?.repoLink ?? ""}
>
{info?.displayName}
</Link>
{branchDisplayName && (
<p
className="text-xs font-semibold text-gray-500 dark:text-gray-400 mt-0.5 flex items-center gap-0.5"
title={branchDisplayTitle}
>
{/* hack since to make the @ symbol look more centered with the text */}
<span
style={{
fontSize: "0.60rem",
lineHeight: "1rem",
marginBottom: "0.1rem",
}}
>
@
</span>
{`${branchDisplayName}`}
</p>
)}
<span>·</span>
<div className="flex-1 flex items-center overflow-hidden">
<span className="inline-block w-full truncate-start font-mono text-sm">
{!fileNameHighlightRange ?
fileName
: (
<>
{fileName.slice(0, fileNameHighlightRange.from)}
<span className="bg-yellow-200 dark:bg-blue-700">
{fileName.slice(fileNameHighlightRange.from, fileNameHighlightRange.to)}
</span>
{fileName.slice(fileNameHighlightRange.to)}
</>
)}
</span>
</div>
</div>
)
}