mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-07 01:54:23 +00:00
Refactor tooltip
This commit is contained in:
50
data/structures/tooltip.yml
Normal file
50
data/structures/tooltip.yml
Normal 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.
|
@@ -1,15 +1,18 @@
|
||||
<!--
|
||||
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.
|
||||
"spacing" Optional flag to add spacing to the inline tooltip, defaults to "true".
|
||||
Copyright © 2023 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" "tooltip" "args" .Params) }}
|
||||
{{ errorf "Invalid arguments: %s" .Position -}}
|
||||
{{ $error = true }}
|
||||
{{ end }}
|
||||
|
||||
<!-- Initialize arguments -->
|
||||
{{ $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 -}}
|
||||
|
||||
<!-- Main code -->
|
||||
{{ if not $error }}
|
||||
<div class="d-inline-flex">
|
||||
{{- partial "assets/button.html" (dict
|
||||
|
Reference in New Issue
Block a user