mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-12 04:23:14 +00:00
83 lines
3.5 KiB
HTML
83 lines
3.5 KiB
HTML
<!--
|
|
Copyright © 2024 The Hinode Team / Mark Dumay. All rights reserved.
|
|
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
|
|
Visit gethinode.com/license for more details.
|
|
-->
|
|
|
|
{{ $error := false }}
|
|
|
|
<!-- Validate arguments -->
|
|
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "nav" "child" "nav-item" "args" .Params "group" "shortcode") }}
|
|
{{ errorf "Invalid arguments: %s" .Position -}}
|
|
{{ $error = true }}
|
|
{{ end }}
|
|
|
|
<!-- Initialize arguments -->
|
|
{{- $id := .Get "id" | default (printf "nav-%d" .Ordinal) -}}
|
|
{{- $class := .Get "class" | default "" -}}
|
|
{{ $type := .Get "type" | default "" -}}
|
|
{{ $supportedNavTypes := slice "tabs" "pills" "underline" "callout" -}}
|
|
|
|
{{ $vertical := false -}}
|
|
{{ with .Get "vertical" }}{{ $vertical = partial "utilities/CastBool.html" . }}{{ end -}}
|
|
{{ $wrap := false -}}
|
|
{{ with .Get "wrap" }}{{ $wrap = partial "utilities/CastBool.html" . }}{{ end -}}
|
|
|
|
{{- if and (eq $type "tabs") $vertical -}}
|
|
{{- errorf "Tabs do not support vertical layout" -}}
|
|
{{- end -}}
|
|
|
|
{{ $inner := .Scratch.Get "inner" }}
|
|
{{ $input := trim .Inner " \r\n" }}
|
|
{{ if $input }}
|
|
{{ $input = replace $input "\n" "\n " }}
|
|
{{ warnf "Unexpected inner content: %s\r\n %s" .Position $input }}
|
|
{{ end }}
|
|
|
|
{{- $items := findRE "data-header=\"(.+?)\"" $inner -}}
|
|
{{- $showVal := findRE "data-show-id=\"(.+?)\"" $inner -}}
|
|
{{- $showID := -1 -}}
|
|
{{- if gt (len $showVal) 0 -}}
|
|
{{- $showID = int (partial "utilities/GetVal.html" (index $showVal 0)) -}}
|
|
{{- end -}}
|
|
|
|
{{ $disabled := slice -}}
|
|
{{- $disabledVal := findRE "data-disabled-id=\"(.+?)\"" $inner -}}
|
|
{{- range $item := $disabledVal -}}
|
|
{{- $disabled = $disabled | append (int (partial "utilities/GetVal.html" $item)) -}}
|
|
{{- end -}}
|
|
|
|
{{- $hasContent := gt (len (findRE "data-has-content=\"true\"" $inner)) 0 -}}
|
|
|
|
{{ $alternative := .Scratch.Get "alternative" }}
|
|
{{ if and (eq $type "callout") $alternative }}
|
|
<div class="d-lg-none">
|
|
<div id="accordion-{{ $id }}" class="accordion mb-3{{ with $class }} {{ . }}{{ end }} nav-callout">
|
|
{{- $alternative | safeHTML -}}
|
|
</div>
|
|
</div>
|
|
<div class="d-none d-lg-block">
|
|
{{ end }}
|
|
|
|
<!-- Main code -->
|
|
<div class="nav{{ with $type }} nav-{{ . }}{{ end }}{{ with $class }} {{ . }}{{ end }}{{ if $vertical }} flex-column{{ end }}" id="{{ $id }}" role="tablist"{{ if $vertical }} aria-orientation="vertical"{{ end }}>
|
|
{{ if $vertical }}<div class="row"><div class="col-auto">{{ end }}
|
|
{{- range $index, $item := $items -}}
|
|
{{- $header := partial "utilities/GetVal.html" $item -}}
|
|
{{- $itemDisabled := in $disabled $index -}}
|
|
<button class="nav-link{{ if not $wrap }} text-nowrap{{ end }}{{ if eq $index $showID }} active{{ end }}{{ if $itemDisabled}} disabled {{end }}" id="{{ $id }}-btn-{{ $index }}" data-bs-toggle="pill" data-bs-target="#{{ $id }}-{{ $index }}"
|
|
type="button" role="tab" aria-controls="{{ $id }}-{{ $index }}" aria-selected="{{ if eq $index 0 }}true{{ else }}false{{ end }}">
|
|
{{ $header }}
|
|
</button>
|
|
{{ end -}}
|
|
{{ if $vertical }}</div><div class="col">{{ end }}
|
|
{{- if $hasContent -}}
|
|
<div class="tab-content w-100 {{ if not $vertical }} {{ end }}{{ if eq $type "tabs" }}border border-bottom-0 p-3{{ else if $vertical }}ms-3{{ else }}mt-3{{ end }}">
|
|
{{- $inner | safeHTML -}}
|
|
</div>
|
|
{{- end -}}
|
|
{{ if $vertical }}</div></div>{{ end }}
|
|
</div>
|
|
|
|
{{ if and (eq $type "callout") $alternative }}</div>{{ end }}
|