Files
hinode/layouts/shortcodes/tooltip.html
2023-08-31 13:34:23 +02:00

50 lines
1.9 KiB
HTML

<!--
Displays a tooltip for a link. The shortcode supports the following arguments:
"color": Optional theme color of the element, either "primary" (default), "secondary", "success",
"danger", "warning", "info", "light", or "dark".
"title" Required plain text to display in the tooltip.
"href" Required address for the button or hyperlink.
"placement" Optional position of the tooltip: "top" (default), "bottom", "left", or "right".
"class" Optional class attribute of the tooltip's button element.
-->
{{ $error := false }}
{{ $type := "link" -}}
{{ $title := trim .Inner " \r\n" | plainify -}}
{{ if not $title -}}
{{ errorf "Missing inner element text: %s" .Position -}}
{{ $error = true }}
{{ end -}}
{{ $color := "primary" -}}
{{ with .Get "color" }}{{ $color = . }}{{ end -}}
{{ $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" -}}
{{ if not (in $supportedColors $color) -}}
{{ errorf "Invalid value for param 'color': %s" .Position -}}
{{ $error = true }}
{{ end -}}
{{ $tooltip := .Get "title" | default "" -}}
{{ $href := .Get "href" | default "" -}}
{{ if not $href -}}
{{ errorf "Missing value for param 'href': %s" .Position -}}
{{ $error = true }}
{{ end -}}
{{ $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 -}}
{{- $class := .Get "class" | default "" -}}
{{ if not $error }}
<div class="d-inline-flex">
{{- partial "assets/button.html" (dict "type" $type "title" $title "color" $color "tooltip" $tooltip "href" $href "placement" $placement "class" $class) -}}
</div>
{{ end }}