Skip to content

Commit

Permalink
Merge pull request #1015 from gethinode/develop
Browse files Browse the repository at this point in the history
Support navbar buttons and spacing
  • Loading branch information
markdumay authored Jun 27, 2024
2 parents c962f93 + 741bff8 commit 55d73b3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
41 changes: 25 additions & 16 deletions layouts/partials/assets/navbar-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,29 @@

<!-- Main code -->
{{ if not $error }}
<a class="{{ $anchorClass }}{{ if $isActive }} active{{ end }}{{ with $class }} {{. }}{{ end }}"
{{ if $isIcon }}aria-label="{{ $menu.Name }}"{{ end }}
data-nav="main" data-nav-main="{{ $mainNav }}"{{ with $childNav }} data-nav-child="{{ . }}"{{ end }}
href="{{ $menuURL }}{{ $params | safeHTMLAttr }}"{{ with $externalHref }} {{ . | safeHTMLAttr }}{{ end }} {{ $button | safeHTMLAttr }}>

{{- with $menu.Pre }}
{{ if hasPrefix . "<i" }}
{{ . | safeHTML }}
{{ else }}
{{ partial "assets/icon.html" (dict "icon" (string .) )}}
{{ end }}
{{ end -}}
<span {{ if $isActive }} class="active"{{ end }}>{{ if not $isIcon }}{{ $menu.Name }}{{ end }}</span>
{{- with $menu.Post }}{{ . }}{{ end -}}
{{- if not $isIcon }}&nbsp;{{ $suffix }}{{ end -}}
</a>
{{ if $menu.Params.button }}
{{ partial "assets/button.html" (dict
"title" $menu.Name
"icon" $menu.Pre
"href" $menuURL
"size" "sm"
)}}
{{ else }}
<a class="{{ $anchorClass }}{{ if $isActive }} active{{ end }}{{ with $class }} {{. }}{{ end }}"
{{ if $isIcon }}aria-label="{{ $menu.Name }}"{{ end }}
data-nav="main" data-nav-main="{{ $mainNav }}"{{ with $childNav }} data-nav-child="{{ . }}"{{ end }}
href="{{ $menuURL }}{{ $params | safeHTMLAttr }}"{{ with $externalHref }} {{ . | safeHTMLAttr }}{{ end }} {{ $button | safeHTMLAttr }}>

{{- with $menu.Pre }}
{{ if hasPrefix . "<i" }}
{{ . | safeHTML }}
{{ else }}
{{ partial "assets/icon.html" (dict "icon" (string .) )}}
{{ end }}
{{ end -}}
<span {{ if $isActive }} class="active"{{ end }}>{{ if not $isIcon }}{{ $menu.Name }}{{ end }}</span>
{{- with $menu.Post }}{{ . }}{{ end -}}
{{- if not $isIcon }}&nbsp;{{ $suffix }}{{ end -}}
</a>
{{ end }}
{{ end }}
37 changes: 23 additions & 14 deletions layouts/partials/assets/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
{{- $contrast := false -}}
{{- if in (slice "primary" "secondary" "success" "danger") $color }}{{ $contrast = true }}{{ end -}}

{{- $flex := false }}
{{ if gt (where $menus "Params.spacing" true | len) 0 }}
{{ $flex = true }}
{{ end }}

<!-- Main code -->
<div class="container-fluid {{ if $fixed }}fixed-top{{ end }} p-0{{ with $class }} {{ . }}{{ end }}">
{{- partial "assets/page-alert.html" (dict "page" $page) -}}
Expand Down Expand Up @@ -225,23 +230,27 @@
{{- if and $search (not $searchModal) }}{{ partial "assets/search-input.html" }}{{ end -}}

<!-- Render top-menu items (maximum depth of 2) -->
<ul class="navbar-nav ms-auto">
<ul class="navbar-nav {{ if $flex }}d-flex w-100{{ else }}ms-auto{{ end }}">
{{- range $menu := $menus -}}
<li class="nav-item{{ if .HasChildren }} dropdown{{ if $horizontal }} dropdown-horizontal-{{ $size }}{{ end }}{{ end }}">
{{- partial "assets/navbar-item.html" (dict "menu" $menu "page" $page) -}}
{{- if .HasChildren -}}
<ul class="dropdown-menu">
{{- range .Children -}}
<li>{{- partial "assets/navbar-item.html" (dict "menu" . "parent" $menu "page" $page) -}}</li>
{{- end -}}
</ul>
{{- end -}}
</li>
{{ if $menu.Params.spacing }}
<li class="nav-item flex-grow-1"></li>
{{ else }}
<li class="nav-item {{ if .HasChildren }} dropdown{{ if $horizontal }} dropdown-horizontal-{{ $size }}{{ end }}{{ end }}">
{{- partial "assets/navbar-item.html" (dict "menu" $menu "page" $page) -}}
{{- if .HasChildren -}}
<ul class="dropdown-menu">
{{- range .Children -}}
<li>{{- partial "assets/navbar-item.html" (dict "menu" . "parent" $menu "page" $page) -}}</li>
{{- end -}}
</ul>
{{- end -}}
</li>
{{- end -}}
{{- end -}}

<!-- Insert divider if applicable -->
{{- if and $menus (or $enableLanguage $enableVersions) -}}
<li class="nav-item py-2 py-md-1 col-12 col-md-auto d-none d-{{ $size }}-block">
<li class="nav-item py-2 py-md-1 col-12 col-md-auto d-none d-{{ $size }}-block me-auto">
<div class="vr d-none d-md-flex h-100 mx-md-2"></div>
</li>
<li><hr class="dropdown-divider-bg"></li>
Expand All @@ -256,7 +265,7 @@
<!-- Insert language switcher if applicable -->
{{- if $enableLanguage -}}
{{- $currentLang := $page.Language.Lang -}}
<li class="nav-item dropdown">
<li class="nav-item dropdown me-auto">
<a class="nav-link dropdown-toggle d-{{ $size }}-none" href="#!" role="button" data-bs-toggle="dropdown" aria-label="{{ T "languageSwitcherLabel" }}" aria-expanded="false">
{{- partial "assets/icon.html" (dict "icon" "fas globe fa-fw" "spacing" false) }}&nbsp;{{ T "languageSwitcherLabel" }}
</a>
Expand Down Expand Up @@ -284,7 +293,7 @@

<!-- Insert modal search button -->
{{- if $searchModal }}
<li class="nav-item py-2 py-md-1 col-12 col-md-auto d-none d-{{ $size }}-block">
<li class="nav-item py-2 py-md-1 col-12 col-md-auto d-none d-{{ $size }}-block me-auto">
<div class="vr d-none d-md-flex h-100 mx-md-2"></div>
</li>
<li><hr class="dropdown-divider-bg"></li>
Expand Down

0 comments on commit 55d73b3

Please sign in to comment.