Skip to content

Commit a6b3c6b

Browse files
committed
feat: moved theme toggle next to search bar
1 parent eaf5e57 commit a6b3c6b

File tree

7 files changed

+58
-36
lines changed

7 files changed

+58
-36
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
]
2727
}
2828
}
29-
}
29+
}

_includes/sidebar.html

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@
4141
</nav>
4242

4343
<div class="sidebar-bottom d-flex flex-wrap align-items-center w-100">
44-
{% unless site.theme_mode %}
45-
<button type="button" class="btn btn-link nav-link" aria-label="Switch Mode" id="mode-toggle">
46-
<i class="fas fa-adjust"></i>
47-
</button>
48-
49-
{% if site.data.contact.size > 0 %}
50-
<span class="icon-border"></span>
51-
{% endif %}
52-
{% endunless %}
53-
5444
{% for entry in site.data.contact %}
5545
{% case entry.type %}
5646
{% when 'github', 'twitter' %}

_includes/topbar.html

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,55 @@
5454
{{- site.data.locales[include.lang].layout[page.layout] | default: page.layout | capitalize -}}
5555
{% endif %}
5656
</div>
57+
{% comment %} Container for buttons {% endcomment %}
58+
<div class="d-flex">
59+
{% unless site.theme_mode %}
60+
<button
61+
type="button"
62+
class="btn btn-link nav-link"
63+
aria-label="Switch Mode"
64+
id="mode-toggle"
65+
onClick="iconSwap()"
66+
>
67+
{% comment %} <i class="fas fa-adjust"></i> {% endcomment %}
68+
<i class="bi bi-brightness-high-fill"></i>
69+
</button>
70+
{% endunless %}
71+
<button type="button" id="search-trigger" class="btn btn-link" aria-label="Search">
72+
<i class="fas fa-search fa-fw"></i>
73+
</button>
5774

58-
<button type="button" id="search-trigger" class="btn btn-link" aria-label="Search">
59-
<i class="fas fa-search fa-fw"></i>
60-
</button>
61-
62-
<search id="search" class="align-items-center ms-3 ms-lg-0">
63-
<i class="fas fa-search fa-fw"></i>
64-
<input
65-
class="form-control"
66-
id="search-input"
67-
type="search"
68-
aria-label="search"
69-
autocomplete="off"
70-
placeholder="{{ site.data.locales[include.lang].search.hint | capitalize }}..."
71-
>
72-
</search>
73-
<button type="button" class="btn btn-link text-decoration-none" id="search-cancel">
74-
{{- site.data.locales[include.lang].search.cancel -}}
75-
</button>
75+
<search id="search" class="align-items-center">
76+
<i class="fas fa-search fa-fw"></i>
77+
<input
78+
class="form-control"
79+
id="search-input"
80+
type="search"
81+
aria-label="search"
82+
autocomplete="off"
83+
placeholder="{{ site.data.locales[include.lang].search.hint | capitalize }}..."
84+
>
85+
</search>
86+
<button type="button" class="btn btn-link text-decoration-none" id="search-cancel">
87+
{{- site.data.locales[include.lang].search.cancel -}}
88+
</button>
89+
{% comment %} Theme button {% endcomment %}
90+
</div>
7691
</div>
7792
</header>
93+
94+
<script>
95+
$toggle = document.getElementById('mode-toggle');
96+
if (Theme.visualState == 'dark') {
97+
$toggle.innerHTML = '<i class="bi bi-brightness-high-fill"></i>';
98+
} else if (Theme.visualState == 'light') {
99+
$toggle.innerHTML = '<i class="bi bi-moon-stars"></i>';
100+
}
101+
function iconSwap() {
102+
if (Theme.visualState == 'dark') {
103+
$toggle.innerHTML = '<i class="bi bi-moon-stars"></i>';
104+
} else if (Theme.visualState == 'light') {
105+
$toggle.innerHTML = '<i class="bi bi-brightness-high-fill"></i>';
106+
}
107+
}
108+
</script>

_javascript/modules/components/mode-toggle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Add listener for theme mode toggle
33
*/
44

5-
const $toggle = document.getElementById('mode-toggle');
6-
75
export function modeWatcher() {
6+
const $toggle = document.getElementById('mode-toggle');
7+
console.log('Mode watcher initialized');
88
if (!$toggle) {
99
return;
1010
}

_sass/base/_base.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@use '../abstracts/placeholders';
55
@use '../themes/light';
66
@use '../themes/dark';
7+
@import url("https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css");
78

89
:root {
910
font-size: 16px;

_sass/layout/_sidebar.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ $sidebar-display: 'sidebar-display'; /* the attribute for sidebar display */
225225
line-height: $btn-size;
226226
}
227227

228-
#mode-toggle {
229-
@extend %button;
230-
@extend %sidebar-links;
231-
@extend %sidebar-link-hover;
232-
}
228+
233229

234230
.icon-border {
235231
@extend %no-cursor;

_sass/layout/_topbar.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
}
1515
}
1616

17+
#mode-toggle {
18+
margin-right: 1.5rem;
19+
}
20+
1721
#topbar {
1822
@extend %btn-color;
1923

0 commit comments

Comments
 (0)