Skip to content

Commit e2e5e02

Browse files
committed
make default colors less harsh, add dark/light theme swapper
1 parent 9323e4e commit e2e5e02

File tree

7 files changed

+246
-59
lines changed

7 files changed

+246
-59
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;(function () {
2+
const supportsLocalStorage = (() => {
3+
try {
4+
localStorage.setItem('test', 'test');
5+
localStorage.removeItem('test');
6+
return true;
7+
} catch (e) {
8+
return false;
9+
}
10+
})();
11+
12+
function toggleDarkTheme(isDark) {
13+
currentlyDark = isDark
14+
// this triggers the `:root.theme-dark` rule from scalastyle.css,
15+
// which changes the values of a bunch of CSS color variables
16+
document.documentElement.classList.toggle("theme-dark", isDark);
17+
supportsLocalStorage && localStorage.setItem("use-dark-theme", isDark);
18+
}
19+
20+
/* This needs to happen ASAP so we don't get a FOUC of bright colors before the dark theme is applied */
21+
const initiallyDark = supportsLocalStorage && (localStorage.getItem("use-dark-theme") === "true");
22+
let currentlyDark = initiallyDark;
23+
toggleDarkTheme(initiallyDark);
24+
25+
/* Wait for the DOM to be loaded before we try to attach event listeners to things in the DOM */
26+
window.addEventListener("DOMContentLoaded", () => {
27+
const themeToggler = document.querySelector('#theme-toggle input');
28+
themeToggler.checked = !currentlyDark;
29+
themeToggler.addEventListener("change", e => {
30+
toggleDarkTheme(!e.target.checked);
31+
});
32+
});
33+
})();

scaladoc/resources/dotty_res/styles/filter-bar.css

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.documentableFilter {
22
padding: 24px 12px;
3-
background-color: var(--leftbar-bg);
3+
background-color: var(--code-bg);
44
}
55

66
.documentableFilter.active .filterToggleButton svg {
@@ -26,13 +26,13 @@
2626
}
2727

2828
.filterToggleButton svg {
29-
fill: var(--code-bg);
29+
fill: var(--body-fg);
3030
transition: fill 0.1s ease-in, transform 0.1s ease-in-out;
3131
}
3232

3333
.filterToggleButton:hover svg,
3434
.filterToggleButton:focus svg {
35-
fill: var(--active-tab-color);
35+
fill: var(--active-fg);
3636
}
3737

3838
.filterableInput {
@@ -41,7 +41,7 @@
4141
outline: 0;
4242
border: 0;
4343
border-radius: 3px;
44-
background-color: var(--code-bg);
44+
background-color: var(--body-bg);
4545
}
4646

4747
.filterLowerContainer {
@@ -50,12 +50,11 @@
5050
}
5151

5252
.filterGroup {
53-
display: flex;
5453
margin-bottom: 16px;
5554
}
5655

5756
.filterList {
58-
margin-left: 10px;
57+
margin: 0.5em;
5958
}
6059

6160
.filterButtonItem {
@@ -66,12 +65,12 @@
6665
outline: 0;
6766
border: 0;
6867
border-radius: 3px;
69-
color: var(--leftbar-bg);
70-
background-color: var(--code-bg);
68+
color: var(--inactive-fg);
69+
background-color: var(--inactive-bg);
7170
font-size: 12px;
7271
font-weight: 700;
7372
cursor: pointer;
74-
border-bottom: 2px solid var(--inactive-fg);
73+
border-bottom: 2px solid var(--inactive-bg-shadow);
7574
transition: all 0.1s ease-in;
7675
}
7776

@@ -81,27 +80,29 @@
8180
}
8281

8382
.filterButtonItem.active {
84-
color: var(--code-bg);
85-
border-bottom-color: var(--link-fg);
86-
background-color: var(--active-tab-color);
83+
color: var(--active-fg);
84+
border-bottom-color: var(--active-bg-shadow);
85+
background-color: var(--active-bg);
8786
}
8887

8988
.filterButtonItem.visible {
9089
display: inline-block;
9190
}
9291

9392
.groupTitle {
94-
min-width: 98px;
95-
margin-top: 4px;
93+
margin-bottom: 4px;
9694
font-weight: 700;
97-
font-size: 14px;
98-
color: var(--code-bg);
95+
color: var(--body-fg);
96+
}
97+
.groupTitle > span {
98+
display: inline-block;
99+
vertical-align: baseline;
99100
}
100101

101102
.groupButtonsContainer {
102-
display: flex;
103-
align-items: center;
104-
margin-top: 4px;
103+
display: inline-block;
104+
vertical-align: baseline;
105+
margin-left: 1em;
105106
}
106107

107108
.selectAll {
@@ -114,16 +115,16 @@
114115
border: 0;
115116
background-color: transparent;
116117
padding: 0;
117-
color: var(--code-bg);
118-
font-size: 8px;
118+
color: var(--active-fg);
119+
font-size: 0.7em;
119120
cursor: pointer;
120121
transition: all 0.1s ease-in;
121122
}
122123

123124
.selectAll {
124125
padding: 4px;
125126
border-radius: 2px;
126-
background-color: var(--active-tab-color);
127+
background-color: var(--active-bg);
127128
}
128129

129130
.selectAll:hover,
@@ -133,5 +134,5 @@
133134

134135
.deselectAll:hover,
135136
.deselectAll:focus {
136-
color: var(--active-tab-color);
137+
color: var(--active-bg);
137138
}
Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
/* Theme inspired by nordtheme. The colors have been darkened to work on light backgrounds. */
2+
:root {
3+
--hljs-bg: var(--code-bg);
4+
--hljs-fg: var(--code-fg);
5+
--hljs-comment: #90A1C1;
6+
--hljs-doctag: #4B6B92;
7+
--hljs-meta: hsl(40, 100%, 40%);
8+
--hljs-subst: hsl(40, 100%, 40%);
9+
--hljs-title: hsl(193, 60%, 42%);
10+
--hljs-type: hsl(179, 61%, 30%);
11+
--hljs-keyword: hsl(213, 60%, 45%);
12+
--hljs-string: hsl(92, 46%, 43%);
13+
--hljs-literal: hsl(311, 30%, 47%);
14+
}
15+
:root.theme-dark {
16+
--hljs-meta: hsl(40, 100%, 49%);
17+
--hljs-subst: hsl(40, 100%, 49%);
18+
--hljs-title: hsl(193, 60%, 58%);
19+
--hljs-keyword: hsl(213, 60%, 60%);
20+
--hljs-type: hsl(179, 61%, 45%);
21+
--hljs-string: hsl(92, 46%, 68%);
22+
--hljs-literal: hsl(311, 30%, 62%);
23+
}
24+
225
pre, .hljs {
3-
background: #F4F5FA;
4-
color: #4C566A;
26+
background: var(--hljs-bg);
27+
color: var(--code-fg);
528
}
629

730
.hljs-comment {
8-
color: #90A1C1;
31+
color: var(--hljs-comment);
932
}
1033
.hljs-doctag {
11-
color: #4B6B92;
34+
color: var(--hljs-doctag);
1235
font-weight: 500;
1336
}
1437
.hljs-emphasis {
@@ -19,26 +42,26 @@ pre, .hljs {
1942
}
2043

2144
.hljs-meta {
22-
color: #F9A600;
45+
color: var(--hljs-meta);
2346
font-weight: 500;
2447
}
2548
.hljs-subst {
26-
color: #F9A600;
49+
color: var(--hljs-subst);
2750
}
2851
.hljs-title {
29-
color: #2B8FAC;
52+
color: var(--hljs-title);
3053
font-weight: 500;
3154
}
3255
.hljs-type {
33-
color: #1E7C7A;
56+
color: var(--hljs-type);
3457
}
3558
.hljs-keyword {
36-
color: #2E6BB8;
59+
color: var(--hljs-keyword);
3760
font-weight: 500;
3861
}
3962
.hljs-string {
40-
color: #6AA13B;
63+
color: var(--hljs-string);
4164
}
4265
.hljs-built_in, .hljs-number, .hljs-literal {
43-
color: #9D5490;
66+
color: var(--hljs-literal);
4467
}

0 commit comments

Comments
 (0)