Repository navigation
Expand file tree
/
Copy pathSidebarColumns.tsx
More file actions
264 lines (250 loc) · 9.62 KB
/
Copy pathSidebarColumns.tsx
File metadata and controls
264 lines (250 loc) · 9.62 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import { ChevronRightIcon } from "lucide-react";
import type { CSSProperties, ReactNode } from "react";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { splitSidebarModelLabel } from "./SidebarBackgroundWork.logic";
import { sidebarCaretCount } from "./SidebarColumns.logic";
import { useClientSettings } from "../../hooks/useSettings";
import { cn } from "~/lib/utils";
if (import.meta.env.DEV) void import("./ForkSidebarDebug");
/*
* The Codex-style sidebar's shared columns. Every row (section header, project, thread, subagent,
* shell) keeps an 8px start and end padding and a caret slot, so carets and icons line up across
* rows; the trailing columns end flush at the row's end padding.
*/
/** Projects uses the same compact height for top-level threads and their work rows. */
export const PROJECTS_WORK_ROW_HEIGHT = "h-6";
const CARET_SLOT_CLASS = "flex w-4 shrink-0 items-center justify-center";
export function SidebarCaret(props: { readonly open: boolean }) {
return (
<ChevronRightIcon
aria-hidden
className={cn("size-3 transition-transform", props.open && "rotate-90")}
/>
);
}
/**
* The left caret slot. Rows that are themselves the toggle pass `open`; a row that can't collapse,
* or whose toggle is a `SidebarCaretToggle` over it, leaves it empty or puts a small mark there.
*/
export function SidebarCaretSlot(props: {
readonly open?: boolean | undefined;
readonly count?: number | undefined;
readonly className?: string | undefined;
readonly children?: ReactNode;
}) {
const count = sidebarCaretCount(props.count, props.open);
const slot = (
<span
aria-hidden
className={cn(CARET_SLOT_CLASS, "sidebar-caret-slot", props.className)}
data-count={count === undefined ? undefined : ""}
>
{count === undefined ? null : (
<span
className={cn(
"sidebar-caret-count",
props.open !== undefined &&
"group-hover/sidebar-caret:hidden group-focus/sidebar-caret:hidden",
)}
>
{count}
</span>
)}
{props.open === undefined ? (
props.children
) : (
<span
className={cn(
"sidebar-caret-icon",
count !== undefined &&
"hidden group-hover/sidebar-caret:flex group-focus/sidebar-caret:flex",
)}
>
<SidebarCaret open={props.open} />
</span>
)}
</span>
);
return props.count === undefined ? (
slot
) : (
<Tooltip>
<TooltipTrigger render={slot} />
<TooltipPopup side="right">{props.count}</TooltipPopup>
</Tooltip>
);
}
/**
* A caret toggle over a row's empty caret slot, for rows that are buttons themselves (buttons
* cannot nest), so it renders as the row's sibling inside a `relative` parent whose padding box
* starts at the row. `start-0.5` plus `px-1.5` is the row's 8px padding, which widens the hit area.
* `className` places it vertically to match the row's height.
*/
export function SidebarCaretToggle(props: {
readonly open: boolean;
readonly count?: number | undefined;
readonly label: string;
readonly onToggle: () => void;
readonly className: string;
}) {
return (
<button
type="button"
aria-expanded={props.open}
aria-label={props.label}
className={cn(
"sidebar-caret-toggle group/sidebar-caret absolute flex cursor-pointer items-center rounded px-1.5 text-sidebar-muted-foreground/70 hover:bg-sidebar-row-hover hover:text-sidebar-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
props.className,
)}
onClick={props.onToggle}
>
<SidebarCaretSlot open={props.open} count={props.count} />
</button>
);
}
/**
* The right columns, last in the row: a count, then time, then status mark. Each renders only when
* given, and the group sizes to what it holds, so a narrow sidebar leaves the title its room and a
* header row reserves nothing it doesn't show.
*/
export function SidebarTrailingColumns(props: {
readonly count?: number | undefined;
readonly time?: ReactNode;
readonly status?: ReactNode;
}) {
if (props.count === undefined && !props.time && !props.status) return null;
return (
<span className="ms-auto flex shrink-0 items-center gap-2 whitespace-nowrap text-2xs font-normal tabular-nums">
{props.count === undefined ? null : (
<span className="text-sidebar-muted-foreground/55">{props.count}</span>
)}
{props.time ? <span className="text-muted-foreground">{props.time}</span> : null}
{props.status ? <span className="flex w-3.5 justify-center">{props.status}</span> : null}
</span>
);
}
/**
* All thread surfaces share these fixed tracks; the spacer gets spare width. Rows never indent,
* so every column lines up at every depth; in Projects a group tint connects a thread's lineage.
*/
export function SidebarThreadColumns(props: {
readonly caret?: ReactNode;
readonly location?: ReactNode;
readonly role?: ReactNode;
readonly provider?: ReactNode;
/** The short model label; its name and version fill two aligned tracks. */
readonly model?: string | undefined;
readonly effort?: ReactNode;
readonly name: ReactNode;
/** The row has no model or effort, so its name starts in the model's column. */
readonly wideName?: boolean | undefined;
readonly issue?: ReactNode;
readonly pr?: ReactNode;
readonly trailingClassName?: string | undefined;
readonly time?: ReactNode;
readonly status?: ReactNode;
}) {
const columns = useClientSettings((settings) => ({
roleDisplay: settings.sidebarRoleDisplay,
location: !settings.codexStyleSidebar || settings.sidebarShowLocation,
role: settings.sidebarRoleDisplay === "icon",
provider: !settings.codexStyleSidebar || settings.sidebarShowProvider,
model: !settings.codexStyleSidebar || settings.sidebarShowModel,
version: !settings.codexStyleSidebar || settings.sidebarShowModel,
effort: !settings.codexStyleSidebar || settings.sidebarShowEffort,
issue: !settings.codexStyleSidebar || settings.sidebarShowIssueBadge,
pr: !settings.codexStyleSidebar || settings.sidebarShowPullRequestBadge,
}));
const style = Object.fromEntries(
Object.entries(columns).flatMap(([column, visible]) =>
visible === false
? [
[`--sidebar-${column}-track`, "0px"],
[`--sidebar-${column}-gap`, "0px"],
]
: [],
),
) as CSSProperties;
return (
<span
className="sidebar-thread-columns"
data-sidebar-role-display={columns.roleDisplay}
style={style}
>
<span className="sidebar-thread-caret">{props.caret ?? <SidebarCaretSlot />}</span>
{columns.location !== false ? (
<span className="sidebar-thread-icon sidebar-thread-location">{props.location}</span>
) : null}
{columns.role !== false ? (
<span className="sidebar-thread-icon sidebar-thread-role">{props.role}</span>
) : null}
{columns.provider !== false ? (
<span className="sidebar-thread-icon sidebar-thread-provider">{props.provider}</span>
) : null}
{columns.model !== false && !props.wideName ? (
<SidebarThreadModel label={props.model} />
) : null}
{columns.effort !== false && !props.wideName ? (
<span className="sidebar-thread-effort">{props.effort}</span>
) : null}
<span className={cn("sidebar-thread-name", props.wideName && "sidebar-thread-name-wide")}>
{props.name}
</span>
{columns.issue !== false ? (
<span className={cn("sidebar-thread-badge sidebar-thread-issue", props.trailingClassName)}>
{props.issue}
</span>
) : null}
{columns.pr !== false ? (
<span className={cn("sidebar-thread-badge sidebar-thread-pr", props.trailingClassName)}>
{props.pr}
</span>
) : null}
<span className={cn("sidebar-thread-time", props.trailingClassName)}>{props.time}</span>
<span className={cn("sidebar-thread-icon sidebar-thread-work", props.trailingClassName)}>
{props.status}
</span>
</span>
);
}
// oklch hue angles that read in light and dark themes as low-alpha row tints.
const THREAD_GROUP_HUES = [250, 300, 160, 70, 20, 195] as const;
/** The hue a thread group tints its rows with, fixed by its top-level thread's id. */
export function threadGroupHue(rootThreadId: string): number {
let hash = 0;
for (let index = 0; index < rootThreadId.length; index++) {
hash = (hash * 31 + rootThreadId.charCodeAt(index)) | 0;
}
return THREAD_GROUP_HUES[Math.abs(hash) % THREAD_GROUP_HUES.length]!;
}
/** A row's title (see `sidebarThreadTitle`) with the thread's own name on hover. */
export function sidebarThreadName(name: string, title: string): ReactNode {
if (title === name) return name;
return (
<Tooltip>
<TooltipTrigger render={<span className="block truncate" />}>{title}</TooltipTrigger>
<TooltipPopup side="top">{name}</TooltipPopup>
</Tooltip>
);
}
/** The model's name and version cells, with the whole label on the name's hover. */
function SidebarThreadModel(props: { readonly label: string | undefined }) {
if (!props.label) {
return (
<>
<span className="sidebar-thread-model" />
<span className="sidebar-thread-version" />
</>
);
}
const { name, version } = splitSidebarModelLabel(props.label);
return (
<>
<Tooltip>
<TooltipTrigger render={<span className="sidebar-thread-model" />}>{name}</TooltipTrigger>
<TooltipPopup side="top">{props.label}</TooltipPopup>
</Tooltip>
<span className="sidebar-thread-version">{version}</span>
</>
);
}