Skip to content

Commit ff7e5fa

Browse files
Filip Łukasikpikinier20
authored andcommitted
connect search icon to searchbar, add basic styles
1 parent 3ddfeca commit ff7e5fa

File tree

5 files changed

+79
-54
lines changed

5 files changed

+79
-54
lines changed

scaladoc-js/common/css/searchbar.css

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
color: var(--inactive-fg) !important;
2525
font-weight: 500 !important;
2626
}
27-
.action_def:hover, .action_def.hover_a79 {
27+
.action_def:hover,
28+
.action_def.hover_a79 {
2829
color: var(--selected-fg);
2930
background: var(--selected-bg) !important;
3031
font-weight: 500;
@@ -35,15 +36,15 @@
3536
}
3637

3738
/* Landscape phones, portait tablets */
38-
@media(max-width: 768px) {
39+
@media (max-width: 768px) {
3940
.popup-wrapper {
4041
width: calc(100% - 48px);
4142
left: 24px !important;
4243
}
4344
}
4445

4546
/* Portrait phones */
46-
@media(max-width: 576px) {
47+
@media (max-width: 576px) {
4748
.search-content {
4849
margin: 0 !important;
4950
top: 9px !important;
@@ -70,8 +71,10 @@
7071
padding: 4px;
7172
}
7273

73-
.loading, .loading::before, .loading::after {
74-
content: '';
74+
.loading,
75+
.loading::before,
76+
.loading::after {
77+
content: "";
7578
width: 10px;
7679
height: 10px;
7780
border-radius: 5px;
@@ -89,7 +92,7 @@
8992

9093
.loading {
9194
position: relative;
92-
animation-delay: .2s;
95+
animation-delay: 0.2s;
9396
}
9497

9598
.loading::before {
@@ -99,7 +102,7 @@
99102

100103
.loading::after {
101104
left: 15px;
102-
animation-delay: .4s;
105+
animation-delay: 0.4s;
103106
}
104107

105108
@keyframes dotFlashing {
@@ -116,7 +119,7 @@
116119

117120
.scaladoc-searchbar-inkuire-package {
118121
display: none;
119-
color: var(--symbol-fg)
122+
color: var(--symbol-fg);
120123
}
121124

122125
div[selected] > .scaladoc-searchbar-inkuire-package {
@@ -142,19 +145,19 @@ div[selected] > .scaladoc-searchbar-inkuire-package {
142145
background: var(--red600);
143146
}
144147

145-
@media(max-width: 576px) {
148+
@media (max-width: 576px) {
146149
.search span {
147-
background: none;
148-
fill: var(--icon-color);
149-
cursor: pointer;
150-
border: none;
151-
padding: 0;
152-
box-shadow: none;
153-
margin-top: 2px;
150+
background: none;
151+
fill: var(--icon-color);
152+
cursor: pointer;
153+
border: none;
154+
padding: 0;
155+
box-shadow: none;
156+
margin-top: 2px;
154157
}
155158

156159
.search span:hover {
157-
fill: var(--link-hover-fg);
160+
fill: var(--link-hover-fg);
158161
}
159162

160163
#scaladoc-searchbar span.pull-right {
@@ -175,32 +178,34 @@ div[selected] > .scaladoc-searchbar-inkuire-package {
175178
display: none;
176179
}
177180

178-
#scaladoc-searchbar {
181+
/* #scaladoc-searchbar {
179182
position: fixed;
180183
top: 50px;
181184
left: calc(5% + var(--side-width));
182185
z-index: 5;
183186
width: calc(90% - var(--side-width));
184187
box-shadow: 2px 2px 8px 0 var(--shadow);
185188
font-size: 13px;
186-
font-family: system-ui, -apple-system, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, Arial, sans-serif;
189+
font-family: system-ui, -apple-system, Segoe UI, Roboto, Noto Sans, Ubuntu,
190+
Cantarell, Helvetica Neue, Arial, sans-serif;
187191
background-color: var(--leftbar-bg);
188192
color: var(--leftbar-fg);
189-
}
193+
box-shadow: 0 0 2px var(--shadow);
194+
} */
190195

191-
#scaladoc-searchbar-input {
192-
width: 100%;
196+
/* #scaladoc-searchbar-input { */
197+
/* width: 100%;
193198
min-height: 32px;
194199
border: none;
195200
border-bottom: 1px solid #bbb;
196201
padding: 10px;
197202
background-color: var(--leftbar-bg);
198-
color: var(--leftbar-fg);
199-
}
203+
color: var(--leftbar-fg); */
204+
/* } */
200205

201-
#scaladoc-searchbar-input:focus {
206+
/* #scaladoc-searchbar-input:focus {
202207
outline: none;
203-
}
208+
} */
204209

205210
#scaladoc-searchbar-results {
206211
display: flex;

scaladoc-js/main/src/searchbar/SearchbarComponent.scala

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,29 +156,20 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
156156
}
157157
}
158158

159-
private val searchIcon: html.Div =
160-
val element = div(cls := "search-content")(
161-
div(cls := "search-container")(
162-
div(cls := "search")(
163-
span(id := "scaladoc-search")().tap { span =>
164-
span.innerHTML = """<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M19.64 18.36l-6.24-6.24a7.52 7.52 0 10-1.28 1.28l6.24 6.24zM7.5 13.4a5.9 5.9 0 115.9-5.9 5.91 5.91 0 01-5.9 5.9z"></path></svg>"""
165-
span.onclick = (event: Event) =>
166-
if (document.body.contains(rootDiv)) {
167-
document.body.removeChild(rootDiv)
168-
}
169-
else {
170-
document.body.appendChild(rootDiv)
171-
inputElem.focus()
172-
}
173-
}
174-
)
175-
)
176-
)
159+
private val searchIcon: html.Button =
160+
val icon = document.getElementById("search-toggle").asInstanceOf[html.Button]
161+
icon.onclick = (event: Event) =>
162+
if (document.body.contains(rootDiv)) {
163+
document.body.removeChild(rootDiv)
164+
}
165+
else {
166+
document.body.appendChild(rootDiv)
167+
input.focus()
168+
}
177169
// open the search if the user hits the `s` key when not focused on a text input
178170
document.body.addEventListener("keydown", (e: KeyboardEvent) => handleGlobalKeyDown(e))
179171

180-
document.getElementById("scaladoc-searchBar").appendChild(element)
181-
element
172+
icon
182173

183174
private val inputElem: html.Input =
184175
input(id := "scaladoc-searchbar-input").tap { element =>
@@ -198,11 +189,8 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
198189
private val rootShowClasses = ""
199190

200191
private val rootDiv: html.Div =
201-
val element = div(id := "scaladoc-searchbar")(
202-
inputElem,
203-
resultsDiv
204-
)
205-
192+
val rootParent = document.createElement("div").asInstanceOf[html.Div]
193+
val element = document.createElement("div").asInstanceOf[html.Div]
206194
element.addEventListener("mousedown", (e: Event) => e.stopPropagation())
207195
searchIcon.addEventListener("mousedown", (e: Event) => e.stopPropagation())
208196
document.body.addEventListener("mousedown", (e: Event) =>
@@ -217,8 +205,14 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
217205
else if e.keyCode == 13 then handleEnter()
218206
else if e.keyCode == 27 then handleEscape()
219207
})
220-
221-
element
208+
element.id = "scaladoc-searchbar"
209+
element.appendChild(input)
210+
element.appendChild(resultsDiv)
211+
// element
212+
rootParent.id = "searchbar-container"
213+
rootParent.appendChild(element)
214+
rootParent.addEventListener("mousedown", (e: Event) => handleEscape())
215+
rootParent
222216

223217
private def handleArrowUp() = {
224218
val selectedElement = resultsDiv.querySelector("[selected]")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#searchbar-container {
2+
width: 100%;
3+
height: 100%;
4+
z-index: 4;
5+
background-color: rgba(0, 0, 0, 0.569);
6+
display: flex;
7+
justify-content: center;
8+
position: absolute;
9+
}
10+
11+
#scaladoc-searchbar {
12+
z-index: 5;
13+
}
14+
15+
#scaladoc-searchbar-input {
16+
width: 100%;
17+
background-color: var(--action-primary-background-default-solid);
18+
background-image: url("../../../images/icon-buttons/search/dark/default.svg");
19+
background-repeat: no-repeat;
20+
padding: calc(2 * var(--base-spacing)) calc(2 * var(--base-spacing))
21+
calc(2 * var(--base-spacing)) calc(5 * var(--base-spacing));
22+
border-radius: 4px;
23+
background-size: 16px;
24+
background-position: 10px 15px;
25+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class HtmlRenderer(rootPackage: Member, members: Map[DRI, Member])(using ctx: Do
319319
div (id := "leftToggler")(
320320
span(cls := "icon-toggler")
321321
),
322-
// div(id := "scaladoc-searchBar"),
322+
div(id := "scaladoc-searchBar"),
323323
// main(id := "main-content")(
324324
// parentsHtml,
325325
// div(id := "content")(content),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ trait Resources(using ctx: DocContext) extends Locations, Writer:
9292
"styles/theme/layout/header.css",
9393
"styles/theme/layout/leftMenu.css",
9494
"styles/theme/layout/sideMenu.css",
95+
"styles/theme/layout/searchBar.css",
9596

9697
// components
9798
"styles/theme/components/switcher.css",

0 commit comments

Comments
 (0)