mirror of
https://github.com/gethinode/hinode.git
synced 2025-10-07 01:54:23 +00:00
Refactor toast shortcode
This commit is contained in:
@@ -813,13 +813,13 @@ arguments:
|
||||
optional: true
|
||||
comment: >-
|
||||
Messages to include in the element. Each element is rendered as a card.
|
||||
# message:
|
||||
# type:
|
||||
# - string
|
||||
# - template.HTML
|
||||
# optional: false
|
||||
# comment: Toast message.
|
||||
# group: partial
|
||||
message:
|
||||
type:
|
||||
- string
|
||||
- template.HTML
|
||||
optional: false
|
||||
comment: Message to display.
|
||||
group: partial
|
||||
mode:
|
||||
type: bool
|
||||
default: false
|
||||
|
@@ -1,27 +1,19 @@
|
||||
comment: >-
|
||||
Prepares a toast message. Use a trigger to display the message.
|
||||
arguments:
|
||||
title:
|
||||
release: v1.0.0
|
||||
id:
|
||||
type: string
|
||||
optional: true
|
||||
comment: >-
|
||||
Unique identifier of the toast message, defaults to `toast-message-n`
|
||||
with sequence n.
|
||||
class:
|
||||
message:
|
||||
group: partial
|
||||
# deprecated arguments
|
||||
header:
|
||||
type: string
|
||||
optional: true
|
||||
comment: Header of the toast message. Uses the site title by default.
|
||||
class:
|
||||
type: string
|
||||
optional: true
|
||||
comment: Class attribute of the toast element.
|
||||
message:
|
||||
type:
|
||||
- string
|
||||
- template.HTML
|
||||
optional: false
|
||||
comment: Toast message.
|
||||
group: partial
|
||||
deprecated: v1.0.0
|
||||
alternative: title
|
||||
body:
|
||||
type: string
|
||||
optional: false
|
||||
|
@@ -464,11 +464,11 @@ As an example, the following shortcode displays a button that, when clicked, tri
|
||||
Show toast 2
|
||||
{{</* /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.`
|
||||
{{</* /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.`
|
||||
{{</* /toast */>}}
|
||||
{{< /example >}}
|
||||
|
@@ -412,11 +412,11 @@ H{{</* sub 2 */>}}O est un liquide.
|
||||
Affiche la notification #1
|
||||
{{</* /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`.
|
||||
{{</* /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`.
|
||||
{{</* /toast */>}}
|
||||
{{< /example >}}
|
||||
|
@@ -595,46 +595,11 @@
|
||||
"fab-medium",
|
||||
"fab-whatsapp",
|
||||
"fab-x-twitter",
|
||||
"faq-3505caedb8ef4b60cf50a8e7418a831e",
|
||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-heading-faq-3505caedb8ef4b60cf50a8e7418a831e",
|
||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-item-0",
|
||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-item-1",
|
||||
"faq-3505caedb8ef4b60cf50a8e7418a831e-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",
|
||||
"faq-4faf1b36c305b1b7fadf914be4a4575a",
|
||||
"faq-4faf1b36c305b1b7fadf914be4a4575a-heading-faq-4faf1b36c305b1b7fadf914be4a4575a",
|
||||
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-0",
|
||||
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-1",
|
||||
"faq-4faf1b36c305b1b7fadf914be4a4575a-item-2",
|
||||
"fas-1",
|
||||
"fas-2",
|
||||
"fas-3",
|
||||
|
@@ -20,12 +20,12 @@
|
||||
|
||||
{{/* Initialize arguments */}}
|
||||
{{- $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 */}}
|
||||
<div id="{{ $id }}" class="toast{{ with $args.class }} {{ . }}{{ end }}" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<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>
|
||||
</div>
|
||||
<div class="toast-body">{{ $args.message }}</div>
|
||||
|
@@ -6,17 +6,22 @@
|
||||
|
||||
{{ $error := false }}
|
||||
|
||||
{{/* Validate arguments */}}
|
||||
{{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "toast" "args" .Params "group" "shortcode") }}
|
||||
{{ errorf "Invalid arguments: %s" .Position -}}
|
||||
{{/* Initialize arguments */}}
|
||||
{{ $args := partial "utilities/InitArgs.html" (dict "structure" "toast" "args" .Params "named" .IsNamedParams "group" "shortcode") }}
|
||||
{{ 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 }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Initialize arguments */}}
|
||||
{{- $id := .Get "id" | default (printf "toast-message-%d" .Ordinal) -}}
|
||||
{{ $header := .Get "header" | default "" -}}
|
||||
{{/* Initialize local arguments */}}
|
||||
{{- $id := $args.id | default (printf "toast-message-%d" .Ordinal) -}}
|
||||
{{ $message := trim .Inner " \r\n" | .Page.RenderString -}}
|
||||
{{- $class := .Get "class" | default "" -}}
|
||||
|
||||
{{ if not $message -}}
|
||||
{{ errorf "Missing inner element text: %s" .Position -}}
|
||||
@@ -25,5 +30,10 @@
|
||||
|
||||
{{/* Main code */}}
|
||||
{{ 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 -}}
|
||||
|
Reference in New Issue
Block a user