{{ $error := false }} {{ $type := "button" -}} {{- $icon := .Get "icon" | default "" }} {{ $title := trim .Inner " \r\n" | .Page.RenderString -}} {{ if not (or $title $icon) -}} {{ errorf "Missing icon or inner element text: %s" .Position -}} {{ $error = true }} {{ end -}} {{ $state := "enabled" -}} {{ with .Get "state" }}{{ $state = . }}{{ end -}} {{ $supportedStates := slice "enabled" "disabled" "active" "inactive" -}} {{ if not (in $supportedStates $state) -}} {{ errorf "Invalid value for param 'state': %s" .Position -}} {{ $error = true }} {{ end -}} {{ $size := "md" -}} {{ with .Get "size" }}{{ $size = . }}{{ end -}} {{ $supportedSizes := slice "sm" "md" "lg" -}} {{ if not (in $supportedSizes $size) -}} {{ errorf "Invalid value for param 'size': %s" .Position -}} {{ end -}} {{ $color := "primary" -}} {{ with .Get "color" }}{{ $color = . }}{{ end -}} {{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "white" "black" -}} {{ if not (in $supportedColors $color) -}} {{ errorf "Invalid value for param 'color': %s" .Position -}} {{ $error = true }} {{ end -}} {{ $outlineParam := "false" -}} {{ $outline := false -}} {{ with .Get "outline" }}{{ $outlineParam = . }}{{ end -}} {{ $supportedFlags := slice "true" "false" -}} {{ if in $supportedFlags $outlineParam -}} {{ if eq $outlineParam "true" }}{{ $outline = true }}{{ end -}} {{ else -}} {{ errorf "Invalid value for param 'outline': %s" .Position -}} {{ end -}} {{ $badge := .Get "badge" | default "" -}} {{ $label := .Get "aria-label" | default "" -}} {{ $tooltip := .Get "tooltip" | default "" -}} {{ $collapse := .Get "collapse" | default "" -}} {{ $href := .Get "href" | default "" -}} {{ $relref := .Get "relref" | default "" -}} {{ $id := .Get "id" | default "" -}} {{ if $relref }} {{ $href = relref . $relref }} {{ end }} {{ $class := .Get "class" | default "" -}} {{ $placement := "top" -}} {{ with .Get "placement" }}{{ $placement = . }}{{ end -}} {{ $supportedPlacements := slice "top" "bottom" "left" "right" -}} {{ if not (in $supportedPlacements $placement) -}} {{ errorf "Invalid value for param 'placement': %s" .Position -}} {{ $error = true }} {{ end -}} {{- $toast := .Get "toast" | default "" -}} {{- $order := "last" -}} {{- with .Get "order" }}{{ $order = . }}{{ end -}} {{- $supportedOrders := slice "first" "last" -}} {{- if not (in $supportedOrders $order) -}} {{ errorf "Invalid value for param 'order': %s" .Position -}} {{ $error = true }} {{- end -}} {{- $justify := "center" -}} {{- with .Get "justify" }}{{ $justify = . }}{{ end -}} {{- $supportedJustify := slice "start" "end" "center" "between" "around" "evenly" -}} {{- if not (in $supportedJustify $justify) -}} {{ errorf "Invalid value for param 'justify': %s" .Position -}} {{ $error = true }} {{- end -}} {{- $cue := .Get "cue" | default site.Params.main.externalLinks.cue -}} {{- $tab := .Get "tab" | default site.Params.main.externalLinks.tab -}} {{ if not $error }} {{- $output := partial "assets/button.html" (dict "type" $type "title" $title "size" $size "color" $color "outline" $outline "badge" $badge "label" $label "tooltip" $tooltip "collapse" $collapse "href" $href "id" $id "state" $state "class" $class "placement" $placement "icon" $icon "order" $order "justify" $justify "cue" $cue "tab" $tab "toast" $toast) -}} {{- if .Parent -}} {{ $current := .Parent.Scratch.Get "inner" }} {{ if $current }} {{ .Parent.Scratch.Set "inner" (print $current $output) }} {{ else }} {{ .Parent.Scratch.Set "inner" $output }} {{ end }} {{- else -}} {{ $output | safeHTML }} {{- end -}} {{ end }}