2021-09-15 15:58:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Views\Components;
|
|
|
|
|
|
|
|
use ViewComponents\Component;
|
|
|
|
|
|
|
|
class Alert extends Component
|
|
|
|
{
|
|
|
|
protected ?string $glyph = null;
|
|
|
|
|
|
|
|
protected ?string $title = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var 'default'|'success'|'danger'|'warning'
|
|
|
|
*/
|
|
|
|
protected string $variant = 'default';
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2022-05-16 11:57:39 +00:00
|
|
|
$variants = [
|
|
|
|
'success' => [
|
|
|
|
'class' => 'text-pine-900 bg-pine-100 border-pine-300',
|
|
|
|
'glyph' => 'check',
|
|
|
|
],
|
|
|
|
'danger' => [
|
|
|
|
'class' => 'text-red-900 bg-red-100 border-red-300',
|
|
|
|
'glyph' => 'close',
|
|
|
|
],
|
|
|
|
'warning' => [
|
|
|
|
'class' => 'text-yellow-900 bg-yellow-100 border-yellow-300',
|
|
|
|
'glyph' => 'alert',
|
|
|
|
],
|
2023-06-21 16:17:11 +00:00
|
|
|
'default' => [
|
|
|
|
'class' => 'text-blue-900 bg-blue-100 border-blue-300',
|
|
|
|
'glyph' => 'error-warning',
|
|
|
|
],
|
2021-09-15 15:58:21 +00:00
|
|
|
];
|
|
|
|
|
2023-06-21 16:17:11 +00:00
|
|
|
if (! array_key_exists($this->variant, $variants)) {
|
|
|
|
$this->variant = 'default';
|
|
|
|
}
|
|
|
|
|
|
|
|
$glyph = icon(($this->glyph === null ? $variants[$this->variant]['glyph'] : $this->glyph), 'flex-shrink-0 mr-2 text-lg');
|
2021-09-15 15:58:21 +00:00
|
|
|
$title = $this->title === null ? '' : '<div class="font-semibold">' . $this->title . '</div>';
|
2022-05-16 11:57:39 +00:00
|
|
|
$class = 'inline-flex w-full p-2 text-sm border rounded ' . $variants[$this->variant]['class'] . ' ' . $this->class;
|
2021-09-15 15:58:21 +00:00
|
|
|
|
2022-02-01 16:08:55 +00:00
|
|
|
unset($this->attributes['slot']);
|
|
|
|
unset($this->attributes['variant']);
|
2023-06-21 16:17:11 +00:00
|
|
|
unset($this->attributes['class']);
|
|
|
|
unset($this->attributes['glyph']);
|
2021-09-15 15:58:21 +00:00
|
|
|
$attributes = stringify_attributes($this->attributes);
|
|
|
|
|
|
|
|
return <<<HTML
|
2021-09-20 15:45:38 +00:00
|
|
|
<div class="{$class}" role="alert" {$attributes}>{$glyph}<div>{$title}<p>{$this->slot}</p></div></div>
|
2021-09-15 15:58:21 +00:00
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
}
|