Skip to content

Commit

Permalink
feat(icon-grid): add the item-attr-* dynamic parameters for attaching…
Browse files Browse the repository at this point in the history
… custom attributes on items
  • Loading branch information
razonyang committed Sep 19, 2023
1 parent 1c9c88a commit a6fca8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions layouts/partials/bootstrap/functions/attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $attrs := slice }}
{{- $prefix := .Prefix | printf "%s-" }}
{{- range $name, $value := .Params }}
{{- if hasPrefix $name $prefix }}
{{- $attrs = $attrs | append (printf "%s=%s" (strings.TrimPrefix $prefix $name) $value) }}
{{- end }}
{{- end }}
{{- return $attrs }}
7 changes: 6 additions & 1 deletion layouts/partials/bootstrap/icon-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
}}
{{- $border := true }}
{{- $alignment := "start" }}
{{- $itemAttrs := slice }}
{{- if .IsNamedParams }}
{{- $key = .Get "data" }}
{{- if isset .Params "linkText" }}{{ $linkText = .Get "linkText" }}{{ end }}
{{- if isset .Params "border" }}{{ $border = .Get "border" }}{{ end }}
{{- with .Get "alignment" }}{{ $alignment = . }}{{ end }}
{{- $itemAttrs = partial "bootstrap/functions/attributes" (dict "Params" .Params "Prefix" "item-attr") }}
{{- else }}
{{- $key = .Get 0 }}
{{- end }}
Expand Down Expand Up @@ -50,6 +52,7 @@
<a
class="bs-icon-grid-item d-flex flex-column rounded h-100 w-100 p-4 text-decoration-none{{ cond $border ` border shadow` `` }} text-{{ $alignment }}"
href="{{ $link }}"
{{ with $itemAttrs }}{{ delimit . " " | safeHTMLAttr }}{{ end }}
{{ if $url.Scheme }}target="_blank" rel="external"{{ end }}>
<div class="bs-icon-grid-item-title fw-bold mb-3 fs-4 d-flex align-items-center justify-content-{{ $alignment }}">
{{- $icon -}}{{- .title -}}
Expand All @@ -59,7 +62,9 @@
</p>
</a>
{{ else }}
<div class="bs-icon-grid-item d-flex flex-column rounded h-100 w-100 p-4{{ cond $border ` border shadow` `` }} text-{{ $alignment }}">
<div
class="bs-icon-grid-item d-flex flex-column rounded h-100 w-100 p-4{{ cond $border ` border shadow` `` }} text-{{ $alignment }}"
{{ with $itemAttrs }}{{ delimit . " " | safeHTMLAttr }}{{ end }}>
<div class="bs-icon-grid-item-title fw-bold mb-3 fs-4 d-flex align-items-center justify-content-{{ $alignment }}">
{{- $icon -}}{{- .title -}}
</div>
Expand Down

0 comments on commit a6fca8f

Please sign in to comment.