Skip to content

Commit fdbb94f

Browse files
authored
Merge pull request #12565 from dylemma/scaladoc-color-themes
Add dark/light theme swapper, make light theme less harsh, and some other small style changes
2 parents 9323e4e + be8fbba commit fdbb94f

File tree

9 files changed

+285
-77
lines changed

9 files changed

+285
-77
lines changed

docs/css/dottydoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ul.post-list {
4343

4444
/* headings anchors */
4545
a.anchor {
46-
color: white;
46+
color: transparent;
4747
margin-left: -23px;
4848
padding-right: 3px;
4949
transition: color .4s ease-out;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
const settingKey = "use-dark-theme";
13+
14+
function toggleDarkTheme(isDark) {
15+
currentlyDark = isDark
16+
// this triggers the `:root.theme-dark` rule from scalastyle.css,
17+
// which changes the values of a bunch of CSS color variables
18+
document.documentElement.classList.toggle("theme-dark", isDark);
19+
supportsLocalStorage && localStorage.setItem(settingKey, isDark);
20+
}
21+
22+
/* Infer a dark/light theme preference from the user's system */
23+
const colorSchemePrefMql = window.matchMedia("(prefers-color-scheme: dark)");
24+
25+
/* This needs to happen ASAP so we don't get a FOUC of bright colors before the dark theme is applied */
26+
const initiallyDark = (() => {
27+
const storedSetting = supportsLocalStorage && localStorage.getItem(settingKey);
28+
return (storedSetting === null) ? colorSchemePrefMql.matches : storedSetting === "true";
29+
})();
30+
let currentlyDark = initiallyDark;
31+
toggleDarkTheme(initiallyDark);
32+
33+
/* Wait for the DOM to be loaded before we try to attach event listeners to things in the DOM */
34+
window.addEventListener("DOMContentLoaded", () => {
35+
const themeToggler = document.querySelector('#theme-toggle input');
36+
themeToggler.checked = !currentlyDark;
37+
themeToggler.addEventListener("change", e => {
38+
toggleDarkTheme(!e.target.checked);
39+
});
40+
41+
/* Auto-swap the dark/light theme if the user changes it in their system */
42+
colorSchemePrefMql.addEventListener('change', e => {
43+
const preferDark = e.matches;
44+
themeToggler.checked = !preferDark;
45+
toggleDarkTheme(preferDark);
46+
});
47+
});
48+
})();

scaladoc/resources/dotty_res/scripts/ux.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ window.addEventListener("DOMContentLoaded", () => {
3939
})
4040

4141
if (location.hash) {
42-
var selected = document.getElementById(location.hash.substring(1));
43-
if (selected){
44-
selected.classList.toggle("expand");
42+
var target = location.hash.substring(1);
43+
// setting the 'expand' class on the top-level container causes undesireable styles
44+
// to apply to the top-level docs, so we avoid this logic for that element.
45+
if (target != 'container') {
46+
var selected = document.getElementById(location.hash.substring(1));
47+
if (selected) {
48+
selected.classList.toggle("expand");
49+
}
4550
}
4651
}
4752

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

+24-23
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
}
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)