Skip to content

Commit

Permalink
Merge pull request #1009 from gethinode/develop
Browse files Browse the repository at this point in the history
Support rounding of card icons
  • Loading branch information
markdumay authored Jun 22, 2024
2 parents f235eb4 + c3c1b4b commit 23d051e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
6 changes: 6 additions & 0 deletions data/structures/card.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ arguments:
optional: true
comment: >-
Font Awesome icon, displayed on top or the left of the card.
iconRounded:
type: bool
parent: cascade
optional: true
release: v0.24.8
comment: Stack the icon in a round container.
align:
type: select
parent: cascade
Expand Down
8 changes: 6 additions & 2 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"use"
],
"classes": [
"%!s(MISSING)",
"accordion",
"accordion-body",
"accordion-button",
Expand Down Expand Up @@ -134,13 +135,11 @@
"col-3",
"col-4",
"col-6",
"col-8",
"col-9",
"col-auto",
"col-lg-2",
"col-lg-4",
"col-lg-8",
"col-md-10",
"col-md-2",
"col-md-3",
"col-md-4",
Expand Down Expand Up @@ -190,6 +189,7 @@
"fa-arrow-left",
"fa-arrow-right",
"fa-bootstrap",
"fa-circle",
"fa-circle-check",
"fa-code",
"fa-docker",
Expand All @@ -202,6 +202,7 @@
"fa-globe",
"fa-heart",
"fa-house",
"fa-inverse",
"fa-link",
"fa-linkedin",
"fa-magnifying-glass",
Expand All @@ -211,6 +212,9 @@
"fa-share-nodes",
"fa-sort",
"fa-square-check",
"fa-stack",
"fa-stack-1x",
"fa-stack-2x",
"fa-sun",
"fa-up-right-from-square",
"fa-whatsapp",
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/assets/card-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{{- $button := .button -}}
{{- $buttonLabel := .buttonLabel -}}
{{- $buttonType := .buttonType -}}
{{- $iconRounded := .iconRounded }}
{{- $hook := .hook | default "assets/card.html" }}

<!-- Override arguments -->
Expand Down
61 changes: 50 additions & 11 deletions layouts/partials/assets/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{{- $href := .href -}}
{{- $icon := .icon -}}
{{- $iconStyle := "" -}}
{{- $iconRounded := .iconRounded | default false -}}
{{- $align := .align | default "start" -}}
{{- $style := .style | default "" -}}
{{- $sizes := .sizes | default "100vw" -}}
Expand Down Expand Up @@ -127,20 +128,53 @@
<!-- Main code -->
{{ if ne $gutter "0" }}<div class="g-{{ $gutter }}">{{ end }}

{{ $stack := "fa-2x" }}

{{- if hasPrefix $orientation "horizontal" -}}
{{ $col1 := "" }}
{{ $col2 := "" }}

{{ if $thumbnail }}
{{ if eq $orientation "horizontal-sm" }}
{{ $stack = "fa-1x" }}
{{ $col1 = "col-4 col-md-2" }}
{{ $col2 = "col-8 col-md-10" }}
{{ else }}
{{ $col1 = "col-4" }}
{{ $col2 = "col-8" }}
{{ end }}
{{ else if $icon }}
{{ if eq $orientation "horizontal-sm" }}
{{ $stack = "fa-1x" }}
{{ $col1 = "col-2" }}
{{ $col2 = "col-10" }}
{{ else }}
{{ $col1 = "col-4" }}
{{ $col2 = "col-8" }}
{{ end }}

{{ end }}

<!-- Render horizontal card -->
<div class="card {{ $colorStyle }} {{ $class }}">
<div class="row g-0 row-cols-1 h-100{{ if $button }} pb-5{{ end }}">
<div class="{{ if eq $orientation "horizontal-sm" }}col-4 col-md-2{{ else }}col-4{{ end }}">
{{- if $thumbnail -}}
<div class="row g-0 row-cols-2 h-100{{ if $button }} pb-5{{ end }}">
{{- if $thumbnail -}}
<div class="{{ $col1 }}">
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "1x1") "sizes" $sizes "wrapper" "h-100 card-img-wrap" "class" "rounded-start card-img-h100 card-img-bg" "title" $title "loading" $loading) -}}
{{- else if $icon -}}
<div class="card-icon p-{{ $padding }} h-100 fa-wrapper d-flex align-items-{{ $align}} justify-content-center {{ $iconStyle }}">
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
</div>
{{- else if $icon -}}
<div class="{{ $col1 }}">
<div class="card-icon {{ if $iconRounded }}fa-stack {{ $stack }} mx-auto{{ else }}fa-wrapper h-100 {{ end }} p-{{ $padding }} d-flex align-items-{{ $align}} justify-content-center {{ $iconStyle }}">
{{ if $iconRounded }}
{{- partial "assets/icon.html" (dict "icon" "fas circle fa-stack-2x") -}}
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-stack-1x fa-inverse" $icon)) -}}
{{ else }}
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
{{ end }}
</div>
{{- end -}}
</div>
<div class="{{ if eq $orientation "horizontal-sm" }}col-8 col-md-10{{ else }}col-8{{ end }}">
</div>
{{- end -}}
<div class="{{ $col2 }}">
<div class="card-body d-flex p-{{ $padding }} flex-column h-100 flex-fill">
{{ if $page }}<div>{{ partial "card-caption.html" (dict "page" $page "keywords" $header "color" $color) }}</div>{{ end }}
<div class="flex-fill">
Expand Down Expand Up @@ -173,8 +207,13 @@
{{- if $thumbnail -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "16x9") "sizes" $sizes "wrapper" "card-img-wrap" "class" "card-img-top card-img-bg" "title" (or $alt $title) "loading" $loading) -}}
{{- else if $icon -}}
<div class="card-icon p-{{ $padding }} {{ $iconStyle }} text-{{ $align }}">
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
<div class="card-icon p-{{ $padding }} {{ $iconStyle }} text-{{ $align }} {{ if $iconRounded }}fa-stack {{ $stack }}{{ end }} w-100">
{{ if $iconRounded }}
{{- partial "assets/icon.html" (dict "icon" (printf "fas circle fa-stack-2x %s")) -}}
{{- partial "assets/icon.html" (dict "icon" (printf "%s fa-stack-1x fa-inverse" $icon)) -}}
{{ else }}
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
{{ end }}
</div>
{{- end -}}
<div class="card-body d-flex flex-column p-{{ $padding }}">
Expand Down
2 changes: 2 additions & 0 deletions layouts/shortcodes/card-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{{- $subtle := .Get "subtle" | default false -}}
{{- $button := .Get "button" | default false -}}
{{- $buttonType := .Get "buttonType" | default "" -}}
{{- $iconRounded := .Get "iconRounded" | default false -}}

{{ $inner := .Scratch.Get "inner" }}
{{ $input := trim .Inner " \r\n" }}
Expand Down Expand Up @@ -58,5 +59,6 @@
"subtle" $subtle
"button" $button
"buttonType" $buttonType
"iconRounded" $iconRounded
)
-}}
2 changes: 2 additions & 0 deletions layouts/shortcodes/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{{- $gutter := partial "utilities/GetArgParent" (dict "page" . "arg" "gutter") | default "0" -}}
{{- $header := partial "utilities/GetArgParent" (dict "page" . "arg" "header") | default "full" -}}
{{- $icon := .Get "icon" -}}
{{- $iconRounded := partial "utilities/GetArgParent" (dict "page" . "arg" "iconRounded") | default false -}}
{{- $align := partial "utilities/GetArgParent" (dict "page" . "arg" "align") | default "start" -}}
{{- $style := partial "utilities/GetArgParent" (dict "page" . "arg" "style") | default "" -}}
{{- $subtle := partial "utilities/GetArgParent" (dict "page" . "arg" "subtle") | default false -}}
Expand Down Expand Up @@ -64,6 +65,7 @@
"description" $description
"ratio" $ratio
"icon" $icon
"iconRounded" $iconRounded
"align" $align
"style" $style
"subtle" $subtle
Expand Down

0 comments on commit 23d051e

Please sign in to comment.