Skip to content

Commit

Permalink
Add HTML attribute "id" to Button element
Browse files Browse the repository at this point in the history
  • Loading branch information
jhauraw committed Jul 16, 2020
1 parent 7fb077f commit 6a1a598
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions layouts/partials/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
{{- end }}
{{- $text := .text -}}
{{- $type := .type | default "default" -}}
{{- $svg := "" -}}
{{- $id := .id -}}
{{- $class := "" -}}
{{- $svg := "" -}}
{{- with .icon }}
{{- $svg = printf "svg/%s.svg" . -}}
{{- $svg = partial $svg (dict "class" "fill-current h-4 w-auto mr-2") -}}
Expand All @@ -23,7 +24,7 @@
{{- $class = printf "%s rounded font-content-sans font-semibold %s %s %s py-2 px-4 %s" $class $textColor $bgColor $hoverColor $borderColor -}}
{{- $class = trim $class " " -}}
{{- if $href }}
<a class="{{ $class }}" href="{{ $href }}" role="button">
<a{{ with $id }} id="{{ . }}"{{ end }} class="{{ $class }}" href="{{ $href }}" role="button">
{{- with $svg }}
{{ . | safeHTML }}
{{- end }}
Expand Down
5 changes: 4 additions & 1 deletion layouts/shortcodes/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
{{- $type := "" -}}
{{- $icon := "" -}}
{{- $href := "" -}}
{{- $id := "" -}}
{{- if .IsNamedParams }}
{{- $text = .Get "text" -}}
{{- $type = .Get "type" -}}
{{- $icon = .Get "icon" -}}
{{- $href = .Get "href" -}}
{{- $id = .Get "id" -}}
{{- else }}
{{- $text = .Get 0 -}}
{{- $type = .Get 1 -}}
{{- $icon = .Get 2 -}}
{{- $href = .Get 3 -}}
{{- $id = .Get 4 -}}
{{- end }}
{{- if not $text }}
{{- errorf "Missing required 'text'. Shortcode: 'button'." -}}
{{- end }}
{{- partial "button" (dict "Site" $.Site "Page" . "text" $text "type" $type "icon" $icon "href" $href) -}}
{{- partial "button" (dict "Site" $.Site "Page" . "text" $text "type" $type "icon" $icon "href" $href "id" $id) -}}

0 comments on commit 6a1a598

Please sign in to comment.