Refactor tooltip

This commit is contained in:
mark
2023-12-26 07:19:30 +01:00
parent 8c007fd627
commit 04c253995f
2 changed files with 64 additions and 31 deletions

View File

@@ -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.

View File

@@ -1,15 +1,18 @@
<!-- <!--
Displays a tooltip for a link. The shortcode supports the following arguments: Copyright © 2023 The Hinode Team / Mark Dumay. All rights reserved.
"color": Optional theme color of the element, either "primary" (default), "secondary", "success", Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file.
"danger", "warning", "info", "light", or "dark". Visit gethinode.com/license for more details.
"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.
"spacing" Optional flag to add spacing to the inline tooltip, defaults to "true".
--> -->
{{ $error := false }} {{ $error := false }}
<!-- Validate arguments -->
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "tooltip" "args" .Params) }}
{{ errorf "Invalid arguments: %s" .Position -}}
{{ $error = true }}
{{ end }}
<!-- Initialize arguments -->
{{ $type := "link" -}} {{ $type := "link" -}}
{{ $title := trim .Inner " \r\n" | plainify -}} {{ $title := trim .Inner " \r\n" | plainify -}}
@@ -18,34 +21,14 @@
{{ $error = true }} {{ $error = true }}
{{ end -}} {{ end -}}
{{ $color := "primary" -}} {{ $color := .Get "color" | default "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 "" -}} {{ $tooltip := .Get "title" | default "" -}}
{{ $href := .Get "href" | default "" -}} {{ $href := .Get "href" | default "" -}}
{{ if not $href -}} {{ $placement := .Get "placement" | default "top" -}}
{{ 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 "" -}} {{- $class := .Get "class" | default "" -}}
{{- $spacing := .Get "spacing" | default true -}} {{- $spacing := .Get "spacing" | default true -}}
<!-- Main code -->
{{ if not $error }} {{ if not $error }}
<div class="d-inline-flex"> <div class="d-inline-flex">
{{- partial "assets/button.html" (dict {{- partial "assets/button.html" (dict