Files
hinode/layouts/shortcodes/alert.html
2024-01-01 12:32:39 +01:00

48 lines
1.8 KiB
HTML

<!--
Copyright © 2024 The Hinode Team / Mark Dumay. All rights reserved.
Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
Visit gethinode.com/license for more details.
-->
{{ $error := false }}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "alert" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments -->
{{ $color := .Get "color" | default "danger" -}}
{{ $icon := .Get "icon" | default "" }}
{{ $type := .Get "type" | default "" -}}
{{ if eq $type "danger" }}
{{ $icon = "fas triangle-exclamation" }}
{{ $color = "danger" }}
{{ else if eq $type "info" }}
{{ $icon = "fa lightbulb" }}
{{ $color = "info" }}
{{ end }}
{{ with $icon }}
{{ $icon = partial "assets/icon.html" (dict "icon" (printf "%s fa-2x fa-fw" .)) }}
{{ end }}
{{ $dismissible := false -}}
{{ with .Get "dismissible" }}{{ $dismissible = partial "utilities/CastBool.html" . }}{{ end -}}
{{- $class := .Get "class" | default "" -}}
{{ $body := trim .Inner " \r\n" -}}
{{ if not $body -}}
{{ errorf "Missing inner element text: %s" .Position -}}
{{ $error = true }}
{{ end -}}
<!-- Main code -->
{{- if not $error -}}
<div class="d-flex alert alert-{{ $color }} {{ if $dismissible }}alert-dismissible fade show{{ end }}{{ with $class }} {{ . }}{{ end }}" role="alert">
{{ with $icon }}<div class="pt-1 pe-2">{{ . }}</div>{{ end }}
<div class="flex-grow-1 my-auto">
{{ $body | .Page.RenderString | safeHTML -}}
{{ if $dismissible }}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{{ T "close" }}"></button>{{ end }}
</div>
</div>
{{- end -}}