|
1 |
| -{{- /* Modified version of https://github.com/imfing/hextra/blob/v0.10.0/layouts/_partials/shortcodes/badge.html */ -}} |
| 1 | +{{- /* Modified version of https://github.com/imfing/hextra/blob/v0.11.0/layouts/_partials/shortcodes/badge.html */ -}} |
2 | 2 | {{- /* This file overrides the badge partial of the theme */ -}}
|
3 | 3 |
|
4 | 4 | {{- $content := .content -}}
|
5 |
| -{{- $type := .type | default "" -}} |
| 5 | +{{- $color := .color | default .type | default "" -}}{{- /* Compatibility with previous parameter. */ -}} |
6 | 6 | {{- $class := .class | default "" -}}
|
7 | 7 | {{- $border := .border | default false -}}
|
8 | 8 | {{- $icon := .icon | default "" -}}
|
9 |
| -{{- $data := .data | default "" -}} |
10 | 9 |
|
11 |
| -{{- $defaultClass := "hx:text-gray-600 hx:bg-gray-100 hx:dark:bg-neutral-800 hx:dark:text-neutral-200 hx:border-gray-200 hx:dark:border-neutral-700" -}} |
| 10 | +{{- /* Compatibility with previous names. */ -}} |
| 11 | +{{- $mapping := (dict |
| 12 | + "default" "gray" |
| 13 | + "tip" "green" |
| 14 | + "info" "blue" |
| 15 | + "warning" "yellow" |
| 16 | + "error" "red" |
| 17 | + "important" "purple" |
| 18 | + ) |
| 19 | +-}} |
| 20 | +{{- $color = index $mapping $color | default $color | default "gray" -}} |
12 | 21 |
|
13 | 22 | {{- $styleClass := newScratch -}}
|
14 |
| -{{- $styleClass.Set "info" "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} |
15 |
| -{{- $styleClass.Set "warning" "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} |
16 |
| -{{- $styleClass.Set "error" "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} |
| 23 | +{{- $styleClass.Set "gray" "hx:text-gray-600 hx:bg-gray-100 hx:dark:bg-neutral-800 hx:dark:text-neutral-200 hx:border-gray-200 hx:dark:border-neutral-700" -}} |
| 24 | +{{- $styleClass.Set "purple" "hx:border-purple-200 hx:bg-purple-100 hx:text-purple-900 hx:dark:border-purple-200/30 hx:dark:bg-purple-900/30 hx:dark:text-purple-200" -}} |
| 25 | +{{- $styleClass.Set "indigo" "hx:border-indigo-200 hx:bg-indigo-100 hx:text-indigo-900 hx:dark:border-indigo-200/30 hx:dark:bg-indigo-900/30 hx:dark:text-indigo-200" -}} |
| 26 | +{{- $styleClass.Set "blue" "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} |
| 27 | +{{- $styleClass.Set "green" "hx:border-green-200 hx:bg-green-100 hx:text-green-900 hx:dark:border-green-200/30 hx:dark:bg-green-900/30 hx:dark:text-green-200" -}} |
| 28 | +{{- $styleClass.Set "yellow" "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} |
| 29 | +{{- $styleClass.Set "orange" "hx:border-orange-100 hx:bg-orange-50 hx:text-orange-800 hx:dark:border-orange-400/30 hx:dark:bg-orange-400/20 hx:dark:text-orange-300" -}} |
| 30 | +{{- $styleClass.Set "amber" "hx:border-amber-200 hx:bg-amber-100 hx:text-amber-900 hx:dark:border-amber-200/30 hx:dark:bg-amber-900/30 hx:dark:text-amber-200" -}} |
| 31 | +{{- $styleClass.Set "red" "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} |
17 | 32 |
|
18 | 33 | {{- $borderClass := cond (eq $border true) "hx:border" "" -}}
|
19 |
| -{{- $badgeClass := or ($styleClass.Get $type) $defaultClass -}} |
| 34 | +{{- $badgeClass := or ($styleClass.Get $color) ($styleClass.Get "gray") -}} |
20 | 35 |
|
21 | 36 | {{- /* Custom section to handle icon-only badges. */ -}}
|
22 |
| -{{- $iconOnly := hasPrefix $type "icon-only" -}} |
| 37 | +{{- $iconOnly := hasPrefix $color "icon-only" -}} |
23 | 38 | {{- if $iconOnly -}}
|
24 |
| - {{- $icon = (strings.TrimPrefix "icon-only:" $type) -}} |
| 39 | + {{- $icon = (strings.TrimPrefix "icon-only:" $color) -}} |
25 | 40 | {{- $borderClass = "" -}}
|
26 |
| - {{- $defaultClass = "" -}} |
27 | 41 | {{- $badgeClass = "hx:p-2" -}}
|
28 | 42 | {{- end -}}
|
29 | 43 |
|
30 | 44 | {{- /* Custom section to set attributes. */ -}}
|
| 45 | +{{- $data := .data | default "" -}} |
31 | 46 | {{- $attributes := slice -}}
|
32 | 47 | {{- if $iconOnly -}}
|
33 | 48 | {{- $attributes = $attributes | append (printf `title="%s"` $content) -}}
|
|
0 commit comments