diff --git a/data/structures/tooltip.yml b/data/structures/tooltip.yml new file mode 100644 index 00000000..1315e8c2 --- /dev/null +++ b/data/structures/tooltip.yml @@ -0,0 +1,50 @@ +comment: >- + Displays a tooltip for a link. The inner content is used as hyperlink text. +arguments: + title: + type: string + optional: true + comment: Plain text to display in the tooltip. + href: + type: url + optional: true + comment: Address for the button or hyperlink. + class: + type: string + optional: true + parent: merge + comment: Class attribute of the tooltip's button element. + color: + type: select + optional: true + default: dark + comment: Theme color of the element. + options: + values: + - primary + - secondary + - success + - danger + - warning + - info + - light + - dark + placement: + type: select + optional: true + default: top + comment: Position of the tooltip. + options: + values: + - top + - bottom + - left + - right + spacing: + type: bool + optional: true + default: true + comment: Flag to add spacing to the inline tooltip. +body: + optional: false + comment: Hyperlink text. diff --git a/layouts/shortcodes/tooltip.html b/layouts/shortcodes/tooltip.html index 07e578f3..948ff1ab 100644 --- a/layouts/shortcodes/tooltip.html +++ b/layouts/shortcodes/tooltip.html @@ -1,15 +1,18 @@ {{ $error := false }} + + +{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "tooltip" "args" .Params) }} + {{ errorf "Invalid arguments: %s" .Position -}} + {{ $error = true }} +{{ end }} + + {{ $type := "link" -}} {{ $title := trim .Inner " \r\n" | plainify -}} @@ -18,34 +21,14 @@ {{ $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 -}} - +{{ $color := .Get "color" | default "primary" -}} {{ $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 -}} - +{{ $placement := .Get "placement" | default "top" -}} {{- $class := .Get "class" | default "" -}} - {{- $spacing := .Get "spacing" | default true -}} + {{ if not $error }}
{{- partial "assets/button.html" (dict