Skip to content

Commit

Permalink
badge: add new shortcode matcornic#410
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Dec 1, 2022
1 parent 3b47f1e commit c45f6dd
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 95 deletions.
174 changes: 90 additions & 84 deletions exampleSite/content/basics/migration/_index.en.md

Large diffs are not rendered by default.

188 changes: 188 additions & 0 deletions exampleSite/content/shortcodes/badge.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
+++
description = "Marker badges to display in your text"
title = "Badge"
+++

The `badge` shortcode displays little markers in your text with adjustable color, title and icon.

{{% badge %}}Important{{% /badge %}}
{{% badge style="primary" title="Version" %}}6.6.6{{% /badge %}}
{{% badge style="red" icon="skull-crossbones" %}}Captain{{% /badge %}}
{{% badge style="info" %}}Awesome{{% /badge %}}

## Usage

While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.

{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}

````go
{{%/* badge %}}Important{{% /badge */%}}
{{%/* badge style="primary" title="Version" %}}6.6.6{{% /badge */%}}
{{%/* badge style="red" icon="skull-crossbones" %}}Captain{{% /badge */%}}
{{%/* badge style="info" %}}Awesome{{% /badge */%}}
````

{{% /tab %}}
{{% tab name="partial" %}}

````go
{{ partial "shortcodes/badge.html" (dict
"context" .
"content" "Important"
)}}
{{ partial "shortcodes/badge.html" (dict
"context" .
"style" "primary"
"title" "Version"
"content" "6.6.6"
)}}
{{ partial "shortcodes/badge.html" (dict
"context" .
"style" "red"
"icon" "skull-crossbones"
"content" "Captain"
)}}
{{ partial "shortcodes/badge.html" (dict
"context" .
"style" "info"
"content" "Awesome"
)}}
````

{{% /tab %}}
{{< /tabs >}}

Once the button is clicked, it opens another browser tab for the given URL.

### Parameter

| Name | Default | Notes |
|:----------------------|:----------------|:------------|
| **style** | `transparent` | The color scheme used to paint the badge.<br><br>- by severity: `info`, `note`, `tip`, `warning`<br>- by brand color: `primary`, `secondary`<br>- by color: `blue`, `green`, `grey`, `orange`, `red`<br>- by special color: `default`, `transparent` |
| **icon** | see notes | [Font Awesome icon name]({{%relref "cont/icons#finding-an-icon" %}}) set to the left of the title. Depending on the **style** there may be a default icon. Any given value will overwrite the default.<br><br>- for severity styles: a nice matching icon for the severity<br>- for all other colors: _&lt;empty&gt;_<br><br>If you want no icon for a severity style, you have to set this parameter to `" "` (a non empty string filled with spaces) |
| **title** | see notes | Arbitrary text for the badge title. Depending on the **style** there may be a default title. Any given value will overwrite the default.<br><br>- for severity styles: the matching title for the severity<br>- for all other colors: _&lt;empty&gt;_<br><br>If you want no title for a severity style, you have to set this parameter to `" "` (a non empty string filled with spaces) |
| _**&lt;content&gt;**_ | see notes | Arbitrary text for the badge| _**&lt;content&gt;**_ | | _&lt;empty&gt;_ | Arbitrary text to be displayed in box. |

## Examples

### Style

#### By Severity

````go
{{%/* badge style="info" %}}New{{% /badge */%}}
{{%/* badge style="note" %}}Change{{% /badge */%}}
{{%/* badge style="tip" %}}Optional{{% /badge */%}}
{{%/* badge style="warning" %}}Breaking{{% /badge */%}}
````

{{% badge style="info" %}}New{{% /badge %}}
{{% badge style="note" %}}Change{{% /badge %}}
{{% badge style="tip" %}}Optional{{% /badge %}}
{{% badge style="warning" %}}Breaking{{% /badge %}}

#### By Brand Colors

````go
{{%/* badge style="primary" icon="bullhorn" title="Announcement" %}}Mandatory{{% /badge */%}}
{{%/* badge style="secondary" icon="bullhorn" title="Announcement" %}}Optional{{% /badge */%}}
````

{{% badge style="primary" icon="bullhorn" title="Announcement" %}}Mandatory{{% /badge %}}
{{% badge style="secondary" icon="bullhorn" title="Announcement" %}}Optional{{% /badge %}}

#### By Color

````go
{{%/* badge style="blue" icon="palette" title="Color" %}}Blue{{% /badge */%}}
{{%/* badge style="green" icon="palette" title="Color" %}}Green{{% /badge */%}}
{{%/* badge style="grey" icon="palette" title="Color" %}}Grey{{% /badge */%}}
{{%/* badge style="orange" icon="palette" title="Color" %}}Orange{{% /badge */%}}
{{%/* badge style="red" icon="palette" title="Color" %}}Red{{% /badge */%}}
````

{{% badge style="blue" icon="palette" title="Color" %}}Blue{{% /badge %}}
{{% badge style="green" icon="palette" title="Color" %}}Green{{% /badge %}}
{{% badge style="grey" icon="palette" title="Color" %}}Grey{{% /badge %}}
{{% badge style="orange" icon="palette" title="Color" %}}Orange{{% /badge %}}
{{% badge style="red" icon="palette" title="Color" %}}Red{{% /badge %}}

#### By Special Color

````go
{{%/* badge style="default" icon="palette" title="Color" %}}Default{{% /badge */%}}
{{%/* badge style="transparent" icon="palette" title="Color" %}}Transparent{{% /badge */%}}
````

{{% badge style="default" icon="palette" title="Color" %}}Default{{% /badge %}}
{{% badge style="transparent" icon="palette" title="Color" %}}Transparent{{% /badge %}}

### Variants

#### Without Icon and Title Text

````go
{{%/* badge %}}6.6.6{{% /badge */%}}
{{%/* badge style="info" icon=" " title=" " %}}Awesome{{% /badge */%}}
{{%/* badge style="red" %}}Captain{{% /badge */%}}
````

{{% badge %}}6.6.6{{% /badge %}}
{{% badge style="info" icon=" " title=" " %}}Awesome{{% /badge %}}
{{% badge style="red" %}}Captain{{% /badge %}}

#### Without Icon

````go
{{%/* badge title="Version" %}}6.6.6{{% /badge */%}}
{{%/* badge style="info" icon=" " %}}Awesome{{% /badge */%}}
{{%/* badge style="red" title="Rank" %}}Captain{{% /badge */%}}
````

{{% badge title="Version" %}}6.6.6{{% /badge %}}
{{% badge style="info" icon=" " %}}Awesome{{% /badge %}}
{{% badge style="red" title="Rank" %}}Captain{{% /badge %}}

#### Without Title Text

````go
{{%/* badge icon="star" %}}6.6.6{{% /badge */%}}
{{%/* badge style="info" title=" " %}}Awesome{{% /badge */%}}
{{%/* badge style="red" icon="skull-crossbones" %}}Captain{{% /badge */%}}
````

{{% badge icon="star" %}}6.6.6{{% /badge %}}
{{% badge style="info" title=" " %}}Awesome{{% /badge %}}
{{% badge style="red" icon="skull-crossbones" %}}Captain{{% /badge %}}

#### All Set

````go
{{%/* badge icon="star" title="Version" %}}6.6.6{{% /badge */%}}
{{%/* badge style="info" %}}Awesome{{% /badge */%}}
{{%/* badge style="red" icon="skull-crossbones" title="Rank" %}}Captain{{% /badge */%}}
````

{{% badge icon="star" title="Version" %}}6.6.6{{% /badge %}}
{{% badge style="info" %}}Awesome{{% /badge %}}
{{% badge style="red" icon="skull-crossbones" title="Rank" %}}Captain{{% /badge %}}

#### Override for Severity

````go
{{%/* badge style="info" icon="rocket" title="Feature" %}}Awesome{{% /badge */%}}
````

{{% badge style="info" icon="rocket" title="Feature" %}}Awesome{{% /badge %}}

### Other

#### Inside of Text

````go
Lorem ipsum dolor sit amet, graecis denique ei vel, at duo primis mandamus. {{%/* badge style="blue" icon="rocket" %}}Awesome{{% /badge */%}} Et legere ocurreret pri, animal tacimates complectitur ad cum. Cu eum inermis inimicus efficiendi. Labore officiis his ex, soluta officiis concludaturque ei qui, vide sensibus vim ad.
````

Lorem ipsum dolor sit amet, graecis denique ei vel, at duo primis mandamus. {{% badge style="blue" icon="rocket" %}}Awesome{{% /badge %}} Et legere ocurreret pri, animal tacimates complectitur ad cum. Cu eum inermis inimicus efficiendi. Labore officiis his ex, soluta officiis concludaturque ei qui, vide sensibus vim ad.
5 changes: 5 additions & 0 deletions exampleSite/content/shortcodes/badge.pir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+++
descrption = "Nice buttons on yer plank"
title = "Button"
+++
{{< piratify >}}
3 changes: 2 additions & 1 deletion layouts/partials/shortcodes/attachments.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{- $content := .content }}
{{- $style := .style | default "transparent" }}
{{- $title := .title | default ($style | T) | default ("Attachments-label" | T) }}
{{- $title = trim $title " " }}
{{- $icon := .icon | default "" }}
{{- if and (not $icon) (eq (len $icon) 0) }}
{{- $icon = "paperclip" }}
Expand All @@ -18,7 +19,7 @@
{{- $pattern := .pattern | default "" }}
{{- with $context }}
<div class="box attachments cstyle {{ $style }}">
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i> {{ end }}{{ $title }}</div>
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title }}</div>
<ul class="box-content attachments-files">
{{- $filesName := "files" }}
{{- if ne .Page.File.BaseFileName "index" }}
Expand Down
19 changes: 19 additions & 0 deletions layouts/partials/shortcodes/badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- $context := .context }}
{{- $content := .content }}
{{- $style := .style | default "default" }}
{{- $title := .title | default ($style | T) }}
{{- $title = trim $title " " }}
{{- $icon := .icon | default "" }}
{{- if and (not $icon) (eq (len $icon) 0) }}
{{- if eq $style "info" }}{{ $icon = default "info-circle" }}{{ end }}
{{- if eq $style "warning" }}{{ $icon = default "exclamation-triangle" }}{{ end }}
{{- if eq $style "note" }}{{ $icon = default "exclamation-circle" }}{{ end }}
{{- if eq $style "tip" }}{{ $icon = default "lightbulb" }}{{ end }}
{{- end }}
{{- $icon = trim $icon " " }}
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- with $context -}}
<span class="badge cstyle {{ $style }}{{ if or $icon $title }} badge-with-title{{ end }}">{{ if or $icon $title }}<span class="badge-title">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ if $title }}{{ $title }}{{ end }}</span>{{ end }}<span class="badge-content">{{ $content }}</span></span>
{{- end }}
1 change: 1 addition & 0 deletions layouts/partials/shortcodes/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{{- $target = "_blank" }}
{{- end }}
{{- $title := .title | default ($content) | default ($style | T) }}
{{- $title = trim $title " " }}
{{- $icon := .icon | default "" }}
{{- if and (not $icon) (eq (len $icon) 0) }}
{{- if eq $style "info" }}{{ $icon = default "info-circle" }}{{ end }}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/shortcodes/expand.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{- $context := .context }}
{{- $content := .content }}
{{- $title := .title | default (T "Expand-title") }}
{{- $title = trim $title " " }}
{{- $expanded := .open | default false }}
{{- if eq (printf "%T" $expanded) "string" }}
{{- $expanded = (eq $expanded "true") }}
Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/shortcodes/notice.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{- $content := .content }}
{{- $style := .style | default "default" }}
{{- $title := .title | default ($style | T) }}
{{- $title = trim $title " " }}
{{- $icon := .icon | default "" }}
{{- if and (not $icon) (eq (len $icon) 0) }}
{{- if eq $style "info" }}{{ $icon = default "info-circle" }}{{ end }}
Expand All @@ -15,8 +16,8 @@
{{- end }}
{{- with $context }}
<div class="box notices cstyle {{ $style }}">
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i> {{ end }}{{ $title }}</div>
<div class="box-content">
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title }}</div>
<div class="box-content">
{{ $content | safeHTML }} </div>
</div>
{{- end }}
8 changes: 8 additions & 0 deletions layouts/shortcodes/badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $_hugo_config := `{ "version": 1 }` }}
{{- partial "shortcodes/badge.html" (dict
"context" .
"content" .Inner
"icon" (.Get "icon")
"style" (.Get "style")
"title" (.Get "title")
) }}
85 changes: 85 additions & 0 deletions static/css/ie.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
margin-left: 1em;
}

.badge > .badge-title {
border-right: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

.badge.badge-with-title > .badge-content {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

/* set default colors as in variant.css for IE11 */
body {
background-color: #ffffff; /* var(--MAIN-BG-color) */
Expand Down Expand Up @@ -481,6 +492,80 @@
border-bottom-color: #ffffff !important; /* var(--MAIN-BG-color) */
}

.badge > * {
border-color: rgba( 16, 16, 16, 1 ); /* var(--BOX-TEXT-color) */
}

.badge > .badge-title {
background-color: rgba( 16, 16, 16, 1 ); /* var(--BOX-TEXT-color) */
color: rgba( 255, 255, 255, .833 ); /* var(--BOX-BG-color) */
}

.badge > .badge-content {
background-color: rgba( 128, 128, 128, 1 ); /* var(--INTERNAL-BOX-NEUTRAL-color) */
color: rgba( 255, 255, 255, 1 ); /* var(--BOX-CAPTION-color) */
}

.badge.info > .badge-content {
background-color: rgba( 48, 117, 229, 1 ); /* var(--INTERNAL-BOX-INFO-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-INFO-TEXT-color) */
}

.badge.warning > .badge-content {
background-color: rgba( 224, 62, 62, 1 ); /* var(--INTERNAL-BOX-WARNING-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-WARNING-TEXT-color) */
}

.badge.note > .badge-content {
background-color: rgba( 237, 153, 9, 1 ); /* var(--INTERNAL-BOX-NOTE-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-NOTE-TEXT-color) */
}

.badge.tip > .badge-content {
background-color: rgba( 42, 178, 24, 1 ); /* var(--INTERNAL-BOX-TIP-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-TIP-TEXT-color) */
}

.badge.primary > .badge-content {
background-color: #7dc903; /* var(--INTERNAL-PRIMARY-color) */
color: #101010; /* var(--INTERNAL-MAIN-TEXT-color) */
}

.badge.secondary > .badge-content {
background-color: #486ac9; /* var(--INTERNAL-SECONDARY-color) */
color: #101010; /* var(--INTERNAL-MAIN-TEXT-color) */
}

.badge.blue > .badge-content {
background-color: rgba( 48, 117, 229, 1 ); /* var(--INTERNAL-BOX-BLUE-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-BLUE-TEXT-color) */
}

.badge.green > .badge-content {
background-color: rgba( 42, 178, 24, 1 ); /* var(--INTERNAL-BOX-GREEN-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-GREEN-TEXT-color) */
}

.badge.grey > .badge-content {
background-color: rgba( 128, 128, 128, 1 ); /* var(--INTERNAL-BOX-GREY-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-GREY-TEXT-color) */
}

.badge.orange > .badge-content {
background-color: rgba( 237, 153, 9, 1 ); /* var(--INTERNAL-BOX-ORANGE-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-ORANGE-TEXT-color) */
}

.badge.red > .badge-content {
background-color: rgba( 224, 62, 62, 1 ); /* var(--INTERNAL-BOX-RED-color) */
color: rgba( 16, 16, 16, 1 ); /* var(--INTERNAL-BOX-RED-TEXT-color) */
}

.badge.transparent > .badge-content {
background-color: transparent;
color: #4a4a4a; /* var(--MAIN-TITLES-TEXT-color) */
}

/* set further styles to fix broken stuff in IE11 */

/* turn off animiation in IE because this causes the menu
Expand Down
Loading

0 comments on commit c45f6dd

Please sign in to comment.