Skip to content

Commit 4844f72

Browse files
authored
Merge pull request #1935 from ehuss/theme-dropdown-rendering-changes
Show the currently selected theme
2 parents c34c3bf + f32bd6f commit 4844f72

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl HtmlHandlebars {
340340
);
341341
handlebars.register_helper("previous", Box::new(helpers::navigation::previous));
342342
handlebars.register_helper("next", Box::new(helpers::navigation::next));
343+
// TODO: remove theme_option in 0.5, it is not needed.
343344
handlebars.register_helper("theme_option", Box::new(helpers::theme::theme_option));
344345
}
345346

@@ -630,6 +631,7 @@ fn make_data(
630631
);
631632
}
632633

634+
// TODO: remove default_theme in 0.5, it is not needed.
633635
let default_theme = match html_config.default_theme {
634636
Some(ref theme) => theme.to_lowercase(),
635637
None => "light".to_string(),

src/theme/book.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ function playground_text(playground) {
300300
themePopup.querySelector("button#" + get_theme()).focus();
301301
}
302302

303+
function updateThemeSelected() {
304+
themePopup.querySelectorAll('.theme-selected').forEach(function (el) {
305+
el.classList.remove('theme-selected');
306+
});
307+
themePopup.querySelector("button#" + get_theme()).classList.add('theme-selected');
308+
}
309+
303310
function hideThemes() {
304311
themePopup.style.display = 'none';
305312
themeToggleButton.setAttribute('aria-expanded', false);
@@ -355,6 +362,7 @@ function playground_text(playground) {
355362

356363
html.classList.remove(previousTheme);
357364
html.classList.add(theme);
365+
updateThemeSelected();
358366
}
359367

360368
// Set theme

src/theme/css/chrome.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ ul#searchresults span.teaser em {
507507
padding: 0;
508508
list-style: none;
509509
display: none;
510+
/* Don't let the children's background extend past the rounded corners. */
511+
overflow: hidden;
510512
}
511513
.theme-popup .default {
512514
color: var(--icons);
@@ -515,7 +517,7 @@ ul#searchresults span.teaser em {
515517
width: 100%;
516518
border: 0;
517519
margin: 0;
518-
padding: 2px 10px;
520+
padding: 2px 20px;
519521
line-height: 25px;
520522
white-space: nowrap;
521523
text-align: left;
@@ -527,8 +529,10 @@ ul#searchresults span.teaser em {
527529
.theme-popup .theme:hover {
528530
background-color: var(--theme-hover);
529531
}
530-
.theme-popup .theme:hover:first-child,
531-
.theme-popup .theme:hover:last-child {
532-
border-top-left-radius: inherit;
533-
border-top-right-radius: inherit;
532+
533+
.theme-selected::before {
534+
display: inline-block;
535+
content: "✓";
536+
margin-left: -14px;
537+
width: 14px;
534538
}

src/theme/index.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@
121121
<i class="fa fa-paint-brush"></i>
122122
</button>
123123
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
124-
<li role="none"><button role="menuitem" class="theme" id="light">{{ theme_option "Light" }}</button></li>
125-
<li role="none"><button role="menuitem" class="theme" id="rust">{{ theme_option "Rust" }}</button></li>
126-
<li role="none"><button role="menuitem" class="theme" id="coal">{{ theme_option "Coal" }}</button></li>
127-
<li role="none"><button role="menuitem" class="theme" id="navy">{{ theme_option "Navy" }}</button></li>
128-
<li role="none"><button role="menuitem" class="theme" id="ayu">{{ theme_option "Ayu" }}</button></li>
124+
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
125+
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
126+
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
127+
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
128+
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
129129
</ul>
130130
{{#if search_enabled}}
131131
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">

0 commit comments

Comments
 (0)