Skip to content

Commit de2a236

Browse files
playcationshannesrudolph
authored andcommitted
Switched to tailwind for FilesChangedOverview
- Reduced from 21 to 4 inline styles (only dynamic ones remain) - Converted static styles to Tailwind CSS classes: - Container styles: border, px-2.5, py-1.5, m-0, etc. - Flexbox layouts: flex, justify-between, items-center, gap-2 - Button styles: Consistent classes for primary/secondary/icon buttons - Text styles: font-mono, text-xs, font-medium, etc. - Preserved dynamic styles for runtime calculations: - Virtualization: height, transform - State-based: opacity, borderBottom - Updated tests to check for CSS classes instead of inline styles
1 parent bb2ae8d commit de2a236

File tree

2 files changed

+29
-141
lines changed

2 files changed

+29
-141
lines changed

webview-ui/src/components/file-changes/FilesChangedOverview.tsx

Lines changed: 21 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const FilesChangedOverview: React.FC = () => {
140140
setChangeset(null)
141141
}
142142
break
143-
case "checkpoint_created":
143+
case "checkpointCreated":
144144
handleCheckpointCreated(message.checkpoint, message.previousCheckpoint)
145145
break
146146
case "checkpointRestored":
@@ -206,28 +206,13 @@ const FilesChangedOverview: React.FC = () => {
206206

207207
return (
208208
<div
209-
className="files-changed-overview"
210-
data-testid="files-changed-overview"
211-
style={{
212-
border: "1px solid var(--vscode-panel-border)",
213-
borderTop: 0,
214-
borderRadius: 0,
215-
padding: "6px 10px",
216-
margin: 0,
217-
backgroundColor: "var(--vscode-editor-background)",
218-
}}>
209+
className="files-changed-overview border border-[var(--vscode-panel-border)] border-t-0 rounded-none px-2.5 py-1.5 m-0 bg-[var(--vscode-editor-background)]"
210+
data-testid="files-changed-overview">
219211
{/* Collapsible header */}
220212
<div
213+
className="flex justify-between items-center mt-0 cursor-pointer select-none"
221214
style={{
222-
display: "flex",
223-
justifyContent: "space-between",
224-
alignItems: "center",
225-
marginTop: "0 2px",
226-
//marginBottom: isCollapsed ? "0" : "6px",
227215
borderBottom: isCollapsed ? "none" : "1px solid var(--vscode-panel-border)",
228-
// paddingBottom: "0px",
229-
cursor: "pointer",
230-
userSelect: "none",
231216
}}
232217
onClick={() => setIsCollapsed(!isCollapsed)}
233218
onKeyDown={(e) => {
@@ -246,15 +231,11 @@ const FilesChangedOverview: React.FC = () => {
246231
: t("file-changes:accessibility.expanded"),
247232
})}
248233
title={isCollapsed ? t("file-changes:header.expand") : t("file-changes:header.collapse")}>
249-
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
234+
<div className="flex items-center gap-2">
250235
<span
251-
className={`codicon ${isCollapsed ? "codicon-chevron-right" : "codicon-chevron-down"}`}
252-
style={{
253-
fontSize: "12px",
254-
transition: "transform 0.2s ease",
255-
}}
236+
className={`codicon text-xs transition-transform duration-200 ease-out ${isCollapsed ? "codicon-chevron-right" : "codicon-chevron-down"}`}
256237
/>
257-
<h3 style={{ margin: 0, fontSize: "14px", fontWeight: "bold" }} data-testid="files-changed-header">
238+
<h3 className="m-0 text-sm font-bold" data-testid="files-changed-header">
258239
{t("file-changes:summary.count_with_changes", {
259240
count: files.length,
260241
changes: totalChanges,
@@ -264,24 +245,15 @@ const FilesChangedOverview: React.FC = () => {
264245

265246
{/* Action buttons always visible for quick access */}
266247
<div
267-
style={{ display: "flex", gap: "8px" }}
248+
className="flex gap-2"
268249
onClick={(e) => e.stopPropagation()} // Prevent collapse toggle when clicking buttons
269250
>
270251
<button
271252
onClick={() => handleWithDebounce(handleRejectAll)}
272253
disabled={isProcessing}
273254
tabIndex={0}
274255
data-testid="reject-all-button"
275-
style={{
276-
backgroundColor: "var(--vscode-button-secondaryBackground)",
277-
color: "var(--vscode-button-secondaryForeground)",
278-
border: "none",
279-
borderRadius: "3px",
280-
padding: "4px 8px",
281-
fontSize: "13px",
282-
cursor: isProcessing ? "not-allowed" : "pointer",
283-
opacity: isProcessing ? 0.6 : 1,
284-
}}
256+
className="bg-[var(--vscode-button-secondaryBackground)] text-[var(--vscode-button-secondaryForeground)] border-none rounded px-2 py-1 text-xs disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer"
285257
title={t("file-changes:actions.reject_all")}>
286258
{t("file-changes:actions.reject_all")}
287259
</button>
@@ -290,16 +262,7 @@ const FilesChangedOverview: React.FC = () => {
290262
disabled={isProcessing}
291263
tabIndex={0}
292264
data-testid="accept-all-button"
293-
style={{
294-
backgroundColor: "var(--vscode-button-background)",
295-
color: "var(--vscode-button-foreground)",
296-
border: "none",
297-
borderRadius: "3px",
298-
padding: "4px 8px",
299-
fontSize: "13px",
300-
cursor: isProcessing ? "not-allowed" : "pointer",
301-
opacity: isProcessing ? 0.6 : 1,
302-
}}
265+
className="bg-[var(--vscode-button-background)] text-[var(--vscode-button-foreground)] border-none rounded px-2 py-1 text-xs disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer"
303266
title={t("file-changes:actions.accept_all")}>
304267
{t("file-changes:actions.accept_all")}
305268
</button>
@@ -309,13 +272,9 @@ const FilesChangedOverview: React.FC = () => {
309272
{/* Collapsible content area */}
310273
{!isCollapsed && (
311274
<div
275+
className="max-h-[300px] overflow-y-auto transition-opacity duration-200 ease-in-out relative pt-2"
312276
style={{
313-
maxHeight: "300px",
314-
overflowY: "auto",
315-
transition: "opacity 0.2s ease-in-out",
316277
opacity: isCollapsed ? 0 : 1,
317-
position: "relative",
318-
paddingTop: "8px",
319278
}}
320279
onScroll={handleScroll}>
321280
{shouldVirtualize && (
@@ -388,104 +347,43 @@ const FileItem: React.FC<FileItemProps> = React.memo(
388347
({ file, formatLineChanges, onViewDiff, onAcceptFile, onRejectFile, handleWithDebounce, isProcessing, t }) => (
389348
<div
390349
data-testid={`file-item-${file.uri}`}
391-
style={{
392-
display: "flex",
393-
justifyContent: "space-between",
394-
alignItems: "center",
395-
padding: "6px 8px",
396-
marginBottom: "3px",
397-
backgroundColor: "var(--vscode-list-hoverBackground)",
398-
borderRadius: "3px",
399-
fontSize: "13px",
400-
minHeight: "32px", // Thinner rows
401-
lineHeight: "1.3",
402-
}}>
403-
<div style={{ flex: 1, minWidth: 0 }}>
404-
<div
405-
style={{
406-
fontFamily: "var(--vscode-editor-font-family)",
407-
fontSize: "13px",
408-
color: "var(--vscode-editor-foreground)",
409-
overflow: "hidden",
410-
textOverflow: "ellipsis",
411-
whiteSpace: "nowrap",
412-
fontWeight: 500,
413-
}}>
350+
className="flex justify-between items-center px-2 py-1.5 mb-1 bg-[var(--vscode-list-hoverBackground)] rounded text-xs min-h-[32px] leading-tight">
351+
<div className="flex-1 min-w-0">
352+
<div className="font-mono text-xs text-[var(--vscode-editor-foreground)] overflow-hidden text-ellipsis whitespace-nowrap font-medium">
414353
{file.uri}
415354
</div>
416-
<div
417-
style={{
418-
fontSize: "11px",
419-
color: "var(--vscode-descriptionForeground)",
420-
marginTop: "2px",
421-
}}>
355+
<div className="text-[11px] text-[var(--vscode-descriptionForeground)] mt-0.5">
422356
{t(`file-changes:file_types.${file.type}`)}
423357
</div>
424358
</div>
425359

426-
<div style={{ display: "flex", alignItems: "center", gap: "8px", marginLeft: "8px" }}>
427-
<div
428-
style={{
429-
fontSize: "12px",
430-
color: "var(--vscode-descriptionForeground)",
431-
whiteSpace: "nowrap",
432-
flexShrink: 0,
433-
}}>
360+
<div className="flex items-center gap-2 ml-2">
361+
<div className="text-xs text-[var(--vscode-descriptionForeground)] whitespace-nowrap flex-shrink-0">
434362
{formatLineChanges(file)}
435363
</div>
436-
<div style={{ display: "flex", gap: "4px" }}>
364+
<div className="flex gap-1">
437365
<button
438366
onClick={() => handleWithDebounce(() => onViewDiff(file.uri))}
439367
disabled={isProcessing}
440368
title={t("file-changes:actions.view_diff")}
441369
data-testid={`diff-${file.uri}`}
442-
style={{
443-
backgroundColor: "transparent",
444-
color: "var(--vscode-button-foreground)",
445-
border: "1px solid var(--vscode-button-border)",
446-
borderRadius: "3px",
447-
padding: "2px 6px",
448-
fontSize: "11px",
449-
cursor: isProcessing ? "not-allowed" : "pointer",
450-
minWidth: "50px",
451-
opacity: isProcessing ? 0.6 : 1,
452-
}}>
370+
className="bg-transparent text-[var(--vscode-button-foreground)] border border-[var(--vscode-button-border)] rounded px-1.5 py-0.5 text-[11px] min-w-[50px] disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer">
453371
{t("file-changes:actions.view_diff")}
454372
</button>
455373
<button
456374
onClick={() => handleWithDebounce(() => onRejectFile(file.uri))}
457375
disabled={isProcessing}
458376
title={t("file-changes:actions.reject_file")}
459377
data-testid={`reject-${file.uri}`}
460-
style={{
461-
backgroundColor: "var(--vscode-button-secondaryBackground)",
462-
color: "var(--vscode-button-secondaryForeground)",
463-
border: "1px solid var(--vscode-button-border)",
464-
borderRadius: "3px",
465-
padding: "2px 6px",
466-
fontSize: "11px",
467-
cursor: isProcessing ? "not-allowed" : "pointer",
468-
minWidth: "20px",
469-
opacity: isProcessing ? 0.6 : 1,
470-
}}>
378+
className="bg-[var(--vscode-button-secondaryBackground)] text-[var(--vscode-button-secondaryForeground)] border border-[var(--vscode-button-border)] rounded px-1.5 py-0.5 text-[11px] min-w-[20px] disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer">
471379
472380
</button>
473381
<button
474382
onClick={() => handleWithDebounce(() => onAcceptFile(file.uri))}
475383
disabled={isProcessing}
476384
title={t("file-changes:actions.accept_file")}
477385
data-testid={`accept-${file.uri}`}
478-
style={{
479-
backgroundColor: "var(--vscode-button-background)",
480-
color: "var(--vscode-button-foreground)",
481-
border: "1px solid var(--vscode-button-border)",
482-
borderRadius: "3px",
483-
padding: "2px 6px",
484-
fontSize: "11px",
485-
cursor: isProcessing ? "not-allowed" : "pointer",
486-
minWidth: "20px",
487-
opacity: isProcessing ? 0.6 : 1,
488-
}}>
386+
className="bg-[var(--vscode-button-background)] text-[var(--vscode-button-foreground)] border border-[var(--vscode-button-border)] rounded px-1.5 py-0.5 text-[11px] min-w-[20px] disabled:opacity-60 disabled:cursor-not-allowed cursor-pointer">
489387
490388
</button>
491389
</div>

webview-ui/src/components/file-changes/__tests__/FilesChangedOverview.spec.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,14 +1181,10 @@ describe("FilesChangedOverview (Self-Managing)", () => {
11811181

11821182
const fcoContainer = screen.getByTestId("files-changed-overview")
11831183

1184-
// FCO should have proper styling that doesn't interfere with other floating elements
1185-
expect(fcoContainer).toHaveStyle({
1186-
border: "1px solid var(--vscode-panel-border)",
1187-
borderRadius: "0",
1188-
padding: "6px 10px",
1189-
margin: "0",
1190-
backgroundColor: "var(--vscode-editor-background)",
1191-
})
1184+
// FCO should have proper styling classes that don't interfere with other floating elements
1185+
expect(fcoContainer).toHaveClass("border", "border-[var(--vscode-panel-border)]")
1186+
expect(fcoContainer).toHaveClass("rounded-none", "px-2.5", "py-1.5", "m-0")
1187+
expect(fcoContainer).toHaveClass("bg-[var(--vscode-editor-background)]")
11921188

11931189
// FCO should not have high z-index values that could cause layering issues
11941190
// In test environment, z-index might be empty string instead of "auto"
@@ -1277,9 +1273,7 @@ describe("FilesChangedOverview (Self-Managing)", () => {
12771273
const fcoContainer = screen.getByTestId("files-changed-overview")
12781274

12791275
// FCO should have consistent margins that don't cause layout jumps
1280-
expect(fcoContainer).toHaveStyle({
1281-
margin: "0",
1282-
})
1276+
expect(fcoContainer).toHaveClass("m-0")
12831277

12841278
// Remove files to test clean disappearance
12851279
simulateMessage({
@@ -1297,10 +1291,8 @@ describe("FilesChangedOverview (Self-Managing)", () => {
12971291

12981292
const fcoContainer = screen.getByTestId("files-changed-overview")
12991293

1300-
// Container should have proper padding
1301-
expect(fcoContainer).toHaveStyle({
1302-
padding: "6px 10px",
1303-
})
1294+
// Container should have proper padding classes
1295+
expect(fcoContainer).toHaveClass("px-2.5", "py-1.5")
13041296

13051297
// Expand to check internal spacing
13061298
const header = screen.getByTestId("files-changed-header")
@@ -1315,9 +1307,7 @@ describe("FilesChangedOverview (Self-Managing)", () => {
13151307
const fileItems = screen.getAllByTestId(/^file-item-/)
13161308
fileItems.forEach((item) => {
13171309
// Each file item should have margin bottom for spacing
1318-
expect(item).toHaveStyle({
1319-
marginBottom: "3px",
1320-
})
1310+
expect(item).toHaveClass("mb-1")
13211311
})
13221312
})
13231313
})

0 commit comments

Comments
 (0)