Skip to content

Commit 40db391

Browse files
committed
handle supertypes and subtypes children visiblity
1 parent 0ff085f commit 40db391

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

scaladoc/resources/dotty_res/scripts/ux.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ window.addEventListener("DOMContentLoaded", () => {
5454
el.parent.addClass("expanded")
5555
}))
5656

57+
document.querySelectorAll(".supertypes").forEach(el => el.firstChild.addEventListener('click', () => {
58+
el.classList.toggle("collapsed");
59+
el.firstChild.classList.toggle("expand");
60+
}))
61+
62+
63+
document.querySelectorAll(".subtypes").forEach(el => el.firstChild.addEventListener('click', () => {
64+
el.classList.toggle("collapsed");
65+
el.firstChild.classList.toggle("expand");
66+
}))
67+
68+
document.querySelectorAll(".nh").forEach(el => el.addEventListener('click', () => {
69+
el.lastChild.click()
70+
el.first.addClass("expanded")
71+
el.parent.addClass("expanded")
72+
}))
73+
5774
const observer = new IntersectionObserver(entries => {
5875
entries.forEach(entry => {
5976
const id = entry.target.getAttribute('id');

scaladoc/resources/dotty_res/styles/theme/components/subtypes.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,27 @@
33
padding: calc(3 * var(--base-spacing));
44
padding-bottom: calc(1.5 * var(--base-spacing));
55
overflow-x: scroll;
6+
position: relative;
7+
}
8+
9+
.subtypes > span {
10+
position: absolute;
11+
top: calc(1 * var(--base-spacing));
12+
right: calc(1 * var(--base-spacing));
13+
}
14+
15+
.subtypes > div {
16+
display: none;
17+
}
18+
19+
.subtypes > div:nth-child(2),
20+
.subtypes > div:nth-child(3),
21+
.subtypes > div:nth-child(4),
22+
.subtypes > div:nth-child(5),
23+
.subtypes > div:nth-child(6) {
24+
display: block;
25+
}
26+
27+
.subtypes.collapsed > div {
28+
display: block;
629
}

scaladoc/resources/dotty_res/styles/theme/components/supertypes.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,27 @@
33
padding: calc(3 * var(--base-spacing));
44
padding-bottom: calc(1.5 * var(--base-spacing));
55
overflow-x: scroll;
6+
position: relative;
7+
}
8+
9+
.supertypes > span {
10+
position: absolute;
11+
top: calc(1 * var(--base-spacing));
12+
right: calc(1 * var(--base-spacing));
13+
}
14+
15+
.supertypes > div {
16+
display: none;
17+
}
18+
19+
.supertypes > div:nth-child(2),
20+
.supertypes > div:nth-child(3),
21+
.supertypes > div:nth-child(4),
22+
.supertypes > div:nth-child(5),
23+
.supertypes > div:nth-child(6) {
24+
display: block;
25+
}
26+
27+
.supertypes.collapsed > div {
28+
display: block;
629
}

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,11 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
365365
))
366366
case _ => Nil
367367

368-
def signatureList(list: Seq[LinkToType], className: String = ""): Seq[AppliedTag] =
368+
def signatureList(list: Seq[LinkToType], className: String = "", expandable: Boolean): Seq[AppliedTag] =
369369
if list.isEmpty then Nil
370-
else Seq(div(cls := s"mono-small-inline $className")(list.map(link =>
370+
else Seq(div(cls := s"mono-small-inline $className")(
371+
if(expandable) then span(cls := "icon-button show-content") else span(),
372+
list.map(link =>
371373
div(link.kind.name," ", link.signature.map(renderElement(_)))
372374
)))
373375

@@ -377,8 +379,8 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
377379
div(link.signature.map(renderElement(_)))
378380
}})
379381

380-
val supertypes = signatureList(m.parents, "supertypes")
381-
val subtypes = signatureList(m.knownChildren, "subtypes")
382+
val supertypes = signatureList(m.parents, "supertypes", m.parents.length > 5)
383+
val subtypes = signatureList(m.knownChildren, "subtypes", m.knownChildren.length > 5)
382384
val selfType = selfTypeList(m.selfType.toList)
383385

384386
Seq(

0 commit comments

Comments
 (0)