Repository navigation
Expand file tree
/
Copy pathTopBar.tsx
More file actions
146 lines (145 loc) · 4.18 KB
/
Copy pathTopBar.tsx
File metadata and controls
146 lines (145 loc) · 4.18 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {
ChevronRight,
FolderOpen,
GitCompareArrows,
GitPullRequest,
PanelLeft,
Search,
Files,
Terminal,
PanelTop,
} from "lucide-react";
import type { DrawerTab } from "../Drawer";
import { shortcutHint } from "../../lib/shortcuts";
/** Project crumb, conversation title and the Comparisons, Changes and
* command palette buttons. */
export function TopBar({
sidebar,
onShowSidebar,
projectPath,
onProject,
title,
comparing,
onComparisons,
changesOpen,
onChanges,
changeCount,
onPalette,
panel,
terminalVisible,
onPanel,
}: {
sidebar: boolean;
onShowSidebar: () => void;
projectPath: string;
onProject: () => void;
title: string;
comparing: boolean;
onComparisons: () => void;
changesOpen: boolean;
onChanges: () => void;
changeCount: number;
onPalette: () => void;
panel?: DrawerTab | null;
terminalVisible?: boolean;
onPanel?: (panel: DrawerTab) => void;
}) {
return (
<header className="top">
{!sidebar && (
<button
type="button"
className="icon-btn"
aria-label="Show sidebar"
title={`Show sidebar (${shortcutHint("B")})`}
onClick={onShowSidebar}
>
<PanelLeft size={18} aria-hidden="true" />
</button>
)}
<button
type="button"
className="project-crumb"
title={projectPath || "Open project"}
onClick={onProject}
>
<FolderOpen size={15} aria-hidden="true" />
<span>{projectPath.split("/").pop() || "Open project"}</span>
</button>
<ChevronRight size={13} className="dim" aria-hidden="true" />
{/* The page's one level-one heading: the open task (or Comparisons). */}
<h1 className="top-title" title={title}>
{comparing ? "Comparisons" : title}
</h1>
<div className="top-right">
{onPanel && (
<nav className="workspace-tools" aria-label="Workspace tools">
{(
[
["files", "Files", Files],
["terminal", "Terminal", Terminal],
["preview", "Preview", PanelTop],
] as const
).map(([id, label, Icon]) => {
const pressed =
id === "terminal"
? (terminalVisible ?? panel === id)
: panel === id;
return (
<button
key={id}
type="button"
className={`top-action ${pressed ? "on" : ""}`}
aria-label={`Show ${label.toLowerCase()}`}
aria-pressed={pressed}
title={
id === "terminal"
? `${label} (${shortcutHint("`")})`
: label
}
onClick={() => onPanel(id)}
>
<Icon size={16} aria-hidden="true" />
<span>{label}</span>
</button>
);
})}
</nav>
)}
<button
type="button"
className={`top-action compare-action ${comparing ? "on" : ""}`}
aria-label="Comparisons"
aria-pressed={comparing}
title="Comparisons in this project"
onClick={onComparisons}
>
<GitCompareArrows size={15} aria-hidden="true" />
<span>Comparisons</span>
</button>
<button
type="button"
className={`top-action ${changesOpen ? "on" : ""}`}
aria-label="Review changes"
aria-pressed={changesOpen}
title={`Review diffs, commit, and open a pull request (${shortcutHint("Shift+B")})`}
onClick={onChanges}
>
<GitPullRequest size={15} aria-hidden="true" />
<span>Changes</span>
{changeCount > 0 && <span className="count">{changeCount}</span>}
</button>
<span className="top-divider" />
<button
type="button"
className="icon-btn"
title={`Command palette (${shortcutHint("K")})`}
aria-label="Command palette"
onClick={onPalette}
>
<Search size={16} aria-hidden="true" />
</button>
</div>
</header>
);
}