-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathbutton.html
More file actions
111 lines (100 loc) · 4.93 KB
/
button.html
File metadata and controls
111 lines (100 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{{/*
Copyright © 2022 - 2025 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 }}
{{/* Initialize arguments */}}
{{ $args := partial "utilities/InitArgs.html" (dict "structure" "button" "args" . "group" "partial")}}
{{ if or $args.err $args.warnmsg }}
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
"partial" "assets/button.html"
"warnid" "warn-invalid-arguments"
"msg" "Invalid arguments"
"details" ($args.errmsg | append $args.warnmsg)
"file" page.File
)}}
{{ $error = $args.err }}
{{ end }}
{{/* Initialize local arguments */}}
{{- $title := trim $args.title " \r\n" -}}
{{- if not (or $title $args.icon) -}}
{{- warnf "partial [assets/button.html] - Missing element title or icon" -}}
{{ $title = T "linkPlaceholder" }}
{{- end -}}
{{- $label := $args.label | default $title -}}
{{- $tooltip := "" -}}
{{ $state := or $args.buttonState $args.state }}
{{- if not (strings.HasSuffix $state "active") -}}
{{- with $args.tooltip }}{{ $tooltip = . }}{{ end -}}
{{- end -}}
{{- $href := .href -}}
{{ $linkType := or $args.linkType $args.type }}
{{ $buttonSize := or $args.buttonSize $args.size }}
{{ $toastID := or $args.toastId $args.toast }}
{{ $collapseID := or $args.collapseId $args.collapse }}
{{- if not (strings.HasSuffix $state "active") -}}
{{- with $collapseID }}{{ $href = printf "#%s" . }}{{ end -}}
{{ else }}
{{- $collapseID = "" -}}
{{- end -}}
{{- if and $tooltip $collapseID -}}
{{- errorf "partial [assets/button.html] - Cannot use tooltip and collapse at the same time" -}}
{{ $error = true }}
{{- end -}}
{{- $class := $args.class | default "" }}
{{ with $args.badge }}{{ $class = printf "%s me-3" $class }}{{ end }}
{{- $cue := $args.cue | default site.Params.main.externalLinks.cue -}}
{{- $tab := $args.tab | default site.Params.main.externalLinks.tab -}}
{{- $isExternal := false }}
{{ if in (slice "http" "https") ((urls.Parse (absURL $href)).Scheme) }}
{{ $isExternal = ne (urls.Parse (absURL $href)).Host (urls.Parse site.BaseURL).Host -}}
{{ end }}
{{- $target := "" -}}
{{- $rel := "" -}}
{{- if $isExternal -}}
{{- if $tab -}}
{{- $target = "_blank" -}}
{{- $rel = "noopener noreferrer nofollow" -}}
{{- end -}}
{{- if and $title $cue -}}
{{ $suffix := partial "assets/icon.html" (dict "icon" "fas up-right-from-square fa-2xs") }}
{{- $title = printf "%s %s" $title $suffix | safeHTML -}}
{{- end -}}
{{- end -}}
{{/* Main code */}}
{{ if not $error }}
<a aria-label="{{ (or $label $title) | safeHTML }}"
{{ if ne $state "disabled" }}{{ with $href }}href="{{ . }}"{{ end }}{{ end -}}
{{- with $args.id }} id="{{ . }}"{{ end -}}
{{- with $target }} target="{{ . }}"{{ end }}{{ with $rel }} rel="{{ . }}"{{ end -}}
{{- with $toastID }} data-toast-target="{{ . }}"{{ end -}}
{{- with $args.clipboard }} data-clipboard="{{ . }}"{{ end -}}
{{- if eq $linkType "button" }} class="btn btn-{{ if $args.outline }}outline-{{ end }}{{ $args.color }} {{ if ne $buttonSize "md" }}btn-{{ $args.size }}{{ end }} position-relative {{ if in (slice "disabled" "active") $args.state }}{{ $args.state }}{{ end }} {{ $class -}}"
{{ if eq $state "disabled" }}aria-disabled="true"{{ end -}}
{{- else }} class="btn btn-link link-{{ $args.color }} position-relative {{ $class }}"{{ end -}}
{{- with $tooltip }} data-bs-toggle="tooltip" data-bs-title="{{ . }}" data-bs-placement="{{ $args.placement }}"{{ end -}}
{{- with $collapseID }} data-bs-toggle="collapse" aria-expanded="false" aria-controls="{{ . }}"{{ end -}}
{{- if eq $state "active" }} data-bs-toggle="button" aria-pressed="true"{{ end -}}
{{- if eq $state "inactive" }} data-bs-toggle="button" aria-pressed="false"{{ end -}}
{{- range $key, $val := $args.attributes -}}
{{ printf " %s=\"%s\"" $key $val | safeHTMLAttr }}
{{- end -}}
role="button"
>
<span class="d-flex justify-content-{{ $args.justify }}">
<span class="my-auto">{{ $title | safeHTML }}</span>
{{- with $args.icon }}
<span class="align-self-center{{ if $title }}{{ if eq $args.order "first" }} order-first pe-1{{ else }} ps-1{{ end }}{{ end }}">
{{ partial "assets/icon.html" (dict "icon" $args.icon "spacing" false) }}
</span>
{{ end }}
</span>
{{- with $args.badge }}
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
{{ . }}
{{ with $label }}<span class="visually-hidden">{{ . }}</span>{{ end }}
</span>
{{- end -}}
</a>{{ if $args.spacing }} {{- end }}
{{ end }}