Skip to content

Commit 4e9f2de

Browse files
authored
Merge pull request #30 from pikinier20/scaladoc/concise-view
Scaladoc/concise view
2 parents a688472 + 93c1c08 commit 4e9f2de

File tree

13 files changed

+219
-54
lines changed

13 files changed

+219
-54
lines changed

scaladoc-js/common/src/utils/SafeLocalStorage.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SafeLocalStorage[T <: js.Any](key: String, defaultValue: T) {
2020
def checkSupport[U](defaultValue: U)(callback: () => U): U =
2121
if isLocalStorageSupported then callback() else defaultValue
2222

23-
def parseData(data: String): T =
23+
private def parseData(data: String): T =
2424
try {
2525
Option(JSON.parse(data).asInstanceOf[T]).getOrElse(defaultValue)
2626
} catch {

scaladoc-js/main/src/ux/Ux.scala

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dotty.tools.scaladoc
22

3+
import scala.scalajs.js
34
import org.scalajs.dom._
45
import org.scalajs.dom.ext._
56

@@ -20,4 +21,31 @@ class Ux():
2021
case e: html.Span => e
2122
}.foreach(modifySpan)
2223

23-
sideMenuItemsWordBreaking()
24+
def loadConciseView(): Unit =
25+
val localStorageValue = SafeLocalStorage("__CONCISE_VIEW__", js.Array(false)) // One-element js.Array is a hack for having type extending js.Any
26+
val conciseViewSwitchInput = Option(document.getElementById("concise-view-switch"))
27+
.map(_.querySelector("input").asInstanceOf[html.Input])
28+
29+
def modifyContent(concise: Boolean) =
30+
if (concise) {
31+
document.querySelector(".membersList").classList.add("concise")
32+
} else {
33+
document.querySelector(".membersList").classList.remove("concise")
34+
}
35+
36+
conciseViewSwitchInput.foreach { input =>
37+
val storedValue = localStorageValue.getData.head
38+
modifyContent(storedValue)
39+
input.checked = storedValue
40+
input.addEventListener("change", e => {
41+
val target = e.target.asInstanceOf[html.Input]
42+
localStorageValue.setData(js.Array(target.checked))
43+
modifyContent(target.checked)
44+
})
45+
}
46+
47+
sideMenuItemsWordBreaking()
48+
loadConciseView()
49+
50+
51+

scaladoc/resources/dotty_res/scripts/components/DocumentableList.js

-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ class List {
177177
.every(([filterKey, value]) => {
178178
const filterGroup = filter.filters[filterKey]
179179

180-
console.log(Object.entries(filterGroup).filter(arr => arr[1].selected))
181-
182180
return Object.entries(filterGroup).filter(arr => arr[1].selected).length == 0 || value.split(",").some(v => (filterGroup && filterGroup[v].selected))
183181
})
184182

scaladoc/resources/dotty_res/scripts/ux.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ window.addEventListener("DOMContentLoaded", () => {
3434
var memberLists = document.getElementsByClassName("tab")
3535
if (memberLists) {
3636
for (i = 0; i < memberLists.length; i++) {
37-
memberLists[i].children[0].onclick = function(e) {
38-
this.classList.toggle("expand");
39-
this.parentElement.classList.toggle("expand");
37+
if ($(memberLists[i].children[0]).is("button")) {
38+
memberLists[i].children[0].onclick = function(e) {
39+
this.classList.toggle("expand");
40+
this.parentElement.classList.toggle("expand");
41+
}
4042
}
4143
}
4244
}

scaladoc/resources/dotty_res/styles/theme/color-tokens.css

+10
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
--shadow-first: var(--shadow1);
9393
--shadow-second: var(--shadow2);
9494
--shadow-inset: var(--grey7);
95+
96+
/* switch */
97+
--switch-button: var(--grey1);
98+
--switch-background-default: var(--grey9);
99+
--switch-background-selected: var(--indigo8);
95100
}
96101

97102
:root.theme-dark {
@@ -187,4 +192,9 @@
187192
--shadow-first: var(--shadow1);
188193
--shadow-second: var(--shadow2);
189194
--shadow-inset: var(--grey7);
195+
196+
/* switch */
197+
--switch-button: var(--grey12);
198+
--switch-background-default: var(--grey9);
199+
--switch-background-selected: var(--indigo11);
190200
}

scaladoc/resources/dotty_res/styles/theme/components/api-member.css

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313

1414
.documentableElement .signature {
1515
margin-right: calc(3 * var(--base-spacing));
16+
line-height: 1.5;
1617
}
1718

1819
.documentableElement:hover {
1920
cursor: pointer;
2021
}
2122

23+
.documentableElement .documentableBrief {
24+
color: var(--text-secondary);
25+
}
26+
2227
.documentableElement .annotations {
2328
display: none;
2429
}
@@ -50,10 +55,6 @@
5055
display: block;
5156
}
5257

53-
#content .documentableElement p {
54-
color: var(--text-primary);
55-
}
56-
5758
[t="k"] {
5859
color: var(--code-method-highlighting-keyword);
5960
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.switch {
2+
position: relative;
3+
display: inline-block;
4+
width: calc(4 * var(--base-spacing));
5+
height: calc(calc(2 * var(--base-spacing)) + 2px);
6+
margin: var(--base-spacing);
7+
}
8+
9+
.switch input {
10+
opacity: 0;
11+
width: 0;
12+
height: 0;
13+
}
14+
15+
.slider {
16+
position: absolute;
17+
cursor: pointer;
18+
top: 0;
19+
left: 0;
20+
right: 0;
21+
bottom: 0;
22+
background-color: var(--switch-background-default);
23+
-webkit-transition: .4s;
24+
transition: .4s;
25+
border-radius: calc(calc(4 * var(--base-spacing)) + 2px);
26+
}
27+
28+
.slider:before {
29+
position: absolute;
30+
content: "";
31+
height: calc(2 * var(--base-spacing));
32+
width: calc(2 * var(--base-spacing));
33+
left: 1px;
34+
bottom: 1px;
35+
background-color: var(--switch-button);
36+
-webkit-transition: .4s;
37+
transition: .4s;
38+
border-radius: 50%;
39+
}
40+
41+
input:checked + .slider {
42+
background-color: var(--switch-background-selected);
43+
}
44+
45+
input:focus + .slider {
46+
box-shadow: 0 0 1px var(--switch-background-selected);
47+
}
48+
49+
input:checked + .slider:before {
50+
-webkit-transform: translateX(calc(calc(2 * var(--base-spacing)) - 2px));
51+
-ms-transform: translateX(calc(calc(2 * var(--base-spacing)) - 2px));
52+
transform: translateX(calc(calc(2 * var(--base-spacing)) - 2px));
53+
}

scaladoc/resources/dotty_res/styles/theme/layout/container.css

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ body {
66
overflow: hidden;
77
}
88

9+
[id] {
10+
scroll-margin-top: calc(10 * var(--base-spacing));
11+
}
12+
913
#container {
1014
--header-height: calc(8 * var(--base-spacing));
1115
}

scaladoc/resources/dotty_res/styles/theme/layout/content.css

+35-6
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,17 @@
145145

146146
/* content headers */
147147

148+
#content h1:first-of-type {
149+
line-height: normal;
150+
}
151+
148152
#content h1,
149153
#content h2 {
150154
color: var(--text-primary);
151155
margin-block-end: 0;
152156
margin-block-start: 0;
153157
}
154158

155-
/* content paragraph */
156-
#content p {
157-
color: var(--text-primary);
158-
}
159-
160159
/* content first paragraph */
161160
#content .first-p {
162161
color: var(--text-secondary);
@@ -185,7 +184,6 @@
185184
#content :not(pre) > code {
186185
color: var(--code-props-content);
187186
font-family: "FiraCode-Regular";
188-
background-color: var(--red3);
189187
}
190188

191189
.breadcrumbs {
@@ -424,3 +422,34 @@
424422
#content section:last-child {
425423
margin-bottom: calc(6 * var(--base-spacing));
426424
}
425+
426+
.membersList {
427+
position: relative;
428+
}
429+
430+
#concise-view-switch {
431+
position: absolute;
432+
right: 0;
433+
top: var(--base-spacing);
434+
display: flex;
435+
flex-direction: row;
436+
align-items: center;
437+
}
438+
439+
.membersList.concise .documentableElement {
440+
padding-top: var(--base-spacing);
441+
padding-bottom: var(--base-spacing);
442+
margin: var(--base-spacing);
443+
}
444+
445+
.membersList.concise .documentableBrief p {
446+
margin-block-start: 0.5em;
447+
}
448+
449+
.membersList.concise .documentableElement .modifiers {
450+
display: none;
451+
}
452+
453+
.membersList.concise .documentableElement.expand .modifiers {
454+
display: unset;
455+
}

0 commit comments

Comments
 (0)