-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding shortcode for accordion component (Bootstrap 5)
- Loading branch information
Showing
6 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import "shortcodes/tabbed-pane.scss"; | ||
@import "shortcodes/cards-pane.scss"; | ||
@import "shortcodes/accordion.scss"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.accordion { | ||
--bs-accordion-bg: #fff important; | ||
max-width: 80%; | ||
} | ||
|
||
.accordion-button:not(.collapsed) { | ||
background-color: #e7f1ff; | ||
} | ||
|
||
.accordion-button:focus { | ||
box-shadow: none; | ||
} | ||
|
||
.accordion-collapse.show, .accordion-collapse.open | ||
{ | ||
--bs-accordion-border-width: 0px important; | ||
border-left: 1px solid #dee2e6; | ||
border-right: 1px solid #dee2e6; | ||
} | ||
|
||
.accordion-item { | ||
--bs-accordion-border-width: 0px important; | ||
} | ||
|
||
.accordion-item:last-of-type { | ||
border-bottom: 1px solid #dee2e6; | ||
} | ||
|
||
.accordion-button { | ||
--bs-accordion-border-width: 1px important; | ||
border: 1px solid #dee2e6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{- /* Make sure that we are enclosed within a accordion shortcode block */ -}} | ||
{{ with $.Parent -}} | ||
{{ if ne $.Parent.Name "accordion" -}} | ||
{{ errorf "shortcode 'accordion-item' must be used within an 'accordion' block" -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{ $header := "Header" -}} | ||
{{ if and (not .IsNamedParams) (.Get 0) -}} | ||
{{ $header = (.Get 0) -}} | ||
{{ else -}} | ||
{{/* Prefill header if not given as named or unnamed parameter */ -}} | ||
{{ $header = default (printf "Header %v" ( add $.Ordinal 1)) (.Get "header") -}} | ||
{{ end -}} | ||
|
||
{{/* store all tab info in dict item */ -}} | ||
{{ $item := dict "header" $header -}} | ||
{{ with $.Get "open" -}} | ||
{{ if ne ( printf "%T" . ) "bool" -}} | ||
{{ errorf "shortcode 'accordion-item': parameter 'open' must be either true or false" -}} | ||
{{ end -}} | ||
{{ $item = merge $item (dict "open" ($.Get "open")) -}} | ||
{{ end -}} | ||
|
||
{{ with $.Inner -}} | ||
{{ $item = merge $item (dict "content" $.Inner) -}} | ||
{{ end -}} | ||
|
||
{{/* add dict tab to parent's scratchpad */ -}} | ||
{{ with .Parent -}} | ||
{{ $.Parent.Scratch.SetInMap "items" (printf "%02v" $.Ordinal) $item -}} | ||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{{/* Check parameter type */ -}} | ||
{{ with .Get "alwaysOpen" -}} | ||
{{ warnf "Always open given" }} | ||
{{ $type := printf "%T" . -}} | ||
{{ if ne $type "bool" -}} | ||
{{ errorf `shortcode 'accordion': boolean value expected for parameter 'alwaysOpen', but got %s` $type -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{ $alwaysOpen := default false ($.Get "alwaysOpen") -}} | ||
|
||
{{- /* Scratchpad gets populated through call to .Inner */ -}} | ||
{{- .Inner -}} | ||
|
||
{{/* Accordion markup */ -}} | ||
<div id="accordion-{{- $.Ordinal -}}" class="accordion mb-4"> | ||
{{ range $index, $element := $.Scratch.Get "items" -}} | ||
{{ $itemid := printf "-%02v-%v" $.Ordinal $index | anchorize -}} | ||
|
||
{{ $open := false -}} | ||
{{ with $element.open -}} | ||
{{ $open = . -}} | ||
{{ end -}} | ||
|
||
<div class="accordion-item"> | ||
<div class="accordion-header" id="heading{{- $itemid -}}"> | ||
<button class="accordion-button {{- cond ( eq $index "00" ) "" " collapsed" -}}" type="button" data-bs-toggle="collapse" data-bs-target="#collapse{{- $itemid -}}" | ||
aria-controls="collapse{{- $itemid -}}" aria-expanded="{{- cond ( eq $index "00" ) "true" "false" -}}"> | ||
{{ index . "header" | markdownify }} | ||
</button> | ||
</div> | ||
<div id="collapse{{- $itemid -}}" class="accordion-collapse {{ cond $open "open" "collapse" }} {{- cond ( eq $index "00" ) " show" "" -}}" | ||
aria-labelledby="heading{{- $itemid -}}" {{ if not $alwaysOpen -}}data-bs-parent="#accordion-{{- $.Ordinal -}}"{{- end }}> | ||
<div class="accordion-body"> | ||
{{ index . "content" }} | ||
</div> | ||
</div> | ||
</div> | ||
{{- end }} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters