From 6613f94b75d78c3b48ed083e09916498c87adbf2 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 16 Aug 2025 17:46:15 +0200 Subject: [PATCH] feat(navbar): toggle theme inside navbar (#759) * feat(theme-toggle): toggle inside navbar * chore: used partial parameters * chore: create a constant for icons height inside navbar * feat: better style integration * review: invert enable label option * review: change class value * review Co-authored-by: Xin <5097752+imfing@users.noreply.github.com> * docs: theme toggle * docs: translations --------- Co-authored-by: Xin <5097752+imfing@users.noreply.github.com> --- exampleSite/content/docs/guide/configuration.fa.md | 6 ++++++ exampleSite/content/docs/guide/configuration.ja.md | 6 ++++++ exampleSite/content/docs/guide/configuration.md | 6 ++++++ exampleSite/content/docs/guide/configuration.zh-cn.md | 6 ++++++ layouts/_partials/navbar.html | 7 +++++-- layouts/_partials/theme-toggle.html | 11 ++++++----- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/exampleSite/content/docs/guide/configuration.fa.md b/exampleSite/content/docs/guide/configuration.fa.md index 580eb0d..56dd74b 100644 --- a/exampleSite/content/docs/guide/configuration.fa.md +++ b/exampleSite/content/docs/guide/configuration.fa.md @@ -64,6 +64,12 @@ menu: params: icon: github ``` +5. تبديل السمة + ```yaml + - name: Theme Toggle + params: + type: theme-toggle + ``` این آیتم‌های منو را می‌توان با تنظیم پارامتر `weight` مرتب کرد. diff --git a/exampleSite/content/docs/guide/configuration.ja.md b/exampleSite/content/docs/guide/configuration.ja.md index 4a26143..b34e1c6 100644 --- a/exampleSite/content/docs/guide/configuration.ja.md +++ b/exampleSite/content/docs/guide/configuration.ja.md @@ -64,6 +64,12 @@ menu: params: icon: github ``` +5. テーマ切り替え + ```yaml + - name: Theme Toggle + params: + type: theme-toggle + ``` これらのメニュー項目は `weight` パラメータを設定することで並べ替えられます。 diff --git a/exampleSite/content/docs/guide/configuration.md b/exampleSite/content/docs/guide/configuration.md index 85d758c..a452c33 100644 --- a/exampleSite/content/docs/guide/configuration.md +++ b/exampleSite/content/docs/guide/configuration.md @@ -64,6 +64,12 @@ There are different types of menu items: params: icon: github ``` +5. Theme Toggle + ```yaml + - name: Theme Toggle + params: + type: theme-toggle + ``` These menu items can be sorted by setting the `weight` parameter. diff --git a/exampleSite/content/docs/guide/configuration.zh-cn.md b/exampleSite/content/docs/guide/configuration.zh-cn.md index 0796b91..02b4f9f 100644 --- a/exampleSite/content/docs/guide/configuration.zh-cn.md +++ b/exampleSite/content/docs/guide/configuration.zh-cn.md @@ -64,6 +64,12 @@ menu: params: icon: github ``` +5. 主题切换 + ```yaml + - name: Theme Toggle + params: + type: theme-toggle + ``` 通过设置 `weight` 参数可以调整菜单项的排序。 diff --git a/layouts/_partials/navbar.html b/layouts/_partials/navbar.html index 007768c..c69b8ae 100644 --- a/layouts/_partials/navbar.html +++ b/layouts/_partials/navbar.html @@ -7,6 +7,7 @@ {{ end -}} {{- end -}} +{{- $iconHeight := 24 -}}
- {{- partial "utils/icon.html" (dict "name" .Params.icon "attributes" "height=24") -}} + {{- partial "utils/icon.html" (dict "name" .Params.icon "attributes" (printf "height=%d" $iconHeight)) -}} {{ or (T .Identifier) .Name | safeHTML }} + {{- else if eq .Params.type "theme-toggle" -}} + {{- partial "theme-toggle.html" (dict "iconHeight" $iconHeight "class" "hx:p-2" "hideLabel" (not .Params.label)) -}} {{- else -}} {{- $active := or ($currentPage.HasMenuCurrent "main" .) ($currentPage.IsMenuCurrent "main" .) -}} {{- $activeClass := cond $active "hx:font-medium" "hx:text-gray-600 hx:hover:text-gray-800 hx:dark:text-gray-400 hx:dark:hover:text-gray-200" -}} @@ -94,7 +97,7 @@
diff --git a/layouts/_partials/theme-toggle.html b/layouts/_partials/theme-toggle.html index 3fe5d8c..2501ea8 100644 --- a/layouts/_partials/theme-toggle.html +++ b/layouts/_partials/theme-toggle.html @@ -1,21 +1,22 @@ -{{- $hideLabel := .hideLabel | default false -}} +{{- $hideLabel := .hideLabel -}} +{{- $iconHeight := .iconHeight | default 12 -}} +{{- $class := .class | default "hx:px-2 hx:text-xs hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:font-medium hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400" -}} {{- $changeTheme := (T "changeTheme") | default "Change theme" -}} {{- $light := (T "light") | default "Light" -}} {{- $dark := (T "dark") | default "Dark" -}} -