Skip to content

Commit

Permalink
fix(collapse): use .Page.RenderString to render .Inner (#143)
Browse files Browse the repository at this point in the history
style(collapse): add the triangle indicator
feat(collapse): add the border and rounded named parameters
  • Loading branch information
razonyang authored Mar 21, 2024
1 parent 1ef241b commit dab07c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
15 changes: 15 additions & 0 deletions assets/mods/bootstrap/scss/_collapse.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.collapse-toggle {
padding-left: 0.25rem !important;

&::before {
content: "\2BC8";
margin-right: 0.25rem;
}

&[aria-expanded=true] {
&::before {
transform: rotate(90deg);
display: inline-block;
}
}
}
1 change: 1 addition & 0 deletions assets/mods/bootstrap/scss/index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'alert';
@import 'collapse';
31 changes: 23 additions & 8 deletions layouts/partials/bootstrap/collapse.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
{{- $heading := "" -}}
{{- $style := "primary" -}}
{{- $expand := false -}}
{{- $rounded := true -}}
{{- $border := true }}
{{- if .IsNamedParams -}}
{{- $heading = .Get "heading" -}}
{{- with .Get "style" }}{{ $style = . }}{{ end -}}
{{- with .Get "expand" }}{{ $expand = . }}{{ end -}}
{{- else -}}
{{- $heading = .Get 0 -}}
{{- with .Get "rounded" }}{{ $rounded = . }}{{ end -}}
{{- with .Get "border" }}{{ $border = . }}{{ 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-bg-%s px-2" 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 ps-2 pt-2 mb-3 border-top border-start border-%s%s" id="%s">%s</div>` $style (cond $expand ` show` ``) $id .Inner }}
{{- printf `<div class="collapse-wrapper mb-3">%s%s</div>` $heading $inner | safeHTML }}
<div
class="collapse-wrapper mb-3">
<a
type="button"
class="collapse-toggle text-decoration-none text-bg-{{ $style }} px-2"
data-bs-toggle="collapse"
href="#{{ $id }}"
aria-expanded="{{ cond $expand `true` `false` }}"
aria-controls="{{ $id }}">
{{- $heading -}}
</a>
<div
class="collapse{{ cond $border ` border` `` }}{{ cond $rounded ` rounded-bottom rounded-end` `` }} px-2 pt-2 pb-1 mb-3{{ cond $expand ` show` `` }}"
id="{{ $id }}">
{{ trim .Inner "\r\n" | .Page.RenderString }}
</div>
</div>

0 comments on commit dab07c4

Please sign in to comment.