refactor(ui): unify notice + toast styling, polish inline notices
Notices used to be styled only inside the toast stack — every inline .notice on the login page, auth pages and admin edit screens fell back to browser defaults and looked unstyled. The Stripe-style toast redesign (icon pill + neutral text + soft card surface) now lives on the base .notice rule, and .app-toast-stack adds the slide-in animation, soft shadow, dismiss button and progress bar on top. Inline notices auto-render the variant icon via a ::before pseudo using the Bootstrap Icons codepoints, so all 30+ existing call sites get the new look without markup changes. Toasts opt out of ::before via :has(> .notice-icon) and keep their explicit icon span. The previous app-flash.phtml partial is folded into app-toast-stack.phtml (both create the same .app-toast-stack container — having both mounted made two stacks fight for the same fixed corner). default/login/page templates now mount the unified partial; the architecture contract is updated to match. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -337,7 +337,6 @@ $componentPageConfig['moduleRuntimeComponents'] = $moduleRuntimeComponents;
|
|||||||
|
|
||||||
<script src="<?php e(assetVersion('vendor/fslightbox/fslightbox.js')); ?>"></script>
|
<script src="<?php e(assetVersion('vendor/fslightbox/fslightbox.js')); ?>"></script>
|
||||||
<?php require __DIR__ . '/partials/app-confirm-dialog.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-confirm-dialog.phtml'; ?>
|
||||||
<?php require __DIR__ . '/partials/app-toast-stack.phtml'; ?>
|
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
<?php require __DIR__ . '/partials/app-search-dialog.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-search-dialog.phtml'; ?>
|
||||||
<?php require __DIR__ . '/partials/app-session-warning-dialog.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-session-warning-dialog.phtml'; ?>
|
||||||
@@ -360,7 +359,7 @@ $componentPageConfig['moduleRuntimeComponents'] = $moduleRuntimeComponents;
|
|||||||
?>
|
?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<script type="application/json" id="page-config-app-components"><?php gridJsonForJs($componentPageConfig); ?></script>
|
<script type="application/json" id="page-config-app-components"><?php gridJsonForJs($componentPageConfig); ?></script>
|
||||||
<?php require __DIR__ . '/partials/app-flash.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-toast-stack.phtml'; ?>
|
||||||
<script type="module" src="<?php e(assetVersion('js/app-init.js')); ?>"></script>
|
<script type="module" src="<?php e(assetVersion('js/app-init.js')); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ $loginComponentConfig = [
|
|||||||
<?php require __DIR__ . '/partials/app-footer.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-footer.phtml'; ?>
|
||||||
|
|
||||||
<script type="application/json" id="page-config-login-components"><?php gridJsonForJs($loginComponentConfig); ?></script>
|
<script type="application/json" id="page-config-login-components"><?php gridJsonForJs($loginComponentConfig); ?></script>
|
||||||
<?php require __DIR__ . '/partials/app-flash.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-toast-stack.phtml'; ?>
|
||||||
<script type="module" src="<?php e(assetVersion('js/app-login-init.js')); ?>"></script>
|
<script type="module" src="<?php e(assetVersion('js/app-login-init.js')); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ if ($bufferTitle !== '') {
|
|||||||
</main>
|
</main>
|
||||||
<?php require __DIR__ . '/partials/app-footer.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-footer.phtml'; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php require __DIR__ . '/partials/app-flash.phtml'; ?>
|
<?php require __DIR__ . '/partials/app-toast-stack.phtml'; ?>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use MintyPHP\Http\Request;
|
|
||||||
use MintyPHP\Session;
|
|
||||||
|
|
||||||
$messages = is_array($appFlashMessages ?? null) ? $appFlashMessages : [];
|
|
||||||
if (!$messages) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$returnTarget = Request::pathWithQuery();
|
|
||||||
$timeouts = [
|
|
||||||
'success' => 5000,
|
|
||||||
'info' => 6000,
|
|
||||||
'warning' => 7000,
|
|
||||||
'error' => 0,
|
|
||||||
];
|
|
||||||
|
|
||||||
?>
|
|
||||||
<div class="app-toast-stack" data-app-component="flash-auto-dismiss" aria-live="polite">
|
|
||||||
<?php foreach ($messages as $message) : ?>
|
|
||||||
<?php $type = $message['type'] ?? 'info'; ?>
|
|
||||||
<?php $timeout = $timeouts[$type] ?? 5000; ?>
|
|
||||||
<?php $isAssertive = $type === 'error' || $type === 'warning'; ?>
|
|
||||||
<div class="notice" data-variant="<?php e($type); ?>" data-flash-timeout="<?php e($timeout); ?>" role="<?php echo $isAssertive ? 'alert' : 'status'; // raw-html-ok: hardcoded ARIA role values ?>">
|
|
||||||
<span><?php e(t($message['message'] ?? '')); ?></span>
|
|
||||||
<form method="post" action="flash/dismiss/<?php e($message['id'] ?? ''); ?>">
|
|
||||||
<input type="hidden" name="return" value="<?php e($returnTarget); ?>">
|
|
||||||
<button type="submit" aria-label="<?php e(t('Dismiss')); ?>"><i class="bi bi-x-lg"></i></button>
|
|
||||||
<?php Session::getCsrfInput(); ?>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
@@ -1,12 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async toast stack — global container for JS-triggered notifications.
|
* Async toast stack — global container for both server-rendered flash
|
||||||
|
* messages and JS-triggered notifications via showAsyncFlash().
|
||||||
*
|
*
|
||||||
* Mounted once at the bottom of the shell so any page can fire toasts via
|
* Mounted once at the bottom of the shell. Empty unless flash messages
|
||||||
* showAsyncFlash() without the JS having to lazy-create the container.
|
* are pending, in which case they render inline and the auto-dismiss
|
||||||
* Empty by default; toasts are appended/removed by web/js/components/app-async-flash.js.
|
* component (data-app-component="flash-auto-dismiss") fades them out.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use MintyPHP\Http\Request;
|
||||||
|
use MintyPHP\Session;
|
||||||
|
|
||||||
|
$messages = is_array($appFlashMessages ?? null) ? $appFlashMessages : [];
|
||||||
|
$timeouts = [
|
||||||
|
'success' => 5000,
|
||||||
|
'info' => 6000,
|
||||||
|
'warning' => 7000,
|
||||||
|
'error' => 0,
|
||||||
|
];
|
||||||
|
$variantIcons = [
|
||||||
|
'success' => 'bi-check-circle-fill',
|
||||||
|
'error' => 'bi-x-octagon-fill',
|
||||||
|
'warning' => 'bi-exclamation-triangle-fill',
|
||||||
|
'info' => 'bi-info-circle-fill',
|
||||||
|
];
|
||||||
|
$returnTarget = Request::pathWithQuery();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="app-toast-stack" aria-live="polite"></div>
|
<div class="app-toast-stack" data-app-component="flash-auto-dismiss" aria-live="polite">
|
||||||
|
<?php foreach ($messages as $message): ?>
|
||||||
|
<?php
|
||||||
|
$type = (string) ($message['type'] ?? 'info');
|
||||||
|
$timeout = $timeouts[$type] ?? 5000;
|
||||||
|
$isAssertive = $type === 'error' || $type === 'warning';
|
||||||
|
$iconClass = $variantIcons[$type] ?? $variantIcons['info'];
|
||||||
|
?>
|
||||||
|
<div class="notice" data-variant="<?php e($type); ?>"
|
||||||
|
data-flash-timeout="<?php e((string) $timeout); ?>"
|
||||||
|
role="<?php echo $isAssertive ? 'alert' : 'status'; // raw-html-ok: hardcoded ARIA role values ?>">
|
||||||
|
<span class="notice-icon" aria-hidden="true">
|
||||||
|
<i class="bi <?php e($iconClass); ?>"></i>
|
||||||
|
</span>
|
||||||
|
<span class="notice-content"><?php e(t($message['message'] ?? '')); ?></span>
|
||||||
|
<form method="post" action="flash/dismiss/<?php e((string) ($message['id'] ?? '')); ?>" class="notice-dismiss-form">
|
||||||
|
<input type="hidden" name="return" value="<?php e($returnTarget); ?>">
|
||||||
|
<button type="submit" class="notice-dismiss" aria-label="<?php e(t('Dismiss')); ?>">
|
||||||
|
<i class="bi bi-x-lg"></i>
|
||||||
|
</button>
|
||||||
|
<?php Session::getCsrfInput(); ?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class FrontendRuntimeHostContractTest extends TestCase
|
|||||||
{
|
{
|
||||||
$defaultTemplate = $this->readProjectFile('templates/default.phtml');
|
$defaultTemplate = $this->readProjectFile('templates/default.phtml');
|
||||||
$loginTemplate = $this->readProjectFile('templates/login.phtml');
|
$loginTemplate = $this->readProjectFile('templates/login.phtml');
|
||||||
$flashPartial = $this->readProjectFile('templates/partials/app-flash.phtml');
|
$flashPartial = $this->readProjectFile('templates/partials/app-toast-stack.phtml');
|
||||||
$topbarPartial = $this->readProjectFile('templates/partials/app-topbar.phtml');
|
$topbarPartial = $this->readProjectFile('templates/partials/app-topbar.phtml');
|
||||||
$asideIconBar = $this->readProjectFile('templates/partials/app-main-aside-icon-bar.phtml');
|
$asideIconBar = $this->readProjectFile('templates/partials/app-main-aside-icon-bar.phtml');
|
||||||
$asidePartial = $this->readProjectFile('templates/partials/app-main-aside.phtml');
|
$asidePartial = $this->readProjectFile('templates/partials/app-main-aside.phtml');
|
||||||
|
|||||||
@@ -1,5 +1,101 @@
|
|||||||
@layer components {
|
@layer components {
|
||||||
/* ── Toast stack: fixed top-right overlay for all flash messages ────── */
|
/* ── Base notice — works inline (auth pages, edit pages) and in toasts ── */
|
||||||
|
|
||||||
|
.notice {
|
||||||
|
--app-notice-accent: var(--app-muted-color);
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: calc(var(--app-spacing) * 0.625);
|
||||||
|
padding: calc(var(--app-spacing) * 0.75) calc(var(--app-spacing) * 0.875);
|
||||||
|
background: var(--app-card-background-color);
|
||||||
|
border: 1px solid var(--app-muted-border-color);
|
||||||
|
border-radius: calc(var(--app-border-radius) * 1.1);
|
||||||
|
color: var(--app-color);
|
||||||
|
font-size: var(--text-sm);
|
||||||
|
line-height: var(--leading-snug);
|
||||||
|
margin-bottom: var(--app-spacing);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Auto-injected variant icon for notices that don't carry an explicit
|
||||||
|
.notice-icon child (= every inline use site). Toasts emit the icon
|
||||||
|
in markup so they opt out via :has(). */
|
||||||
|
.notice:not(:has(> .notice-icon))::before {
|
||||||
|
content: "";
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: color-mix(in srgb, var(--app-notice-accent) 16%, transparent);
|
||||||
|
color: var(--app-notice-accent);
|
||||||
|
font-family: "Bootstrap-icons";
|
||||||
|
font-size: var(--text-base);
|
||||||
|
font-weight: var(--font-regular);
|
||||||
|
line-height: var(--leading-none);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice[data-variant=success]:not(:has(> .notice-icon))::before { content: "\f26a"; }
|
||||||
|
.notice[data-variant=info]:not(:has(> .notice-icon))::before { content: "\f430"; }
|
||||||
|
.notice[data-variant=warning]:not(:has(> .notice-icon))::before { content: "\f33a"; }
|
||||||
|
.notice[data-variant=error]:not(:has(> .notice-icon))::before { content: "\f626"; }
|
||||||
|
|
||||||
|
/* Explicit icon span (used by toasts) — same look as the ::before pseudo. */
|
||||||
|
.notice .notice-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: color-mix(in srgb, var(--app-notice-accent) 16%, transparent);
|
||||||
|
color: var(--app-notice-accent);
|
||||||
|
font-size: var(--text-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Message content slot. Inline notices without an explicit wrapper still
|
||||||
|
work because flex layout picks up the next direct child as content. */
|
||||||
|
.notice .notice-content {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
color: var(--app-color);
|
||||||
|
min-width: 0;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice ul {
|
||||||
|
margin: 0;
|
||||||
|
padding-left: 0;
|
||||||
|
list-style: none;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice ul li {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice ul li + li {
|
||||||
|
margin-top: calc(var(--app-spacing) * 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice p {
|
||||||
|
margin: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Variant accent — drives the icon-pill color. Text stays neutral. */
|
||||||
|
.notice[data-variant=success] { --app-notice-accent: var(--app-notice-success-color); }
|
||||||
|
.notice[data-variant=warning] { --app-notice-accent: var(--app-notice-warning-color); }
|
||||||
|
.notice[data-variant=info] { --app-notice-accent: var(--app-notice-info-color); }
|
||||||
|
.notice[data-variant=error] { --app-notice-accent: var(--app-notice-error-color); }
|
||||||
|
|
||||||
|
/* ── Toast stack: fixed top-right overlay for ephemeral notifications ── */
|
||||||
|
|
||||||
.app-toast-stack {
|
.app-toast-stack {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -39,31 +135,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Individual toast notice ─────────────────────────────────────────── */
|
/* Toast-only enhancements on top of the base .notice. */
|
||||||
|
|
||||||
.app-toast-stack .notice {
|
.app-toast-stack .notice {
|
||||||
--app-notice-border-color: var(--app-muted-border-color);
|
|
||||||
--app-notice-background-color: var(--app-background-color);
|
|
||||||
--app-notice-accent-color: var(--app-color);
|
|
||||||
--_toast-tint: transparent;
|
|
||||||
background: linear-gradient(var(--_toast-tint), var(--_toast-tint)), var(--app-background-color);
|
|
||||||
border: 1px solid color-mix(in srgb, var(--app-notice-border-color) 40%, transparent);
|
|
||||||
border-left: 3px solid var(--app-notice-border-color);
|
|
||||||
border-radius: var(--app-border-radius);
|
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.08);
|
|
||||||
padding: calc(var(--app-spacing) * 0.625) calc(var(--app-spacing) * 0.875);
|
|
||||||
padding-right: calc(var(--app-spacing) * 0.5);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: calc(var(--app-spacing) * 0.75);
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
color: var(--app-notice-border-color);
|
|
||||||
font-size: var(--text-sm);
|
|
||||||
line-height: var(--leading-snug);
|
|
||||||
pointer-events: auto;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.06);
|
||||||
|
pointer-events: auto;
|
||||||
animation: toast-slide-in 250ms ease-out;
|
animation: toast-slide-in 250ms ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,37 +164,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Variant colors ──────────────────────────────────────────────────── */
|
/* ── Progress bar timer (toast only) ─────────────────────────────────── */
|
||||||
|
|
||||||
.app-toast-stack .notice strong {
|
|
||||||
color: var(--app-notice-accent-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice[data-variant=success] {
|
|
||||||
--app-notice-border-color: var(--app-notice-success-border-color);
|
|
||||||
--_toast-tint: var(--app-notice-success-background-color);
|
|
||||||
--app-notice-accent-color: var(--app-notice-success-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice[data-variant=warning] {
|
|
||||||
--app-notice-border-color: var(--app-notice-warning-border-color);
|
|
||||||
--_toast-tint: var(--app-notice-warning-background-color);
|
|
||||||
--app-notice-accent-color: var(--app-notice-warning-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice[data-variant=info] {
|
|
||||||
--app-notice-border-color: var(--app-notice-info-border-color);
|
|
||||||
--_toast-tint: var(--app-notice-info-background-color);
|
|
||||||
--app-notice-accent-color: var(--app-notice-info-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice[data-variant=error] {
|
|
||||||
--app-notice-border-color: var(--app-notice-error-border-color);
|
|
||||||
--_toast-tint: var(--app-notice-error-background-color);
|
|
||||||
--app-notice-accent-color: var(--app-notice-error-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ── Progress bar timer ──────────────────────────────────────────────── */
|
|
||||||
|
|
||||||
.app-toast-stack .notice.flash-timed::after {
|
.app-toast-stack .notice.flash-timed::after {
|
||||||
content: "";
|
content: "";
|
||||||
@@ -127,11 +173,11 @@
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
height: 2px;
|
height: 2px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: var(--app-notice-border-color);
|
background: var(--app-notice-accent);
|
||||||
transform-origin: left;
|
transform-origin: left;
|
||||||
transform: scaleX(0);
|
transform: scaleX(0);
|
||||||
animation: flash-progress var(--flash-timeout, 4000ms) linear forwards;
|
animation: flash-progress var(--flash-timeout, 4000ms) linear forwards;
|
||||||
opacity: 0.7;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-toast-stack .notice.flash-timed:hover::after {
|
.app-toast-stack .notice.flash-timed:hover::after {
|
||||||
@@ -149,37 +195,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Dismiss button ──────────────────────────────────────────────────── */
|
/* ── Dismiss button (toast only) ─────────────────────────────────────── */
|
||||||
|
|
||||||
.app-toast-stack .notice button[type=submit],
|
.app-toast-stack .notice .notice-dismiss-form {
|
||||||
.app-toast-stack .notice button[type=button] {
|
margin: 0;
|
||||||
border: none !important;
|
|
||||||
background: transparent;
|
|
||||||
color: var(--app-notice-border-color);
|
|
||||||
opacity: 0.6;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 2px 4px;
|
|
||||||
line-height: var(--leading-none);
|
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-toast-stack .notice button[type=submit]:hover,
|
.app-toast-stack .notice .notice-dismiss {
|
||||||
.app-toast-stack .notice button[type=button]:hover {
|
border: none !important;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--app-muted-color);
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 4px 6px;
|
||||||
|
line-height: var(--leading-none);
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: opacity 120ms ease, background-color 120ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-toast-stack .notice .notice-dismiss:hover,
|
||||||
|
.app-toast-stack .notice .notice-dismiss:focus-visible {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
background: color-mix(in srgb, var(--app-color) 8%, transparent);
|
||||||
|
|
||||||
/* ── List formatting inside notices ──────────────────────────────────── */
|
|
||||||
|
|
||||||
.app-toast-stack .notice ul {
|
|
||||||
margin: 0;
|
|
||||||
padding-left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice li {
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-toast-stack .notice li:last-child {
|
|
||||||
margin: 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ const defaultTimeouts = {
|
|||||||
|
|
||||||
const MAX_VISIBLE_TOASTS = 5;
|
const MAX_VISIBLE_TOASTS = 5;
|
||||||
|
|
||||||
|
const VARIANT_ICONS = {
|
||||||
|
success: 'bi-check-circle-fill',
|
||||||
|
error: 'bi-x-octagon-fill',
|
||||||
|
warning: 'bi-exclamation-triangle-fill',
|
||||||
|
info: 'bi-info-circle-fill',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the server-rendered toast stack container.
|
* Resolve the server-rendered toast stack container.
|
||||||
* Returns null if the partial is missing — callers must handle that case.
|
* Returns null if the partial is missing — callers must handle that case.
|
||||||
@@ -111,14 +118,26 @@ export function showAsyncFlash(type, message, timeout) {
|
|||||||
notice.setAttribute('aria-live', isAssertive ? 'assertive' : 'polite');
|
notice.setAttribute('aria-live', isAssertive ? 'assertive' : 'polite');
|
||||||
notice.setAttribute('aria-atomic', 'true');
|
notice.setAttribute('aria-atomic', 'true');
|
||||||
|
|
||||||
|
const iconSpan = document.createElement('span');
|
||||||
|
iconSpan.className = 'notice-icon';
|
||||||
|
iconSpan.setAttribute('aria-hidden', 'true');
|
||||||
|
const iconElement = document.createElement('i');
|
||||||
|
iconElement.className = `bi ${VARIANT_ICONS[type] || VARIANT_ICONS.info}`;
|
||||||
|
iconSpan.appendChild(iconElement);
|
||||||
|
notice.appendChild(iconSpan);
|
||||||
|
|
||||||
const messageSpan = document.createElement('span');
|
const messageSpan = document.createElement('span');
|
||||||
|
messageSpan.className = 'notice-content';
|
||||||
messageSpan.textContent = message;
|
messageSpan.textContent = message;
|
||||||
notice.appendChild(messageSpan);
|
notice.appendChild(messageSpan);
|
||||||
|
|
||||||
const closeButton = document.createElement('button');
|
const closeButton = document.createElement('button');
|
||||||
closeButton.type = 'button';
|
closeButton.type = 'button';
|
||||||
|
closeButton.className = 'notice-dismiss';
|
||||||
closeButton.setAttribute('aria-label', 'Dismiss');
|
closeButton.setAttribute('aria-label', 'Dismiss');
|
||||||
closeButton.innerHTML = '<i class="bi bi-x-lg"></i>';
|
const closeIcon = document.createElement('i');
|
||||||
|
closeIcon.className = 'bi bi-x-lg';
|
||||||
|
closeButton.appendChild(closeIcon);
|
||||||
closeButton.addEventListener('click', () => dismissToast(notice));
|
closeButton.addEventListener('click', () => dismissToast(notice));
|
||||||
notice.appendChild(closeButton);
|
notice.appendChild(closeButton);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user