feat(tabs): better usage

This commit is contained in:
ZhenShuo Leo
2025-12-01 20:48:12 +08:00
parent 20044af981
commit eda9fc9bc3
7 changed files with 173 additions and 214 deletions

View File

@@ -1,5 +1,7 @@
{{- $index := .Parent.Scratch.Get "tab-index" | default 0 -}}
{{- .Parent.Scratch.Set "tab-index" (add 1 $index) -}}
<div class="tab__panel {{ if eq $index 0 }}tab--active{{ end }}" data-tab-index="{{ $index }}">
{{ .InnerDeindent | strings.TrimSpace | .Page.RenderString }}
</div>
{{- $label := .Get "label" -}}
{{- $index := .Parent.Store.Get "tab-index" | default 0 -}}
{{- $content := .InnerDeindent | strings.TrimSpace | .Page.RenderString -}}
{{- $tabs := .Parent.Store.Get "tabs" | default slice -}}
{{- .Parent.Store.Set "tabs" ($tabs | append (dict "label" $label "content" $content)) -}}
{{- .Parent.Store.Set "tab-index" (add 1 $index) -}}