Skip to content

Commit

Permalink
chore(trace-viewer): Clean up settings component for shared uses
Browse files Browse the repository at this point in the history
  • Loading branch information
agg23 committed Dec 19, 2024
1 parent a239ab3 commit 1f67e16
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
22 changes: 12 additions & 10 deletions packages/trace-viewer/src/ui/settingsView.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
*/

.settings-view {
display: flex;
flex: none;
margin-top: 4px;
padding: 4px 0px;
row-gap: 8px;
user-select: none;
}

.settings-view .setting label {
.settings-view .setting {
display: flex;
flex-direction: row;
align-items: center;
margin: 4px 2px;
}

.settings-view .setting:first-of-type label {
margin-top: 2px;
}
.settings-view .setting label {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;

.settings-view .setting:last-of-type label {
margin-bottom: 2px;
cursor: pointer;
}

.settings-view .setting input {
margin-right: 5px;
}
flex-shrink: 0;
}
40 changes: 25 additions & 15 deletions packages/trace-viewer/src/ui/settingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,32 @@ import * as React from 'react';
import './settingsView.css';

export type Setting<T> = {
value: T,
set: (value: T) => void,
title: string
value: T;
set: (value: T) => void;
name: string;
title?: string;
};

export const SettingsView: React.FunctionComponent<{
settings: Setting<boolean>[],
settings: Setting<boolean>[];
}> = ({ settings }) => {
return <div className='vbox settings-view'>
{settings.map(({ value, set, title }) => {
return <div key={title} className='setting'>
<label>
<input type='checkbox' checked={value} onChange={() => set(!value)}/>
{title}
</label>
</div>;
})}
</div>;
};
return (
<div className='vbox settings-view'>
{settings.map(({ value, set, name, title }) => {
const labelId = `setting-${name}`;

return (
<div key={name} className='setting' title={title}>
<input
type='checkbox'
id={labelId}
checked={value}
onChange={() => set(!value)}
/>
<label htmlFor={labelId}>{name}</label>
</div>
);
})}
</div>
);
};
10 changes: 5 additions & 5 deletions packages/trace-viewer/src/ui/uiModeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ export const UIModeView: React.FC<{}> = ({
<div className='section-title'>Testing Options</div>
</Toolbar>
{testingOptionsVisible && <SettingsView settings={[
{ value: singleWorker, set: setSingleWorker, title: 'Single worker' },
{ value: showBrowser, set: setShowBrowser, title: 'Show browser' },
{ value: updateSnapshots, set: setUpdateSnapshots, title: 'Update snapshots' },
{ value: singleWorker, set: setSingleWorker, name: 'Single worker' },
{ value: showBrowser, set: setShowBrowser, name: 'Show browser' },
{ value: updateSnapshots, set: setUpdateSnapshots, name: 'Update snapshots' },
]} />}
</>}
<Toolbar noShadow={true} noMinHeight={true} className='settings-toolbar' onClick={() => setSettingsVisible(!settingsVisible)}>
Expand All @@ -522,10 +522,10 @@ export const UIModeView: React.FC<{}> = ({
<div className='section-title'>Settings</div>
</Toolbar>
{settingsVisible && <SettingsView settings={[
{ value: darkMode, set: setDarkMode, title: 'Dark mode' },
{ value: darkMode, set: setDarkMode, name: 'Dark mode' },
]} />}
</div>
}
/>
</div>;
};
};

0 comments on commit 1f67e16

Please sign in to comment.