Files
livewire-material/resources/views/components/alert.blade.php
T
Andreas Reinhold / reiniandClaude Opus 5 05c3b968ba Draw the alert without Tailwind
Plan step 36 (actions). <x-alert> renders data-md-alert with
data-md-color and data-md-alert-content/-title/-description/-actions/
-dismiss; no class list. alert.css draws the state's tinted container
colour across all eight colours, the medium corner, and the dismiss
button reaching M3's 48px target from its 40px (ACT-18) with its own
state layer, focus ring and touch target. AlertTest is rewritten on
the hooks and ComponentStylesheet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
2026-09-14 16:48:37 +02:00

71 lines
2.9 KiB
PHP

{{-- A notice in the page: a state that needs saying storage is full, the link has expired.
Not an M3 component (M3's banner is gone); drawn in M3's terms: the state's container colour
(tinted, never filled), a medium corner, the state's icon, a title-small `title`, body-medium
text from `description` or the slot, and an `actions` slot for one or two text buttons.
`color` (alias `tone`): `info` (the default), `success`, `warning`, `error`, `primary`,
`secondary`, `tertiary`, or `neutral` for surface-container-high. `icon` replaces the state's
icon; `:icon="false"` drops it. `dismissible` adds a close button that hides it in the browser,
40px drawn with the 48px target M3 asks for (ACT-18).
It is a `role="status"`, whatever its colour: an alert is usually part of the page as it
renders, and `role="alert"` is an assertive live region that some screen readers announce over
the page title on load — and that a Livewire morph re-announces. `assertive` opts into
`role="alert"` for the case the prop is named after: a notice put on screen in answer to
something the person just did (ACT-36). M3 publishes no banner; the nearest thing it does
publish, the snackbar, says polite and never assertive.
Drawn by resources/css/components/alert.css from `data-md-alert` and `data-md-color`; no
class list. --}}
@props([
'title' => null,
'description' => null,
'color' => null,
'tone' => null,
'icon' => null,
'dismissible' => false,
'assertive' => false,
])
@php
$color = in_array($color ?? $tone, ['info', 'success', 'warning', 'error', 'primary', 'secondary', 'tertiary', 'neutral'], true) ? ($color ?? $tone) : 'info';
$icon = $icon === false ? null : ($icon ?? [
'info' => 'info', 'success' => 'check_circle', 'warning' => 'warning', 'error' => 'error',
'primary' => 'info', 'secondary' => 'info', 'tertiary' => 'info', 'neutral' => 'info',
][$color]);
@endphp
<div
role="{{ $assertive ? 'alert' : 'status' }}"
@if ($dismissible) x-data="{ shown: true }" x-show="shown" x-transition.opacity @endif
data-md-alert
data-md-color="{{ $color }}"
{{ $attributes }}
>
@if ($icon)
<x-livewire-material::icon :name="$icon" filled />
@endif
<div data-md-alert-content>
@if ($title)
<p data-md-alert-title>{{ $title }}</p>
@endif
@if ($description || $slot->isNotEmpty())
<div data-md-alert-description>{{ $description ?? $slot }}</div>
@endif
@isset($actions)
<div data-md-alert-actions>{{ $actions }}</div>
@endisset
</div>
@if ($dismissible)
<button type="button" data-md-alert-dismiss aria-label="{{ __('Dismiss') }}" x-on:click="shown = false">
<x-livewire-material::icon name="close" size="20" />
</button>
@endif
</div>