Skip to content

Commit d509440

Browse files
MatheusRichhsbt
authored andcommitted
Add support for mobile screen sizes on Darkfish
This adds support for reading the Darkfish-generated docs in mobile devices. I tried to keep the changes minimal, and the current layout was mostly preserved. The most notable change is the navigation sidebar, which is now hidden by default on "small screens" (everything below 1024px). It can be toggled by the button on the top left corner. This button implements the ARIA pattern for a [disclosure widget]. The icon for the button was taken from [Iconoir], which is licensed under the MIT license. The design and some of the implementation were loosely inspired by the [Elixir lang docs]. [disclosure widget]: https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/ [Iconoir]: https://iconoir.com/ [Elixir docs]: https://hexdocs.pm/elixir/1.15.2/Kernel.html
1 parent 9ed530b commit d509440

File tree

10 files changed

+131
-20
lines changed

10 files changed

+131
-20
lines changed

lib/rdoc/generator/template/darkfish/_head.rhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<meta charset="<%= @options.charset %>">
2+
<meta name="viewport" content="width=device-width, initial-scale=1" />
23

34
<title><%= h @title %></title>
45

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<button id="navigation-toggle" class="navigation-toggle" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
2+
<!--
3+
Copyright (c) 2021 Luca Burgio
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
-->
23+
<svg width="20px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000">
24+
<path d="M3 5h18M3 12h18M3 19h18" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
25+
</svg>
26+
</button>

lib/rdoc/generator/template/darkfish/class.rhtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<body id="top" role="document" class="<%= klass.type %>">
2-
<nav role="navigation">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
35
<div id="project-navigation">
46
<%= render '_sidebar_navigation.rhtml' %>
57
<%= render '_sidebar_search.rhtml' %>

lib/rdoc/generator/template/darkfish/css/rdoc.css

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ body {
1919
font-weight: 300;
2020

2121
/* Layout */
22-
display: grid;
23-
grid-template-columns: auto 1fr;
22+
display: flex;
23+
flex-wrap: wrap;
2424
}
2525

2626
body > :last-child {
27-
grid-column: 1 / 3;
27+
width: 100%;
2828
}
2929

3030
h1 span,
@@ -203,24 +203,40 @@ nav {
203203
font-family: Helvetica, sans-serif;
204204
font-size: 14px;
205205
border-right: 1px solid #ccc;
206-
position: sticky;
206+
position: fixed;
207207
top: 0;
208208
overflow: auto;
209+
z-index: 10;
209210

210211
/* Layout */
211-
width: 260px; /* fallback */
212-
width: max(50px, 20vw);
213-
min-width: 50px;
214-
max-width: 80vw;
215-
height: calc(100vh - 100px); /* reduce the footer height */
212+
width: 300px;
213+
min-height: 100vh;
214+
216215
resize: horizontal;
216+
background: white;
217+
}
218+
219+
@media (min-width: 1024px) {
220+
nav {
221+
min-height: unset;
222+
height: calc(100vh - 100px); /* reduce the footer height */
223+
}
217224
}
218225

219226
main {
220227
display: block;
221-
margin: 1em;
228+
margin: 3em 1em 1em;
222229
min-width: 340px;
223230
font-size: 16px;
231+
width: 100%;
232+
max-width: 64em;
233+
}
234+
235+
@media (min-width: 1024px) {
236+
main {
237+
margin-left: auto;
238+
margin-right: auto;
239+
}
224240
}
225241

226242
main h1,
@@ -232,8 +248,10 @@ main h6 {
232248
font-family: Helvetica, sans-serif;
233249
}
234250

235-
.table-of-contents main {
236-
margin-left: 2em;
251+
@media (min-width: 1024px) {
252+
.table-of-contents main {
253+
margin-left: 20em;
254+
}
237255
}
238256

239257
#validator-badges {
@@ -280,6 +298,39 @@ nav p {
280298
list-style: none;
281299
}
282300

301+
.navigation-toggle {
302+
position: fixed;
303+
left: 4px;
304+
top: 6px;
305+
z-index: 100;
306+
307+
background: transparent;
308+
border: none;
309+
cursor: pointer;
310+
margin-left: 7px;
311+
padding: 4px;
312+
}
313+
.navigation-toggle[aria-expanded="true"] {
314+
left: 260px;
315+
}
316+
317+
/* Adds a suble gradient to help the toggle stand out from the background */
318+
.navigation-toggle::before {
319+
content: "";
320+
background: linear-gradient(180deg, rgba(250,250,250,1) 40%, rgba(250,250,250,0.8) 70%, rgba(250,250,250,0) 100%);
321+
display: block;
322+
z-index: -1;
323+
pointer-events: none;
324+
position: fixed;
325+
top: 0;
326+
height: 50px;
327+
width: 100vw;
328+
}
329+
330+
.navigation-toggle[aria-expanded="true"]::before {
331+
height: 0;
332+
}
333+
283334
#project-navigation .nav-section {
284335
margin: 0;
285336
border-top: 0;
@@ -684,4 +735,3 @@ pre {
684735
}
685736

686737
/* @end */
687-

lib/rdoc/generator/template/darkfish/index.rhtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<body id="top" role="document" class="file">
2-
<nav role="navigation">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
35
<div id="project-navigation">
46
<%= render '_sidebar_navigation.rhtml' %>
57

lib/rdoc/generator/template/darkfish/js/darkfish.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,25 @@ function hookFocus() {
9090
});
9191
}
9292

93+
function hookSidebar() {
94+
var navigation = document.querySelector('#navigation');
95+
var navigationToggle = document.querySelector('#navigation-toggle');
96+
97+
navigationToggle.addEventListener('click', function() {
98+
navigation.hidden = !navigation.hidden;
99+
navigationToggle.ariaExpanded = navigationToggle.ariaExpanded !== 'true';
100+
});
101+
102+
var isSmallViewport = window.matchMedia("(max-width: 1024px)").matches;
103+
if (isSmallViewport) {
104+
navigation.hidden = true;
105+
navigationToggle.ariaExpanded = false;
106+
}
107+
}
108+
93109
document.addEventListener('DOMContentLoaded', function() {
94110
hookSourceViews();
95111
hookSearch();
96112
hookFocus();
113+
hookSidebar();
97114
});

lib/rdoc/generator/template/darkfish/page.rhtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<body id="top" role="document" class="file">
2-
<nav role="navigation">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
35
<div id="project-navigation">
46
<%= render '_sidebar_navigation.rhtml' %>
57
<%= render '_sidebar_search.rhtml' %>
@@ -15,4 +17,3 @@
1517
<main role="main" aria-label="Page <%=h file.full_name%>">
1618
<%= file.description %>
1719
</main>
18-

lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<body role="document">
2-
<nav role="navigation">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
35
<%= render '_sidebar_navigation.rhtml' %>
46

57
<%= render '_sidebar_search.rhtml' %>
@@ -15,4 +17,3 @@
1517

1618
<p><%= message %>
1719
</main>
18-

lib/rdoc/generator/template/darkfish/servlet_root.rhtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<body role="document">
2-
<nav role="navigation">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
35
<div id="project-navigation">
46
<div id="home-section" class="nav-section">
57
<h2>

lib/rdoc/generator/template/darkfish/table_of_contents.rhtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<body id="top" class="table-of-contents">
2+
<%= render '_sidebar_toggle.rhtml' %>
3+
4+
<nav id="navigation" role="navigation">
5+
<div id="project-navigation">
6+
<%= render '_sidebar_navigation.rhtml' %>
7+
8+
<%= render '_sidebar_search.rhtml' %>
9+
</div>
10+
</nav>
211
<main role="main">
312
<h1 class="class"><%= h @title %></h1>
413

0 commit comments

Comments
 (0)