mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-17 23:13:11 +00:00
97 lines
3.7 KiB
HTML
97 lines
3.7 KiB
HTML
<!--
|
|
Displays a button. The shortcode supports the following arguments:
|
|
"href" Optional address for the button or hyperlink. Automatically assigned when using collapse.
|
|
"relref" Optional name of the page to link to. Replaces "href" with a relative link if set.
|
|
"id" Optional id of the button, to be used in the DOM.
|
|
"state" Optional state of the button, either "enabled" (default), "disabled", "active", or "inactive".
|
|
"size" Optional size of the button, either "sm", "md" (default), or "lg".
|
|
"color": Optional theme color of the element, either "primary" (default), "secondary", "success",
|
|
"danger", "warning", "info", "light", "dark", "white", or "black".
|
|
"outline" Optional flag indicating the button should be outlined, either "false" (default) or "true".
|
|
"badge" Optional positioned badge to display on top of the button.
|
|
"aria-label" Optional label for the badge.
|
|
"tooltip" Optional text to display in a tooltip. Cannot be used together with collapse. Ignored for active/
|
|
inactive buttons.
|
|
"collapse" Optional panel to collapse. Cannot be used together with tooltip. Ignored for active/inactive buttons.
|
|
"placement" Optional position of the tooltip: "top" (default), "bottom", "left", or "right".
|
|
-->
|
|
|
|
{{ $error := false }}
|
|
{{ $type := "button" -}}
|
|
|
|
{{ $title := trim .Inner " \r\n" -}}
|
|
{{ if not $title -}}
|
|
{{ errorf "Missing 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" -}}
|
|
{{ $label := .Get "aria-label" -}}
|
|
{{ $tooltip := .Get "tooltip" -}}
|
|
{{ $collapse := .Get "collapse" -}}
|
|
{{ $href := .Get "href" -}}
|
|
{{ $relref := .Get "relref" }}
|
|
{{ $id := .Get "id" -}}
|
|
{{ if $relref }}
|
|
{{ $href = relref . $relref }}
|
|
{{ 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 -}}
|
|
|
|
{{ if not $error }}
|
|
{{- 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
|
|
"placement" $placement)
|
|
-}}
|
|
{{ end }}
|