mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-07 10:04:22 +00:00
Refactor toast shortcode
This commit is contained in:
@@ -813,13 +813,13 @@ arguments:
|
|||||||
optional: true
|
optional: true
|
||||||
comment: >-
|
comment: >-
|
||||||
Messages to include in the element. Each element is rendered as a card.
|
Messages to include in the element. Each element is rendered as a card.
|
||||||
# message:
|
message:
|
||||||
# type:
|
type:
|
||||||
# - string
|
- string
|
||||||
# - template.HTML
|
- template.HTML
|
||||||
# optional: false
|
optional: false
|
||||||
# comment: Toast message.
|
comment: Message to display.
|
||||||
# group: partial
|
group: partial
|
||||||
mode:
|
mode:
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
|
@@ -1,27 +1,19 @@
|
|||||||
comment: >-
|
comment: >-
|
||||||
Prepares a toast message. Use a trigger to display the message.
|
Prepares a toast message. Use a trigger to display the message.
|
||||||
arguments:
|
arguments:
|
||||||
|
title:
|
||||||
|
release: v1.0.0
|
||||||
id:
|
id:
|
||||||
type: string
|
class:
|
||||||
optional: true
|
message:
|
||||||
comment: >-
|
group: partial
|
||||||
Unique identifier of the toast message, defaults to `toast-message-n`
|
# deprecated arguments
|
||||||
with sequence n.
|
|
||||||
header:
|
header:
|
||||||
type: string
|
type: string
|
||||||
optional: true
|
optional: true
|
||||||
comment: Header of the toast message. Uses the site title by default.
|
comment: Header of the toast message. Uses the site title by default.
|
||||||
class:
|
deprecated: v1.0.0
|
||||||
type: string
|
alternative: title
|
||||||
optional: true
|
|
||||||
comment: Class attribute of the toast element.
|
|
||||||
message:
|
|
||||||
type:
|
|
||||||
- string
|
|
||||||
- template.HTML
|
|
||||||
optional: false
|
|
||||||
comment: Toast message.
|
|
||||||
group: partial
|
|
||||||
body:
|
body:
|
||||||
type: string
|
type: string
|
||||||
optional: false
|
optional: false
|
||||||
|
@@ -464,11 +464,11 @@ As an example, the following shortcode displays a button that, when clicked, tri
|
|||||||
Show toast 2
|
Show toast 2
|
||||||
{{</* /button */>}}
|
{{</* /button */>}}
|
||||||
|
|
||||||
{{</* toast id="toast-example-1" header="First title" */>}}
|
{{</* toast id="toast-example-1" title="First title" */>}}
|
||||||
This is the first toast message. It supports `markdown.`
|
This is the first toast message. It supports `markdown.`
|
||||||
{{</* /toast */>}}
|
{{</* /toast */>}}
|
||||||
|
|
||||||
{{</* toast id="toast-example-2" header="Second title" */>}}
|
{{</* toast id="toast-example-2" title="Second title" */>}}
|
||||||
This is the second toast message. It supports `markdown.`
|
This is the second toast message. It supports `markdown.`
|
||||||
{{</* /toast */>}}
|
{{</* /toast */>}}
|
||||||
{{< /example >}}
|
{{< /example >}}
|
||||||
|
@@ -412,11 +412,11 @@ H{{</* sub 2 */>}}O est un liquide.
|
|||||||
Affiche la notification #1
|
Affiche la notification #1
|
||||||
{{</* /button */>}}
|
{{</* /button */>}}
|
||||||
|
|
||||||
{{</* toast id="toast-example-1" header="Premier titre" */>}}
|
{{</* toast id="toast-example-1" title="Premier titre" */>}}
|
||||||
Ceci est le premier message de notification. Il prend en charge le `markdown`.
|
Ceci est le premier message de notification. Il prend en charge le `markdown`.
|
||||||
{{</* /toast */>}}
|
{{</* /toast */>}}
|
||||||
|
|
||||||
{{</* toast id="toast-example-2" header="Deuxième titre" */>}}
|
{{</* toast id="toast-example-2" title="Deuxième titre" */>}}
|
||||||
Ceci est le deuxième message de notification. Il prend en charge le `markdown`.
|
Ceci est le deuxième message de notification. Il prend en charge le `markdown`.
|
||||||
{{</* /toast */>}}
|
{{</* /toast */>}}
|
||||||
{{< /example >}}
|
{{< /example >}}
|
||||||
|
@@ -595,46 +595,11 @@
|
|||||||
"fab-medium",
|
"fab-medium",
|
||||||
"fab-whatsapp",
|
"fab-whatsapp",
|
||||||
"fab-x-twitter",
|
"fab-x-twitter",
|
||||||
"faq-3505caedb8ef4b60cf50a8e7418a831e",
|
"faq-4faf1b36c305b1b7fadf914be4a4575a",
|
||||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-heading-faq-3505caedb8ef4b60cf50a8e7418a831e",
|
"faq-4faf1b36c305b1b7fadf914be4a4575a-heading-faq-4faf1b36c305b1b7fadf914be4a4575a",
|
||||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-item-0",
|
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-0",
|
||||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-item-1",
|
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-1",
|
||||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-item-2",
|
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-2",
|
||||||
"faq-4365752cf73e3d0323d965c7a8f83608",
|
|
||||||
"faq-4365752cf73e3d0323d965c7a8f83608-heading-faq-4365752cf73e3d0323d965c7a8f83608",
|
|
||||||
"faq-4365752cf73e3d0323d965c7a8f83608-item-0",
|
|
||||||
"faq-4365752cf73e3d0323d965c7a8f83608-item-1",
|
|
||||||
"faq-4365752cf73e3d0323d965c7a8f83608-item-2",
|
|
||||||
"faq-5bdac500cc974ba75360bad1c12b4cbe",
|
|
||||||
"faq-5bdac500cc974ba75360bad1c12b4cbe-heading-faq-5bdac500cc974ba75360bad1c12b4cbe",
|
|
||||||
"faq-5bdac500cc974ba75360bad1c12b4cbe-item-0",
|
|
||||||
"faq-5bdac500cc974ba75360bad1c12b4cbe-item-1",
|
|
||||||
"faq-5bdac500cc974ba75360bad1c12b4cbe-item-2",
|
|
||||||
"faq-9baf5cd4d7ce43ab479949665cf7d353",
|
|
||||||
"faq-9baf5cd4d7ce43ab479949665cf7d353-heading-faq-9baf5cd4d7ce43ab479949665cf7d353",
|
|
||||||
"faq-9baf5cd4d7ce43ab479949665cf7d353-item-0",
|
|
||||||
"faq-9baf5cd4d7ce43ab479949665cf7d353-item-1",
|
|
||||||
"faq-9baf5cd4d7ce43ab479949665cf7d353-item-2",
|
|
||||||
"faq-9f13742a6624a58162a6cc79409b14d0",
|
|
||||||
"faq-9f13742a6624a58162a6cc79409b14d0-heading-faq-9f13742a6624a58162a6cc79409b14d0",
|
|
||||||
"faq-9f13742a6624a58162a6cc79409b14d0-item-0",
|
|
||||||
"faq-9f13742a6624a58162a6cc79409b14d0-item-1",
|
|
||||||
"faq-9f13742a6624a58162a6cc79409b14d0-item-2",
|
|
||||||
"faq-dd3761ad437ea630ae96757434666ed3",
|
|
||||||
"faq-dd3761ad437ea630ae96757434666ed3-heading-faq-dd3761ad437ea630ae96757434666ed3",
|
|
||||||
"faq-dd3761ad437ea630ae96757434666ed3-item-0",
|
|
||||||
"faq-dd3761ad437ea630ae96757434666ed3-item-1",
|
|
||||||
"faq-dd3761ad437ea630ae96757434666ed3-item-2",
|
|
||||||
"faq-e10cf1daf3a0295c526376fa116a9158",
|
|
||||||
"faq-e10cf1daf3a0295c526376fa116a9158-heading-faq-e10cf1daf3a0295c526376fa116a9158",
|
|
||||||
"faq-e10cf1daf3a0295c526376fa116a9158-item-0",
|
|
||||||
"faq-e10cf1daf3a0295c526376fa116a9158-item-1",
|
|
||||||
"faq-e10cf1daf3a0295c526376fa116a9158-item-2",
|
|
||||||
"faq-f8834091cd6732f0d03d11d0ecd14b3d",
|
|
||||||
"faq-f8834091cd6732f0d03d11d0ecd14b3d-heading-faq-f8834091cd6732f0d03d11d0ecd14b3d",
|
|
||||||
"faq-f8834091cd6732f0d03d11d0ecd14b3d-item-0",
|
|
||||||
"faq-f8834091cd6732f0d03d11d0ecd14b3d-item-1",
|
|
||||||
"faq-f8834091cd6732f0d03d11d0ecd14b3d-item-2",
|
|
||||||
"fas-1",
|
"fas-1",
|
||||||
"fas-2",
|
"fas-2",
|
||||||
"fas-3",
|
"fas-3",
|
||||||
|
@@ -20,12 +20,12 @@
|
|||||||
|
|
||||||
{{/* Initialize arguments */}}
|
{{/* Initialize arguments */}}
|
||||||
{{- $id := $args.id | default (printf "toast-message-%d" 0) -}}
|
{{- $id := $args.id | default (printf "toast-message-%d" 0) -}}
|
||||||
{{ $header := $args.header | default site.Title -}}
|
{{ $title := (or $args.title $args.header) | default site.Title -}}
|
||||||
|
|
||||||
{{/* Main code */}}
|
{{/* Main code */}}
|
||||||
<div id="{{ $id }}" class="toast{{ with $args.class }} {{ . }}{{ end }}" role="alert" aria-live="assertive" aria-atomic="true">
|
<div id="{{ $id }}" class="toast{{ with $args.class }} {{ . }}{{ end }}" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
<div class="toast-header">
|
<div class="toast-header">
|
||||||
{{ with $header }}<strong class="me-auto">{{ . }}</strong>{{ end }}
|
{{ with $title }}<strong class="me-auto">{{ . }}</strong>{{ end }}
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="{{ T "close" }}"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="{{ T "close" }}"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="toast-body">{{ $args.message }}</div>
|
<div class="toast-body">{{ $args.message }}</div>
|
||||||
|
@@ -6,17 +6,22 @@
|
|||||||
|
|
||||||
{{ $error := false }}
|
{{ $error := false }}
|
||||||
|
|
||||||
{{/* Validate arguments */}}
|
{{/* Initialize arguments */}}
|
||||||
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "toast" "args" .Params "group" "shortcode") }}
|
{{ $args := partial "utilities/InitArgs.html" (dict "structure" "toast" "args" .Params "named" .IsNamedParams "group" "shortcode") }}
|
||||||
{{ errorf "Invalid arguments: %s" .Position -}}
|
{{ if or $args.err $args.warnmsg }}
|
||||||
|
{{ partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict
|
||||||
|
"partial" "shortcodes/toast.html"
|
||||||
|
"msg" "Invalid arguments"
|
||||||
|
"details" ($args.errmsg | append $args.warnmsg)
|
||||||
|
"file" page.File
|
||||||
|
"position" .Position
|
||||||
|
)}}
|
||||||
{{ $error = true }}
|
{{ $error = true }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{/* Initialize arguments */}}
|
{{/* Initialize local arguments */}}
|
||||||
{{- $id := .Get "id" | default (printf "toast-message-%d" .Ordinal) -}}
|
{{- $id := $args.id | default (printf "toast-message-%d" .Ordinal) -}}
|
||||||
{{ $header := .Get "header" | default "" -}}
|
|
||||||
{{ $message := trim .Inner " \r\n" | .Page.RenderString -}}
|
{{ $message := trim .Inner " \r\n" | .Page.RenderString -}}
|
||||||
{{- $class := .Get "class" | default "" -}}
|
|
||||||
|
|
||||||
{{ if not $message -}}
|
{{ if not $message -}}
|
||||||
{{ errorf "Missing inner element text: %s" .Position -}}
|
{{ errorf "Missing inner element text: %s" .Position -}}
|
||||||
@@ -25,5 +30,10 @@
|
|||||||
|
|
||||||
{{/* Main code */}}
|
{{/* Main code */}}
|
||||||
{{ if not $error -}}
|
{{ if not $error -}}
|
||||||
{{ partial "assets/toast.html" (dict "id" $id "header" $header "message" $message "class" $class) }}
|
{{ partial "assets/toast.html" (dict
|
||||||
|
"id" $id
|
||||||
|
"title" (or $args.title $args.header)
|
||||||
|
"message" $message
|
||||||
|
"class" $args.class
|
||||||
|
) }}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
Reference in New Issue
Block a user