Compare commits

...

8 Commits

Author SHA1 Message Date
Mark Dumay
6fe0df9466 Merge pull request #203 from gethinode/develop
Navbar
2023-04-09 15:20:59 +02:00
mark
2fc134503c Bump release version 2023-04-09 15:14:11 +02:00
mark
f11e98367b Change navbar size 2023-04-09 15:13:31 +02:00
mark
0ad4875ee2 Improve mode selector behavior 2023-04-09 15:13:11 +02:00
mark
a227a01407 Hide language label unless collapsed 2023-04-09 15:12:37 +02:00
mark
a8c8546c23 Add mode param 2023-04-09 15:11:20 +02:00
mark
0aa2a0427b Add mode param 2023-04-09 15:10:27 +02:00
mark
3047f8e937 Support multiple selectors 2023-04-09 15:10:01 +02:00
7 changed files with 94 additions and 44 deletions

View File

@@ -28,17 +28,24 @@
setTheme(getPreferredTheme())
const showActiveTheme = theme => {
const activeSelector = document.querySelector('.theme-icon-active')
const activeButton = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const activeIcon = activeButton.querySelector('i')
const activeSelectors = document.querySelectorAll('.theme-icon-active')
const activeButtons = document.querySelectorAll(`[data-bs-theme-value="${theme}"]`)
if (activeButtons.length > 0) {
const activeIcon = activeButtons[0].querySelector('i')
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
})
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
})
activeSelector.className = activeIcon.className
activeSelector.className = activeSelector.className.replace('theme-icon', 'theme-icon-active')
activeButton.classList.add('active')
for (let i = 0; i < activeSelectors.length; ++i) {
activeSelectors[i].className = activeIcon.className
activeSelectors[i].className = activeSelectors[i].className.replace('theme-icon', 'theme-icon-active')
}
for (let i = 0; i < activeButtons.length; ++i) {
activeButtons[i].classList.add('active')
}
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {

View File

@@ -198,7 +198,7 @@ As an example, the following shortcode displays a light navigation header.
<!-- markdownlint-disable MD037 -->
{{< example lang="hugo" >}}
{{</* navbar path="about" color="primary" size="sm" search="false" menus="sample" title="Brand" */>}}
{{</* navbar path="about" color="primary" size="md" search="false" menus="sample" title="Brand" */>}}
{{< /example >}}
<!-- markdownlint-enable MD037 -->

View File

@@ -198,7 +198,7 @@ De volgende shortcode toont een navigatiemenu.
<!-- markdownlint-disable MD037 -->
{{< example lang="hugo" >}}
{{</* navbar path="about" color="primary" size="sm" search="false" menus="sample" title="Brand" */>}}
{{</* navbar path="about" color="primary" size="md" search="false" menus="sample" title="Brand" */>}}
{{< /example >}}
<!-- markdownlint-enable MD037 -->

View File

@@ -6,12 +6,47 @@
"fixed" Optional flag to indicate the navbar should stick to the top, defaults to false.
"color" Optional background color of the navbar, either "primary", "secondary", "success",
"danger", "warning", "info", "light", "dark", "white" or "black". The default color is none.
"mode" Optional flag to include a color mode switcher, default is "true" (if dark mode is enabled).
"search" Optional flag to include a search input, default is "true".
"logo" Optional address of the logo image, defaults to the parameter "logo" set in the "main" section of
the site's parameter configuration.
"title" Optional brand title, displayed when the logo is not set. Defaults to the site's title.
-->
<!-- Inline partial to render the color mode switcher -->
{{- define "partials/navbar-mode.html" -}}
{{- $id := .id -}}
{{- $size := .size -}}
{{- $collapsed := .collapsed -}}
<li class="nav-item dropdown {{ if $collapsed }}d-{{ $size }}-none{{ else }}d-none d-{{ $size }}-block{{ end }}">
<a class="nav-link dropdown-toggle" href="#!" role="button" data-bs-toggle="dropdown" aria-expanded="false" id="navbar-color-theme">
{{- partial "assets/icon.html" (dict "icon" "fas sun theme-icon-active") }} {{ if $collapsed }} {{ T "colorMode" }} {{ end }}
<span class="d-md-none"></span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbar-color-theme">
<li>
<a class="dropdown-item" data-bs-theme-value="light" href="#!" {{ if $collapsed }}data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent-{{ $id }}"{{ end }}>
{{- partial "assets/icon.html" (dict "icon" "fas sun theme-icon") }}
{{ T "colorLight" }}
</a>
</li>
<li>
<a class="dropdown-item" data-bs-theme-value="dark" href="#!" {{ if $collapsed }}data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent-{{ $id }}"{{ end }}>
{{- partial "assets/icon.html" (dict "icon" "fas moon theme-icon") }}
{{ T "colorDark" }}
</a>
</li>
<li>
<a class="dropdown-item" data-bs-theme-value="auto" href="#!" {{ if $collapsed }}data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent-{{ $id }}"{{ end }}>
{{- partial "assets/icon.html" (dict "icon" "fas circle-half-stroke theme-icon" ) }}
{{ T "colorAuto" }}
</a>
</li>
</ul>
</li>
{{- end -}}
{{- $supportedFlags := slice "true" "false" -}}
{{- $id := 0 -}}
@@ -65,6 +100,15 @@
{{- end -}}
{{- $enableDarkMode := default true site.Params.main.enableDarkMode -}}
{{- with .mode -}}
{{- $darkModeParam := . -}}
{{- if in $supportedFlags $darkModeParam -}}
{{- if eq $darkModeParam "true" }}{{ $enableDarkMode = site.Params.main.enableDarkMode }}{{ else }}{{ $enableDarkMode = false }}{{ end -}}
{{- else -}}
{{- errorf "Invalid value for param 'darkMode': %s" $darkModeParam -}}
{{- end -}}
{{- end -}}
{{- $enableLanguage := or $page.IsTranslated site.IsMultiLingual -}}
{{- $logo := site.Params.navigation.logo -}}
@@ -164,9 +208,12 @@
{{- if $enableLanguage -}}
{{- $currentLang := $page.Language.Lang -}}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#!" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<a class="nav-link dropdown-toggle d-{{ $size }}-none" href="#!" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{- partial "assets/icon.html" (dict "icon" "fas globe") }} {{ T "languageSwitcherLabel" }}
</a>
<a class="nav-link dropdown-toggle d-none d-{{ $size }}-block" href="#!" role="button" data-bs-toggle="dropdown" aria-expanded="false">
{{- partial "assets/icon.html" (dict "icon" "fas globe") }}
</a>
<ul class="dropdown-menu dropdown-menu-end ">
{{- if $page.IsTranslated -}}
{{- range $page.AllTranslations -}}
@@ -183,32 +230,8 @@
<!-- Insert color mode switcher -->
{{- if $enableDarkMode -}}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#!" role="button" data-bs-toggle="dropdown" aria-expanded="false" id="navbar-color-theme">
{{- partial "assets/icon.html" (dict "icon" "fas sun theme-icon-active") }}
<span class="d-md-none"></span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbar-color-theme">
<li>
<a class="dropdown-item" data-bs-theme-value="light" href="#!">
{{- partial "assets/icon.html" (dict "icon" "fas sun theme-icon") }}
{{ T "colorLight" }}
</a>
</li>
<li>
<a class="dropdown-item" data-bs-theme-value="dark" href="#!">
{{- partial "assets/icon.html" (dict "icon" "fas moon theme-icon") }}
{{ T "colorDark" }}
</a>
</li>
<li>
<a class="dropdown-item" data-bs-theme-value="auto" href="#!">
{{- partial "assets/icon.html" (dict "icon" "fas circle-half-stroke theme-icon" ) }}
{{ T "colorAuto" }}
</a>
</li>
</ul>
</li>
{{- partial "partials/navbar-mode.html" (dict "id" $id "size" $size "collapsed" true) -}}
{{- partial "partials/navbar-mode.html" (dict "id" $id "size" $size "collapsed" false) -}}
{{- end -}}
</ul>
</div>

View File

@@ -8,12 +8,15 @@
"style" Optional style of the navbar, either "light" (default) or "dark".
"color" Optional background color of the navbar, either "primary", "secondary", "success",
"danger", "warning", "info", "light", "dark", "white" or "black". The default color is none.
"mode" Optional flag to include a color mode switcher, default is "true" (if dark mode is enabled).
"search" Optional flag to include a search input, default is "true".
"logo" Optional address of the logo image.
"title" Optional brand title, displayed when the logo is not set.
-->
{{ $error := false }}
{{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "white" "black" "body" -}}
{{ $supportedFlags := slice "true" "false" -}}
{{ $id := add .Ordinal 1 }}
@@ -49,7 +52,6 @@
{{ $color := "" -}}
{{ with .Get "color" }}
{{ $color = . }}
{{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "white" "black" "body" -}}
{{ if not (in $supportedColors $color) -}}
{{ errorf "Invalid value for param 'color': %s" $color -}}
{{ $error = true -}}
@@ -58,12 +60,18 @@
{{ $searchParam := "true" -}}
{{ with .Get "search" }}{{ $searchParam = . }}{{ end -}}
{{ $supportedFlags := slice "true" "false" -}}
{{ if not (in $supportedFlags $searchParam) -}}
{{ errorf "Invalid value for param 'search': %s" .Position -}}
{{ $error = true -}}
{{ end -}}
{{ $modeParam := "true" -}}
{{ with .Get "mode" }}{{ $modeParam = . }}{{ end -}}
{{ if not (in $supportedFlags $modeParam) -}}
{{ errorf "Invalid value for param 'mode': %s" .Position -}}
{{ $error = true -}}
{{ end -}}
{{ $logo := "" -}}
{{ with .Get "logo" }}{{ $logo = . }}{{ end -}}
@@ -71,5 +79,17 @@
{{ with .Get "title" }}{{ $title = . }}{{ end -}}
{{ if not $error -}}
{{- partial "assets/navbar.html" (dict "id" $id "page" $page "size" $size "style" $style "color" $color "search" $searchParam "menus" $menus "logo" $logo "title" $title) -}}
{{- partial "assets/navbar.html" (dict
"id" $id
"page" $page
"size" $size
"style" $style
"color" $color
"search" $searchParam
"mode" $modeParam
"menus" $menus
"logo" $logo
"title" $title
)
-}}
{{ end -}}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@gethinode/hinode",
"version": "0.11.5",
"version": "0.11.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@gethinode/hinode",
"version": "0.11.5",
"version": "0.11.6",
"license": "MIT",
"devDependencies": {
"@fortawesome/fontawesome-free": "^6.4.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.11.5",
"version": "0.11.6",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",