mirror of
https://github.com/imfing/hextra.git
synced 2025-05-12 19:56:26 -04:00
feat: add badge shortcode (#457)
* feat: move badge to a separate partial * feat: badge shortcode * docs: add badge shortcode examples * chore: generate css * docs: add spaces between badges
This commit is contained in:
parent
cabdb421e3
commit
c70900c25f
@ -1176,6 +1176,9 @@ video {
|
||||
.hx-text-4xl {
|
||||
font-size: 2.25rem;
|
||||
}
|
||||
.hx-text-\[\.65rem\] {
|
||||
font-size: .65rem;
|
||||
}
|
||||
.hx-text-\[10px\] {
|
||||
font-size: 10px;
|
||||
}
|
||||
@ -2269,7 +2272,6 @@ article details > summary::before {
|
||||
top: 5px;
|
||||
right: 5px;
|
||||
z-index: 10;
|
||||
font-size: .65rem;
|
||||
}
|
||||
.steps h3 {
|
||||
counter-increment: step;
|
||||
@ -2594,6 +2596,10 @@ nav .search-wrapper {
|
||||
overflow: auto;
|
||||
font-size: .75rem;
|
||||
}
|
||||
.hextra-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
html {
|
||||
font-size: 1rem;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
|
3
assets/css/components/badge.css
Normal file
3
assets/css/components/badge.css
Normal file
@ -0,0 +1,3 @@
|
||||
.hextra-badge {
|
||||
@apply hx-inline-flex hx-items-center;
|
||||
}
|
@ -38,5 +38,4 @@
|
||||
top: 5px;
|
||||
right: 5px;
|
||||
z-index: 10;
|
||||
font-size: .65rem;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
@import "components/code-copy.css";
|
||||
@import "components/hextra/feature-grid.css";
|
||||
@import "components/jupyter.css";
|
||||
@import "components/badge.css";
|
||||
|
||||
html {
|
||||
@apply hx-text-base hx-antialiased;
|
||||
|
@ -10,6 +10,41 @@ sidebar:
|
||||
These shortcodes are considered less stable and may be changed anytime.
|
||||
{{< /callout >}}
|
||||
|
||||
## Badge
|
||||
|
||||
```
|
||||
{{</* badge "Badge" */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< badge "Badge" >}}
|
||||
|
||||
Variants:
|
||||
|
||||
```
|
||||
{{</* badge content="info" type="info" */>}}
|
||||
{{</* badge content="warning" type="warning" */>}}
|
||||
{{</* badge content="error" type="error" */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< badge content="info" type="info" >}}
|
||||
{{< badge content="warning" type="warning" >}}
|
||||
{{< badge content="error" type="error" >}}
|
||||
|
||||
With link:
|
||||
|
||||
```
|
||||
{{</* badge content="Releases" link="https://github.com/imfing/hextra/releases" */>}}
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
{{< badge content="Releases" link="https://github.com/imfing/hextra/releases" >}}
|
||||
|
||||
|
||||
## YouTube
|
||||
|
||||
Embed a YouTube video.
|
||||
|
@ -209,6 +209,7 @@
|
||||
"group-hover:hx-underline",
|
||||
"group-open:before:hx-rotate-90",
|
||||
"hamburger-menu",
|
||||
"hextra-badge",
|
||||
"hextra-card",
|
||||
"hextra-card-icon",
|
||||
"hextra-card-image",
|
||||
@ -464,6 +465,7 @@
|
||||
"hx-sticky",
|
||||
"hx-text-2xl",
|
||||
"hx-text-4xl",
|
||||
"hx-text-[.65rem]",
|
||||
"hx-text-[10px]",
|
||||
"hx-text-[color:hsl(var(--primary-hue),100%,50%)]",
|
||||
"hx-text-base",
|
||||
@ -488,7 +490,6 @@
|
||||
"hx-text-white",
|
||||
"hx-text-xl",
|
||||
"hx-text-xs",
|
||||
"hx-text-xxs",
|
||||
"hx-text-yellow-900",
|
||||
"hx-to-gray-600",
|
||||
"hx-top-0",
|
||||
|
16
layouts/partials/shortcodes/badge.html
Normal file
16
layouts/partials/shortcodes/badge.html
Normal file
@ -0,0 +1,16 @@
|
||||
{{- $content := .content -}}
|
||||
{{- $type := .type -}}
|
||||
{{- $class := .class | default "" -}}
|
||||
{{- $border := .border | default false -}}
|
||||
|
||||
{{- $defaultClass := "hx-text-gray-600 hx-bg-gray-100 dark:hx-bg-neutral-800 dark:hx-text-neutral-200 hx-border-gray-200 dark:hx-border-neutral-700" -}}
|
||||
{{- $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" -}}
|
||||
{{- $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" -}}
|
||||
{{- $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" -}}
|
||||
|
||||
{{- $borderClass := cond (eq $border true) "hx-border" "" -}}
|
||||
{{- $badgeClass := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) -}}
|
||||
<div class="hextra-badge {{ $class }}">
|
||||
<div class="hx-inline-flex hx-items-center hx-rounded-full hx-px-2.5 hx-leading-6 hx-text-[.65rem] {{ $borderClass }} {{ $badgeClass }}">{{- $content -}}</div>
|
||||
</div>
|
||||
{{- /* Strip trailing newline. */ -}}
|
@ -54,15 +54,13 @@
|
||||
{{- end -}}
|
||||
|
||||
{{- if $tag }}
|
||||
{{ $defaultClass := "hx-text-gray-600 hx-text-xxs hx-bg-gray-100 dark:hx-bg-neutral-800 dark:hx-text-neutral-200" }}
|
||||
{{ $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" }}
|
||||
{{ $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" }}
|
||||
{{ $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" }}
|
||||
|
||||
{{ $tagClass := cond (eq $tagType "info") $infoClass (cond (eq $tagType "warning") $warningClass (cond (eq $tagType "error") $errorClass $defaultClass)) }}
|
||||
<div class="hextra-card-tag">
|
||||
<span class="hx-inline-block hx-rounded-full hx-px-2.5 hx-leading-6 {{ $tagClass }}">{{ $tag }}</span>
|
||||
</div>
|
||||
{{- partial "shortcodes/badge.html" (dict
|
||||
"content" $tag
|
||||
"type" $tagType
|
||||
"class" "hextra-card-tag"
|
||||
"border" true
|
||||
)
|
||||
-}}
|
||||
{{- end -}}
|
||||
</a>
|
||||
{{- /* Strip trailing newline. */ -}}
|
||||
|
33
layouts/shortcodes/badge.html
Normal file
33
layouts/shortcodes/badge.html
Normal file
@ -0,0 +1,33 @@
|
||||
{{- if .IsNamedParams -}}
|
||||
{{- $content := .Get "content" -}}
|
||||
{{- $type := .Get "type" | default "" -}}
|
||||
{{- $class := .Get "class" | default "" -}}
|
||||
{{- $link := .Get "link" | default "" -}}
|
||||
|
||||
{{- if $link -}}
|
||||
<a href="{{ $link }}" title="{{ $content | plainify }}" target="_blank">
|
||||
{{- partial "shortcodes/badge.html" (dict
|
||||
"content" $content
|
||||
"type" $type
|
||||
"class" $class
|
||||
"border" true
|
||||
)
|
||||
-}}
|
||||
</a>
|
||||
{{- else -}}
|
||||
{{- partial "shortcodes/badge.html" (dict
|
||||
"content" $content
|
||||
"type" $type
|
||||
"class" $class
|
||||
"border" true
|
||||
)
|
||||
-}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $content := .Get 0 -}}
|
||||
{{- partial "shortcodes/badge.html" (dict
|
||||
"content" $content
|
||||
"border" true
|
||||
)
|
||||
-}}
|
||||
{{- end -}}
|
Loading…
x
Reference in New Issue
Block a user