Skip to content

Commit f9276c8

Browse files
committed
Refactor version dropdown
1 parent 8826879 commit f9276c8

File tree

4 files changed

+69
-24
lines changed

4 files changed

+69
-24
lines changed

scaladoc-js/resources/versions-dropdown.css

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
/* The container <div> - needed to position the dropdown content */
2+
23
.versions-dropdown {
4+
margin-left: 10px;
5+
margin-right: 10px;
36
position: relative;
47
}
58

69
/* Dropdown Button */
710
.dropdownbtn {
811
padding: 4px 12px;
912
border: none;
13+
display: flex;
14+
flex-direction: row;
15+
align-items: center;
16+
border-radius: 3px;
17+
}
18+
19+
.dropdownbtnactive {
20+
background-color: var(--leftbar-dropdown-bg);
1021
}
1122

1223
/* Dropdown button on hover & focus */
@@ -15,43 +26,75 @@
1526
cursor: pointer;
1627
}
1728

29+
.dropdownbtn span.ar {
30+
display: none;
31+
}
32+
33+
.dropdownbtnactive span.ar {
34+
display: unset;
35+
position:absolute;
36+
right: 10px;
37+
z-index: 100;
38+
}
39+
40+
.dropdownbtnactive span.ar:before {
41+
content: '\e903';
42+
}
43+
44+
.dropdownbtnactive.expanded span.ar:before {
45+
content: '\e905';
46+
}
47+
1848
/* The search field */
1949
#dropdown-input {
2050
box-sizing: border-box;
21-
background-image: url('searchicon.png');
22-
background-position: 14px 12px;
23-
background-repeat: no-repeat;
24-
font-size: 16px;
25-
padding: 14px 20px 12px 45px;
26-
border: none;
27-
border-bottom: 1px solid #ddd;
51+
background-color: var(--leftbar-dropdown-bg);
52+
color: var(--leftbar-fg);
53+
width: 100%;
54+
font-size: var(--leftbar-font-size);
55+
border-radius: 3px;
56+
padding: 4px 12px;
2857
}
2958

59+
#dropdown-input::placeholder{
60+
color: var(--inactive-fg);
61+
}
3062

31-
/* The search field when it gets focus/clicked on */
32-
#dropdown-input:focus {outline: 3px solid #ddd;}
63+
#dropdown-input, #dropdown-input:focus {
64+
outline: none;
65+
border: none;
66+
border-bottom: 1px solid var(--border-medium);
67+
}
3368

3469

3570
/* Dropdown Content (Hidden by Default) */
3671
.dropdown-content {
3772
display: none;
3873
position: absolute;
39-
background-color: #f6f6f6;
74+
top: 0px;
75+
left: 0px;
76+
width: 100%;
77+
background-color: var(--leftbar-dropdown-bg);
78+
font-size: var(--leftbar-font-size);
4079
min-width: 230px;
41-
border: 1px solid #ddd;
80+
border-radius: 3px;
4281
z-index: 1;
4382
}
4483

4584
/* Links inside the dropdown */
4685
.dropdown-content a {
47-
color: black;
48-
padding: 12px 16px;
86+
color: var(--leftbar-fg);
4987
text-decoration: none;
88+
padding: 4px 12px;
5089
display: block;
90+
border-radius: 3px;
5191
}
5292

5393
/* Change color of dropdown links on hover */
54-
.dropdown-content a:hover {background-color: #f1f1f1}
94+
.dropdown-content a:hover {
95+
background-color: var(--leftbar-hover-bg);
96+
color: var(--leftbar-fg);
97+
}
5598

5699
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
57100
.show {

scaladoc-js/src/versions-dropdown/DropdownHandler.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,11 @@ class DropdownHandler:
6060
addVersionsList(json)
6161

6262
document.addEventListener("click", (e: Event) => {
63-
if e.target.asInstanceOf[html.Element].id != "dropdown-button" then
64-
document.getElementById("dropdown-content").classList.remove("show")
65-
document.getElementById("dropdown-button").classList.remove("expanded")
63+
document.getElementById("dropdown-content").classList.remove("show")
64+
document.getElementById("dropdown-button").classList.remove("expanded")
6665
})
6766

68-
document.getElementById("version").asInstanceOf[html.Span].onclick = (e: Event) => {
69-
e.stopPropagation
70-
}
67+
document.getElementById("version").asInstanceOf[html.Span].addEventListener("click", (e: Event) => e.stopPropagation())
7168
end DropdownHandler
7269

7370
@JSExportTopLevel("dropdownHandler")
@@ -76,6 +73,7 @@ def dropdownHandler() =
7673
window.getSelection.toString.length == 0 then
7774
document.getElementById("dropdown-content").classList.toggle("show")
7875
document.getElementById("dropdown-button").classList.toggle("expanded")
76+
document.getElementById("dropdown-input").asInstanceOf[html.Input].focus()
7977

8078
@JSExportTopLevel("filterFunction")
8179
def filterFunction() =

scaladoc/resources/dotty_res/styles/colors.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
--leftbar-hover-fg: var(--grey900);
7878
--leftbar-border: var(--grey300);
7979

80+
--leftbar-dropdown-bg: var(--grey200);
81+
8082
--footer-bg: var(--white);
8183
--footer-fg: var(--grey700);
8284

@@ -125,6 +127,8 @@
125127
--leftbar-hover-fg: var(--grey300);
126128
--leftbar-border: var(--grey800);
127129

130+
--leftbar-dropdown-bg: var(--grey850);
131+
128132
--footer-bg: var(--grey930);
129133
--footer-fg: var(--grey400);
130134

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
278278
div(id := "version")(
279279
div(cls := "versions-dropdown")(
280280
div(onclick := "dropdownHandler()", id := "dropdown-button", cls := "dropdownbtn dropdownbtnactive")(
281-
args.projectVersion.map(v => div(cls:="projectVersion")(v)).getOrElse("")
282-
),
283-
div(id := "dropdown-content", cls := "dropdown-content")(
284-
input(`type` := "text", placeholder := "Search...", id := "dropdown-input", onkeyup := "filterFunction()"),
281+
args.projectVersion.map(v => div(cls:="projectVersion")(v)).getOrElse(""),
282+
div(id := "dropdown-content", cls := "dropdown-content")(
283+
input(`type` := "text", placeholder := "Search...", id := "dropdown-input", onkeyup := "filterFunction()"),
284+
),
285285
),
286286
)
287287
),

0 commit comments

Comments
 (0)