Files
hextra_mirror/layouts/_partials/theme-toggle.html
Ludovic Fernandez 6613f94b75 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>
2025-08-16 16:46:15 +01:00

23 lines
1.2 KiB
HTML

{{- $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" -}}
<button
title="{{ $changeTheme }}"
data-theme="light"
class="hextra-theme-toggle hx:cursor-pointer hx:group hx:rounded-md hx:text-left {{ $class }}"
type="button"
aria-label="{{ $changeTheme }}"
>
<div class="hx:flex hx:items-center hx:gap-2 hx:capitalize">
{{- partial "utils/icon.html" (dict "name" "sun" "attributes" (printf "height=%d class=\"hx:group-data-[theme=light]:hidden\"" $iconHeight)) -}}
{{- if not $hideLabel }}<span class="hx:group-data-[theme=light]:hidden">{{ $light }}</span>{{ end -}}
{{- partial "utils/icon.html" (dict "name" "moon" "attributes" (printf "height=%d class=\"hx:group-data-[theme=dark]:hidden\"" $iconHeight)) -}}
{{- if not $hideLabel }}<span class="hx:group-data-[theme=dark]:hidden">{{ $dark }}</span>{{ end -}}
</div>
</button>