Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/assets/icon-moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions client/assets/icon-sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions client/components/Button.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
.button {
background: #fff;
border: 1px solid #aaa;
background: var(--bg-primary);
border: 1px solid var(--border-color);
border-radius: 4px;
cursor: pointer;
display: inline-block;
font: var(--main-font);
outline: none;
padding: 5px 7px;
transition: background .3s ease;
transition: background .3s ease, border-color .3s ease, color .3s ease;
white-space: nowrap;
color: var(--text-primary);
}

.button:focus,
.button:hover {
background: #ffefd7;
background: var(--hover-bg);
}

.button.active {
Expand Down
6 changes: 4 additions & 2 deletions client/components/Dropdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
}

.input {
border: 1px solid #aaa;
border: 1px solid var(--border-color);
border-radius: 4px;
display: block;
width: 100%;
color: #7f7f7f;
color: var(--text-secondary);
height: 27px;
background: var(--bg-primary);
transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.option {
Expand Down
5 changes: 5 additions & 0 deletions client/components/Icon.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.icon {
background: no-repeat center/contain;
display: inline-block;
filter: invert(0);
}

[data-theme="dark"] .icon {
filter: invert(1);
}
10 changes: 10 additions & 0 deletions client/components/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PureComponent from '../lib/PureComponent';

import iconArrowRight from '../assets/icon-arrow-right.svg';
import iconPin from '../assets/icon-pin.svg';
import iconMoon from '../assets/icon-moon.svg';
import iconSun from '../assets/icon-sun.svg';

const ICONS = {
'arrow-right': {
Expand All @@ -13,6 +15,14 @@ const ICONS = {
'pin': {
src: iconPin,
size: [12, 18]
},
'moon': {
src: iconMoon,
size: [24, 24]
},
'sun': {
src: iconSun,
size: [24, 24]
}
};

Expand Down
10 changes: 9 additions & 1 deletion client/components/Search.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
}

.input {
border: 1px solid #aaa;
border: 1px solid var(--border-color);
border-radius: 4px;
display: block;
flex: 1;
padding: 5px;
background: var(--bg-primary);
color: var(--text-primary);
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.input:focus {
outline: none;
border-color: var(--text-secondary);
}

.clear {
Expand Down
15 changes: 13 additions & 2 deletions client/components/Sidebar.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@value toggleTime: 200ms;

.container {
background: #fff;
background: var(--bg-primary);
border: none;
border-right: 1px solid #aaa;
border-right: 1px solid var(--border-color);
box-sizing: border-box;
max-width: calc(50% - 10px);
opacity: 0.95;
z-index: 1;
transition: background-color 0.3s ease, border-color 0.3s ease;
}

.container:not(.hidden) {
Expand Down Expand Up @@ -45,6 +46,16 @@
padding: 0;
}

.container :global(.themeToggle) {
position: absolute;
top: 10px;
left: 15px;
z-index: 10;
height: 26px;
width: 27px;
padding: 0;
}

.pinButton,
.toggleButton {
cursor: pointer;
Expand Down
2 changes: 2 additions & 0 deletions client/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cls from 'classnames';
import s from './Sidebar.css';
import Button from './Button';
import Icon from './Icon';
import ThemeToggle from './ThemeToggle';

const toggleTime = parseInt(s.toggleTime);

Expand Down Expand Up @@ -48,6 +49,7 @@ export default class Sidebar extends Component {
className={className}
onClick={this.handleClick}
onMouseLeave={this.handleMouseLeave}>
<ThemeToggle/>
{visible &&
<Button type="button"
title="Pin"
Expand Down
19 changes: 19 additions & 0 deletions client/components/ThemeToggle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.themeToggle {
background: transparent;
border: none;
cursor: pointer;
padding: 8px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
transition: background-color 0.2s ease;
}

.themeToggle:hover {
background: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .themeToggle:hover {
background: rgba(255, 255, 255, 0.1);
}
28 changes: 28 additions & 0 deletions client/components/ThemeToggle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Component} from 'preact';
import {observer} from 'mobx-react';

import s from './ThemeToggle.css';
import Button from './Button';
import Icon from './Icon';
import {store} from '../store';

@observer
export default class ThemeToggle extends Component {
render() {
const {darkMode} = store;

return (
<Button
type="button"

Check failure on line 16 in client/components/ThemeToggle.jsx

View workflow job for this annotation

GitHub Actions / lint

Property should be placed on the same line as the component declaration
title={darkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode'}
className={s.themeToggle}
onClick={this.handleToggle}>
<Icon name={darkMode ? 'sun' : 'moon'} size={16}/>
</Button>
);
}

handleToggle = () => {
store.toggleDarkMode();
}
}
15 changes: 15 additions & 0 deletions client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Store {
@observable defaultSize;
@observable selectedSize;
@observable showConcatenatedModulesContent = (localStorage.getItem('showConcatenatedModulesContent') === true);
@observable darkMode = (localStorage.getItem('darkMode') === true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browser can disable access to localStorage in some environments so we should protect against getItem or setItem throwing an error. We can just fail silently and assume that dark mode is unset and thus use the system value as the default.


setModules(modules) {
walkModules(modules, module => {
Expand Down Expand Up @@ -179,6 +180,20 @@ export class Store {
return filteredModules;
}, []);
}

toggleDarkMode() {
this.darkMode = !this.darkMode;
localStorage.setItem('darkMode', this.darkMode);
this.updateTheme();
}

updateTheme() {
if (this.darkMode) {
document.documentElement.setAttribute('data-theme', 'dark');
} else {
document.documentElement.removeAttribute('data-theme');
}
}
}

export const store = new Store();
22 changes: 22 additions & 0 deletions client/viewer.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
:root {
--main-font: normal 11px Verdana, sans-serif;
--bg-primary: #fff;
--bg-secondary: #f5f5f5;
--text-primary: #000;
--text-secondary: #666;
--border-color: #aaa;
--border-light: #ddd;
--shadow: rgba(0, 0, 0, 0.1);
--hover-bg: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
--bg-primary: #1e1e1e;
--bg-secondary: #252525;
--text-primary: #e0e0e0;
--text-secondary: #a0a0a0;
--border-color: #404040;
--border-light: #333;
--shadow: rgba(0, 0, 0, 0.3);
--hover-bg: rgba(255, 255, 255, 0.05);
}

:global html,
Expand All @@ -10,6 +29,9 @@
overflow: hidden;
padding: 0;
width: 100%;
background: var(--bg-primary);
color: var(--text-primary);
transition: background-color 0.3s ease, color 0.3s ease;
}

:global body.resizing {
Expand Down
1 change: 1 addition & 0 deletions client/viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.addEventListener('load', () => {
store.defaultSize = `${window.defaultSizes}Size`;
store.setModules(window.chartData);
store.setEntrypoints(window.entrypoints);
store.updateTheme();
render(
<ModulesTreemap/>,
document.getElementById('app')
Expand Down
Loading