Skip to content

Commit

Permalink
fix(collapse): allow nesting within the list
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Mar 20, 2024
1 parent 3eb2a4b commit c2d3c0a
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions layouts/partials/bootstrap/collapse.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
{{- $id := printf "collapse-%d" now.UnixNano }}
{{- $heading := "" }}
{{- $style := "primary" }}
{{- $expand := false }}
{{- if .IsNamedParams }}
{{- $heading = .Get "heading" }}
{{- with .Get "style" }}{{ $style = . }}{{ end }}
{{- with .Get "expand" }}{{ $expand = . }}{{ end }}
{{- else }}
{{- $heading = .Get 0 }}
{{- with .Get 1 }}{{ $style = . }}{{ end }}
{{- with .Get 2 }}{{ $expand = . }}{{ end }}
{{- end }}
<div
class="collapse-wrapper border-2 border-start border-{{ $style }} ps-3 mb-3">
<a
type="button"
class="collapse-toggle text-decoration-none text-{{ $style }} fw-bold"
data-bs-toggle="collapse"
href="#{{ $id }}"
aria-expanded="{{ cond $expand `true` `false` }}"
aria-controls="{{ $id }}">
{{- $heading -}}
</a>
<div class="collapse mt-2 mb-3{{ cond $expand ` show` `` }}" id="{{ $id }}">
{{ .Inner }}
</div>
</div>
{{- $id := printf "collapse-%d" now.UnixNano -}}
{{- $heading := "" -}}
{{- $style := "primary" -}}
{{- $expand := false -}}
{{- if .IsNamedParams -}}
{{- $heading = .Get "heading" -}}
{{- with .Get "style" }}{{ $style = . }}{{ end -}}
{{- with .Get "expand" }}{{ $expand = . }}{{ end -}}
{{- else -}}
{{- $heading = .Get 0 -}}
{{- with .Get 1 }}{{ $style = . }}{{ end -}}
{{- with .Get 2 }}{{ $expand = . }}{{ end -}}
{{- end -}}
{{- $heading := printf
`<a type="button" class="collapse-toggle text-decoration-none text-%s fw-bold" data-bs-toggle="collapse" href="#%s" aria-expanded="%s" aria-controls="%s">%s</a>`
$style $id (cond $expand `true` `false`) $id $heading
}}
{{- $inner := printf `<div class="collapse mt-2 mb-3%s" id="%s">%s</div>` (cond $expand ` show` ``) $id .Inner }}
{{- printf `<div class="collapse-wrapper border-2 border-start border-%s ps-3 mb-3">%s%s</div>` $style $heading $inner | safeHTML }}

0 comments on commit c2d3c0a

Please sign in to comment.