Skip to content

Commit 492929c

Browse files
Dark mode toggle implementation (#683)
* svg for theme toggle * feat: add dark mode state management and CSS variables * feat: add ThemeToggle component with moon/sun icons * feat: integrate ThemeToggle into sidebar with proper positioning * style: update component styles for dark mode compatibility * docs: update changelog with correct repository link - Fix PR link to point to webpack/webpack-bundle-analyzer - Add proper GitHub profile attribution @theEquinoxDev - Follow established changelog format consistency * Fix lint --------- Co-authored-by: Vesa Laakso <[email protected]>
1 parent 8c14975 commit 492929c

File tree

15 files changed

+159
-9
lines changed

15 files changed

+159
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1616
* Prevent `TypeError` when `assets` or `modules` are undefined in `analyzer.js`
1717
([#679](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/679) by [@Srushti-33](https://github.com/Srushti-33))
1818

19+
* **New Feature**
20+
* Add optional dark/light mode toggle ([#683](https://github.com/webpack/webpack-bundle-analyzer/pull/683) by [@theEquinoxDev](https://github.com/theEquinoxDev))
21+
22+
1923
## 5.0.1
2024

2125
* **Bug Fix**

client/assets/icon-moon.svg

Lines changed: 3 additions & 0 deletions
Loading

client/assets/icon-sun.svg

Lines changed: 4 additions & 0 deletions
Loading

client/components/Button.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
.button {
2-
background: #fff;
3-
border: 1px solid #aaa;
2+
background: var(--bg-primary);
3+
border: 1px solid var(--border-color);
44
border-radius: 4px;
55
cursor: pointer;
66
display: inline-block;
77
font: var(--main-font);
88
outline: none;
99
padding: 5px 7px;
10-
transition: background .3s ease;
10+
transition: background .3s ease, border-color .3s ease, color .3s ease;
1111
white-space: nowrap;
12+
color: var(--text-primary);
1213
}
1314

1415
.button:focus,
1516
.button:hover {
16-
background: #ffefd7;
17+
background: var(--hover-bg);
1718
}
1819

1920
.button.active {

client/components/Dropdown.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
}
1111

1212
.input {
13-
border: 1px solid #aaa;
13+
border: 1px solid var(--border-color);
1414
border-radius: 4px;
1515
display: block;
1616
width: 100%;
17-
color: #7f7f7f;
17+
color: var(--text-secondary);
1818
height: 27px;
19+
background: var(--bg-primary);
20+
transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
1921
}
2022

2123
.option {

client/components/Icon.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
.icon {
22
background: no-repeat center/contain;
33
display: inline-block;
4+
filter: invert(0);
5+
}
6+
7+
[data-theme="dark"] .icon {
8+
filter: invert(1);
49
}

client/components/Icon.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import PureComponent from '../lib/PureComponent';
44

55
import iconArrowRight from '../assets/icon-arrow-right.svg';
66
import iconPin from '../assets/icon-pin.svg';
7+
import iconMoon from '../assets/icon-moon.svg';
8+
import iconSun from '../assets/icon-sun.svg';
79

810
const ICONS = {
911
'arrow-right': {
@@ -13,6 +15,14 @@ const ICONS = {
1315
'pin': {
1416
src: iconPin,
1517
size: [12, 18]
18+
},
19+
'moon': {
20+
src: iconMoon,
21+
size: [24, 24]
22+
},
23+
'sun': {
24+
src: iconSun,
25+
size: [24, 24]
1626
}
1727
};
1828

client/components/Search.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313
}
1414

1515
.input {
16-
border: 1px solid #aaa;
16+
border: 1px solid var(--border-color);
1717
border-radius: 4px;
1818
display: block;
1919
flex: 1;
2020
padding: 5px;
21+
background: var(--bg-primary);
22+
color: var(--text-primary);
23+
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
24+
}
25+
26+
.input:focus {
27+
outline: none;
28+
border-color: var(--text-secondary);
2129
}
2230

2331
.clear {

client/components/Sidebar.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@value toggleTime: 200ms;
22

33
.container {
4-
background: #fff;
4+
background: var(--bg-primary);
55
border: none;
6-
border-right: 1px solid #aaa;
6+
border-right: 1px solid var(--border-color);
77
box-sizing: border-box;
88
max-width: calc(50% - 10px);
99
opacity: 0.95;
1010
z-index: 1;
11+
transition: background-color 0.3s ease, border-color 0.3s ease;
1112
}
1213

1314
.container:not(.hidden) {
@@ -45,6 +46,16 @@
4546
padding: 0;
4647
}
4748

49+
.container :global(.themeToggle) {
50+
position: absolute;
51+
top: 10px;
52+
left: 15px;
53+
z-index: 10;
54+
height: 26px;
55+
width: 27px;
56+
padding: 0;
57+
}
58+
4859
.pinButton,
4960
.toggleButton {
5061
cursor: pointer;

client/components/Sidebar.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cls from 'classnames';
44
import s from './Sidebar.css';
55
import Button from './Button';
66
import Icon from './Icon';
7+
import ThemeToggle from './ThemeToggle';
78

89
const toggleTime = parseInt(s.toggleTime);
910

@@ -48,6 +49,7 @@ export default class Sidebar extends Component {
4849
className={className}
4950
onClick={this.handleClick}
5051
onMouseLeave={this.handleMouseLeave}>
52+
<ThemeToggle/>
5153
{visible &&
5254
<Button type="button"
5355
title="Pin"

0 commit comments

Comments
 (0)