Skip to content

Commit d0a50e0

Browse files
authored
Compare: align action chips and give them breathing room (#164)
Several inline action chips landed flush against their neighbouring text — "Metric Switch", "Waterfall ", "HAR1 Upload", and the disclosure arrows on rows like "CPU time spent by category" — so visually it read as one crowded blob rather than a label with a separate action you could aim at. The page-x-ray metric column also had the awkward case where "Switch" stayed on the title line and "Only differences" wrapped underneath at a different left edge, which looked broken. Card titles become flex containers so inline chips sit at a consistent gap and centre-align with the heading instead of hugging its baseline. The chip-toggle, submit-smaller and Upload label each pick up a small left margin so they're never flush against preceding content, reset inside flex parents where gap does the work. The metric column header now stacks "Metric" on top of a flex row that holds Switch + Only differences together, so the chips wrap as a group and stay aligned with each other. A small negative left margin on that row pulls the buttons left by the width of their own border + padding so the visible text edge of "Switch" lines up with "URL"/"Date"/"Browser" in the rows below. Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com
1 parent ff67055 commit d0a50e0

4 files changed

Lines changed: 67 additions & 10 deletions

File tree

public/js/compare/templates.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,19 @@ function pageXrayTemplate(d) {
128128
html += '<caption class="sr-only">Page X-ray comparison: ' +
129129
h(config.har1.label) + ' versus ' + h(config.har2.label) + '</caption>';
130130
html += '<thead><tr>';
131-
html += '<th class="tabletext tableXrayMetric" scope="col">Metric ' +
132-
'<button onclick="regenerate(true);" class="submit submit-smaller" ' +
133-
'aria-label="Swap HAR1 and HAR2">Switch</button> ' +
134-
'<button id="diffOnlyToggle" type="button" ' +
135-
'onclick="toggleDiffOnly(this);" ' +
136-
'class="chip-toggle" ' +
137-
'aria-pressed="' + diffOnlyPressed + '">' +
138-
'Only differences</button></th>';
131+
html += '<th class="tabletext tableXrayMetric" scope="col">' +
132+
'<div class="tableXrayMetric-stack">' +
133+
'<span class="tableXrayMetric-label">Metric</span>' +
134+
'<span class="tableXrayMetric-actions">' +
135+
'<button onclick="regenerate(true);" class="submit submit-smaller" ' +
136+
'aria-label="Swap HAR1 and HAR2">Switch</button>' +
137+
'<button id="diffOnlyToggle" type="button" ' +
138+
'onclick="toggleDiffOnly(this);" ' +
139+
'class="chip-toggle" ' +
140+
'aria-pressed="' + diffOnlyPressed + '">' +
141+
'Only differences</button>' +
142+
'</span>' +
143+
'</div></th>';
139144
html += '<th class="tableXrayHarMetric" scope="col">' + h(config.har1.label) +
140145
'<input type="file" id="har1upload" class="inputfile"/>' +
141146
'<label for="har1upload">Upload</label></th>';

src/css/buttons.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
align-items: center;
5555
gap: 4px;
5656
padding: 2px 8px;
57-
margin: 0;
57+
/* Small left margin so the button doesn't sit flush against the
58+
preceding label text (e.g. "Metric Switch", "CPU time spent by
59+
category [arrow]"). Doesn't apply inside flex parents thanks to
60+
`gap` taking over there. */
61+
margin: 0 0 0 8px;
5862
font-size: 0.8rem;
5963
font-weight: var(--font-weight-medium);
6064
vertical-align: middle;

src/css/elements.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ hr {
200200
}
201201

202202
.card-title {
203+
/* Flex container so inline action chips (e.g. "Side by side" on
204+
the Waterfall card) sit at a sensible distance from the title
205+
text and align vertically to the middle — not the baseline of
206+
a smaller chip against a larger h3. */
207+
display: flex;
208+
align-items: center;
209+
flex-wrap: wrap;
210+
gap: 14px;
203211
margin: 0 0 12px 0;
204212
font-size: 1.125rem;
205213
font-weight: var(--font-weight-semibold);

src/css/page-xray.css

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@
6565
}
6666

6767
.tableXrayMetric { width: 22%; text-align: left; }
68+
69+
/*
70+
* Metric column header — "Metric" label sits on top of a row of
71+
* action chips (Switch + Only differences). Stacking with flex
72+
* keeps the chips aligned consistently with each other and with the
73+
* column's left edge (which is where the row labels below sit),
74+
* instead of relying on inline-wrap and ending up indented.
75+
*/
76+
.tableXrayMetric-stack {
77+
display: flex;
78+
flex-direction: column;
79+
align-items: flex-start;
80+
gap: 6px;
81+
}
82+
.tableXrayMetric-actions {
83+
display: flex;
84+
flex-wrap: wrap;
85+
align-items: center;
86+
gap: 8px;
87+
/* Negative margin so the button's visible text edge lines up with
88+
the metric labels below ("URL", "Date", …) — the button's own
89+
border + padding would otherwise indent the text by ~9px. */
90+
margin-left: -9px;
91+
}
92+
.tableXrayMetric-actions .chip-toggle,
93+
.tableXrayMetric-actions .submit-smaller {
94+
/* `gap` handles spacing — strip the default left margins. */
95+
margin-left: 0;
96+
}
6897
.tableXrayHarMetric,
6998
.tableXrayHar2Metric { width: 31%; }
7099
.tableXrayDiff { width: 16%; text-align: right; padding-right: 12px; color: var(--color-text-muted); font-weight: var(--font-weight-medium); }
@@ -101,7 +130,11 @@
101130
display: inline-flex;
102131
align-items: center;
103132
padding: 4px 10px;
104-
margin-left: 4px;
133+
/* Visually separate from any preceding button or text. Reset to 0
134+
inside a flex parent (e.g. .card-title) where `gap` already
135+
handles the spacing. */
136+
margin-left: 12px;
137+
vertical-align: middle;
105138
background: var(--color-surface);
106139
color: var(--color-text-secondary);
107140
border: 1px solid var(--color-border);
@@ -112,6 +145,9 @@
112145
transition: background var(--motion-fast), color var(--motion-fast),
113146
border-color var(--motion-fast);
114147
}
148+
.card-title > .chip-toggle {
149+
margin-left: 0;
150+
}
115151
.chip-toggle:hover,
116152
.chip-toggle:focus-visible {
117153
background: var(--color-blue-tint);
@@ -213,6 +249,10 @@
213249
display: inline-flex;
214250
align-items: center;
215251
padding: 6px 14px;
252+
/* Keep the chip away from the HAR1 / HAR2 column label text it
253+
sits next to. */
254+
margin-left: 10px;
255+
vertical-align: middle;
216256
background: var(--color-surface);
217257
color: var(--color-text-secondary);
218258
border: 1px solid var(--color-border);

0 commit comments

Comments
 (0)