Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use navbar from Doge-Web-Components #4

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions themes/hello-friend-ng/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

(function () {
const themeToggle = document.querySelector(".theme-toggle");
const themeToggles = document.querySelectorAll('.theme-toggle');
const chosenTheme =
window.localStorage && window.localStorage.getItem("theme");
let chosenThemeIsDark = chosenTheme == "dark";
Expand Down Expand Up @@ -50,8 +50,10 @@
}

// Event listener
if (themeToggle) {
themeToggle.addEventListener("click", switchTheme, false);
if (themeToggles.length > 0) {
themeToggles.forEach(function(themeToggle) {
themeToggle.addEventListener("click", switchTheme, false);
});
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => e.matches && detectOSColorTheme());
Expand Down
94 changes: 70 additions & 24 deletions themes/hello-friend-ng/layouts/partials/header.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,71 @@
<header id="header" class="header">
<span class="header__inner">
{{ partial "logo.html" . }}
<doge-nav>
<doge-site-picker slot="brand" selected="foundation"></doge-site-picker>
{{ $pages := .Site.Pages }}
{{ range .Site.Menus.main -}}
{{ if .Children }}
<doge-nav-list>
<a slot="selected" href="{{ .URL | relLangURL }}">{{ .Name }} <small>▼</small></a>
{{ range .Children -}}
{{ $pageCollection := where $pages "Section" "==" .Identifier }}
{{ $pageCount := len $pageCollection }}
{{ if gt $pageCount 0}}
<a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
{{- end }}
{{- end }}
</doge-nav-list>
{{ else }}
<a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
{{ end }}

{{- end }}
<div>
{{- if .Site.Params.EnableThemeToggle }}
<span class="theme-toggle not-selectable">{{ partial "theme-toggle-icon.html" . }}</span>
{{- end}}
</div>
{{ partial "locale.html" . }}
<doge-nav-mobile slot="mobile">
<div slot="controls" class="mobile-controls">
<div>
{{- if .Site.Params.EnableThemeToggle }}
<span class="theme-toggle not-selectable">{{ partial "theme-toggle-icon.html" . }}</span>
{{- end}}
</div>
{{ partial "locale.html" . }}
</div>
{{ range .Site.Menus.main -}}
{{ if .Children }}
<span>{{ .Name }}</span>
{{ range .Children -}}
{{ $pageCollection := where $pages "Section" "==" .Identifier }}
{{ $pageCount := len $pageCollection }}
{{ if gt $pageCount 0}}
<a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
{{- end }}
{{- end }}
{{ else }}
<a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
{{ end }}
{{- end }}
</doge-nav-mobile>
</doge-nav>

<nav class="header__right">
{{ if len .Site.Menus }}
{{ partial "menu.html" . }}
<span class="menu-trigger">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>
</svg>
</span>
{{ end }}
<div class="divider"></div>
<span class="tooltip">
{{- if .Site.Params.EnableThemeToggle }}
<span title="Theme Toggle" class="theme-toggle not-selectable">{{ partial "theme-toggle-icon.html" . }}</span>
{{- end}}
</span>
<div class="divider"></div>
{{ partial "locale.html" . }}
</nav>
</span>
</header>
<style>
.mobile-controls {
display: flex;
justify-content: flex-end;
gap: 16px;
align-items: end;
}

.mobile-controls .locale {
min-width: unset;
}

.mobile-controls .locale:hover .locale-list {
left: unset !important;
right: 0px;
}
</style>

<script type="module" src="https://fetch.dogecoin.org/doge-nav.js"></script>
Loading