Repository navigation
Expand file tree
/
Copy pathAlert.php
More file actions
122 lines (96 loc) · 2.81 KB
/
Copy pathAlert.php
File metadata and controls
122 lines (96 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
declare(strict_types=1);
namespace NyonCode\WireForms\Components\Display;
use Closure;
use NyonCode\WireCore\Foundation\Colors\Color;
use NyonCode\WireCore\Foundation\Concerns\HasColor;
use NyonCode\WireCore\Foundation\Icons\Icon;
/**
* Alert/notification display component with color, icon, title, and dismissible options.
*/
class Alert extends Display
{
protected string $color = 'info';
protected ?string $icon = null;
protected string|Closure|null $title = null;
protected bool $dismissible = false;
/** Alias for {@see content()}. */
public function message(string|Closure|null $message): static
{
return $this->content($message);
}
/** Set the alert title shown above the body. */
public function title(string|Closure|null $title): static
{
$this->title = $title;
return $this;
}
/** Set the alert color hue. */
public function color(string|Color $color): static
{
$this->color = $color instanceof Color ? $color->value : $color;
return $this;
}
/** Shortcut for the informational (blue) color. */
public function info(): static
{
return $this->color(Color::Info);
}
/** Shortcut for the success (green) color. */
public function success(): static
{
return $this->color(Color::Success);
}
/** Shortcut for the warning (amber) color. */
public function warning(): static
{
return $this->color(Color::Warning);
}
/** Shortcut for the danger (red) color. */
public function danger(): static
{
return $this->color(Color::Danger);
}
/** Set the leading icon. */
public function icon(string|Icon|null $icon): static
{
$this->icon = $icon instanceof Icon ? $icon->value() : $icon;
return $this;
}
/** Allow the user to dismiss the alert. */
public function dismissible(bool $condition = true): static
{
$this->dismissible = $condition;
return $this;
}
public function getTitle(): ?string
{
return $this->evaluate($this->title);
}
public function getColor(): string
{
return $this->color;
}
/**
* Soft alert surface color classes (background + border + text).
*
* Delegates to the canonical {@see HasColor::getAlertColorClasses()} palette
* so the view only consumes the result instead of re-encoding the hue map.
*/
public function getColorClasses(): string
{
return HasColor::getAlertColorClasses($this->color);
}
public function getIcon(): ?string
{
return $this->icon;
}
public function isDismissible(): bool
{
return $this->dismissible;
}
protected function viewName(): string
{
return 'wire-forms::components.alert';
}
}