Skip to content

Commit 637f1dc

Browse files
authored
ui: Tweak form & segmented button styles (#4045)
A few improvements to forms and segmented buttons: - Modern segmented button styling - Add FormGrid widget which can be used to lay out sections of forms in a grid rather than stacked - Improve 'AddDebugTrackMenu' styling - Tweak some demo code <img width="368" height="393" alt="image" src="https://github.com/user-attachments/assets/245c5c6d-3388-4e9c-aa07-827851449677" />
1 parent 08919e3 commit 637f1dc

File tree

22 files changed

+263
-155
lines changed

22 files changed

+263
-155
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
92bd72fe856b6a512c6a6e68cc2b2d2a07cb4e68068eb99a8091829928dbb69d
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7494fcad7d86147c741dcb75269f98a50958e401741b8b8f0a3cc5e1b6144505
1+
c00796f5102e3cff6b276566e08537ef0d7e2547ab81640006c1f3f913542f41
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7494fcad7d86147c741dcb75269f98a50958e401741b8b8f0a3cc5e1b6144505
1+
c00796f5102e3cff6b276566e08537ef0d7e2547ab81640006c1f3f913542f41
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0d9afac02bcd1fa7b3cb3f2ac15b4c937102ee1e99fa49427d886c2775e78d01
1+
498514b7dcc6357196f710917117550a385eb8538913e52a1525a10b659961bb
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bf4f8037c1d7a5d3c523d8978f5be79a4366ddc4b83b53fe9cc5bb41ef4b5ec8
1+
bb3cf2112d4e1cc339c93a3af090c21b39bc994a9de94df24b0229b1672274f3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
344728f1ae223a48ba6b9ba463fa3fdbd2017a7cdf7bf4ed3ee4e9a89bda75f3
1+
54820411fa0a671c6d48cd8eaebe80922e24160678fb46020dc59fe71e8bb5b3

ui/src/assets/widgets/flamegraph.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
.loading-container {
2020
font-size: larger;
2121
display: flex;
22-
align-items: center;
22+
align-items: baseline;
2323
justify-content: center;
2424
height: 100%;
2525
}
2626

2727
.filter-bar {
2828
margin: 6px 8px;
2929
display: flex;
30-
gap: 6px;
31-
align-items: center;
30+
column-gap: 6px;
31+
align-items: baseline;
32+
33+
.pf-tag-input {
34+
flex-grow: 1;
35+
}
3236

3337
.pf-select {
3438
flex-shrink: 0;
@@ -65,6 +69,7 @@
6569
background: var(--pf-color-border);
6670
flex-shrink: 0;
6771
margin: 0 4px;
72+
align-self: center;
6873
}
6974

7075
.pf-flamegraph-filter-label {

ui/src/assets/widgets/form.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,26 @@
3232
font-weight: 500;
3333
}
3434

35+
&__row {
36+
display: grid;
37+
gap: 8px 16px;
38+
}
39+
40+
&__grid {
41+
display: grid;
42+
grid-template-columns: auto 1fr;
43+
gap: 0 8px;
44+
align-items: baseline;
45+
}
46+
3547
&__section {
3648
border: 1px solid var(--pf-color-border);
3749
display: flex;
3850
flex-direction: column;
3951
border-radius: 4px;
4052
padding: 8px;
41-
margin-block: 8px;
53+
margin: 0; // Reset default fieldset margin
54+
margin-bottom: 8px;
4255

4356
&-label {
4457
font-weight: 500;
@@ -51,8 +64,9 @@
5164

5265
// Styles for common input elements
5366
.pf-checkbox,
54-
.pf-switch {
55-
margin-bottom: 6px;
67+
.pf-switch,
68+
.pf-segmented-buttons {
69+
margin-bottom: 10px;
5670
}
5771

5872
.pf-select,

ui/src/assets/widgets/segmented_buttons.scss

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,40 @@
1717
.pf-segmented-buttons {
1818
display: inline-flex;
1919
flex-direction: row;
20+
align-items: baseline;
21+
gap: 2px;
22+
padding: 2px;
23+
border-radius: $border-radius-large;
24+
background: color-mix(
25+
in srgb,
26+
transparent,
27+
var(--pf-color-interactive-base) 10%
28+
);
29+
30+
&--fill-width {
31+
display: flex;
32+
33+
.pf-button {
34+
flex: 1;
35+
}
36+
}
2037

2138
.pf-button {
22-
border-radius: 0;
39+
border-radius: $border-radius;
40+
background: transparent;
41+
color: var(--pf-color-text-muted);
2342

24-
&:first-child {
25-
border-radius: $border-radius 0 0 $border-radius;
43+
&:hover {
44+
background: color-mix(
45+
in srgb,
46+
transparent,
47+
var(--pf-color-interactive-base) 10%
48+
);
2649
}
2750

28-
&:last-child {
29-
border-radius: 0 $border-radius $border-radius 0;
51+
&.pf-active {
52+
background: var(--pf-color-background);
53+
color: var(--pf-color-text);
3054
}
3155
}
3256
}

ui/src/components/tracks/add_debug_track_menu.ts

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import m from 'mithril';
1616
import {findRef} from '../../base/dom_utils';
1717
import {assertUnreachable} from '../../base/assert';
1818
import {Trace} from '../../public/trace';
19-
import {Form, FormLabel, FormSection} from '../../widgets/form';
19+
import {Form, FormGrid, FormLabel, FormSection} from '../../widgets/form';
20+
import {SegmentedButtons} from '../../widgets/segmented_buttons';
2021
import {Select} from '../../widgets/select';
2122
import {TextInput} from '../../widgets/text_input';
2223
import {addDebugCounterTrack, addDebugSliceTrack} from './debug_tracks';
@@ -106,6 +107,7 @@ export class AddDebugTrackMenu
106107
return m(
107108
Form,
108109
{
110+
className: 'pf-add-debug-track-menu',
109111
onSubmit: () => {
110112
attrs.onAdd?.();
111113
this.createTracks(attrs);
@@ -132,7 +134,12 @@ export class AddDebugTrackMenu
132134
this.trackName,
133135
),
134136
m(FormLabel, {for: 'track_type'}, 'Track type'),
135-
this.renderTrackTypeSelect(),
137+
m(SegmentedButtons, {
138+
fillWidth: true,
139+
options: [{label: 'Slice Track'}, {label: 'Counter Track'}],
140+
selectedOption: trackTypes.indexOf(this.trackType),
141+
onOptionSelected: (i) => (this.trackType = trackTypes[i]),
142+
}),
136143
m(
137144
FormSection,
138145
{label: 'Column mapping'},
@@ -141,29 +148,6 @@ export class AddDebugTrackMenu
141148
);
142149
}
143150

144-
private renderTrackTypeSelect() {
145-
return m(
146-
Select,
147-
{
148-
id: 'track_type',
149-
oninput: (e: Event) => {
150-
if (!e.target) return;
151-
this.trackType = (e.target as HTMLSelectElement).value as TrackType;
152-
},
153-
},
154-
trackTypes.map((value) =>
155-
m(
156-
'option',
157-
{
158-
value: value,
159-
selected: this.trackType === value,
160-
},
161-
value,
162-
),
163-
),
164-
);
165-
}
166-
167151
private renderOptions(availableColumns: ReadonlyArray<string>) {
168152
switch (this.trackType) {
169153
case 'slice':
@@ -176,46 +160,33 @@ export class AddDebugTrackMenu
176160
}
177161

178162
private renderSliceOptions(availableColumns: ReadonlyArray<string>) {
179-
return [
180-
this.renderFormSelectInput('Timestamp column', 'ts', availableColumns),
181-
this.renderFormSelectInput('Duration column', 'dur', [
163+
return m(
164+
FormGrid,
165+
this.renderFormSelectInput('Timestamp *', 'ts', availableColumns),
166+
this.renderFormSelectInput('Duration *', 'dur', [
182167
'0',
183168
...availableColumns,
184169
]),
185-
this.renderFormSelectInput('Name column', 'name', availableColumns),
170+
this.renderFormSelectInput('Name *', 'name', availableColumns),
186171
this.renderColorSelect(availableColumns),
187-
this.renderFormSelectInput(
188-
'Arguments ID column (optional)',
189-
'argSetId',
190-
availableColumns,
191-
{
192-
optional: true,
193-
},
194-
),
195-
this.renderFormSelectInput(
196-
'Pivot column (optional)',
197-
'pivot',
198-
availableColumns,
199-
{
200-
optional: true,
201-
},
202-
),
203-
];
172+
this.renderFormSelectInput('Args ID', 'argSetId', availableColumns, {
173+
optional: true,
174+
}),
175+
this.renderFormSelectInput('Pivot on', 'pivot', availableColumns, {
176+
optional: true,
177+
}),
178+
);
204179
}
205180

206181
private renderCounterTrackOptions(availableColumns: ReadonlyArray<string>) {
207-
return [
208-
this.renderFormSelectInput('Timestamp column', 'ts', availableColumns),
209-
this.renderFormSelectInput('Value column', 'value', availableColumns),
210-
this.renderFormSelectInput(
211-
'Pivot column (optional)',
212-
'pivot',
213-
availableColumns,
214-
{
215-
optional: true,
216-
},
217-
),
218-
];
182+
return m(
183+
FormGrid,
184+
this.renderFormSelectInput('Timestamp *', 'ts', availableColumns),
185+
this.renderFormSelectInput('Value *', 'value', availableColumns),
186+
this.renderFormSelectInput('Pivot on', 'pivot', availableColumns, {
187+
optional: true,
188+
}),
189+
);
219190
}
220191

221192
private renderColorSelect(availableColumns: ReadonlyArray<string>) {

0 commit comments

Comments
 (0)