Skip to content

Commit

Permalink
Merge pull request #479 from gethinode/develop
Browse files Browse the repository at this point in the history
Add kbd shortcode
  • Loading branch information
markdumay committed Aug 28, 2023
2 parents c426340 + 73edc42 commit b3118ba
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions layouts/shortcodes/kbd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Adds a keyboard input element. The shortcode supports the following arguments:
"title" Required title of the keyboard input. In shorthand notation, this is the first (and only) matched
argument.
"class" Optional class attributes of the keyboard input element.
"color" Optional theme color of the element, either "primary", "secondary" (default), "success",
"danger", "warning", "info", "light", "dark", "white", or "black".
-->

{{- $error := false -}}
{{- $title := "" -}}
{{- if .IsNamedParams }}{{ $title = .Get "title" }}{{ else }}{{ $title = .Get 0 }}{{ end }}
{{- $class := .Get "class" -}}
{{- $color := "" -}}
{{- with .Get "color" }}{{ $color = . }}{{ end -}}
{{- $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "white" "black" -}}
{{- if and $color (not (in $supportedColors $color)) -}}
{{- errorf "Invalid value for param 'color': %s" .Position -}}
{{- end -}}

{{- if not $title }}
{{ errorf "Missing title: %s" .Position -}}
{{ else -}}
<kbd {{ if or $color $class }}class="{{ with $color }}text-bg-{{ . }}{{ end }}{{ with $class }} {{ . }}{{ end }}"{{ end }}>{{ $title | plainify }}</kbd>
{{ end -}}

0 comments on commit b3118ba

Please sign in to comment.