Skip to content

Commit d5697cd

Browse files
committed
feat: add Alert component with customizable properties
1 parent 4289bd1 commit d5697cd

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@php
2+
$classes = 'alert alert-' . $type;
3+
4+
if ($dismissible) {
5+
$classes .= ' alert-dismissible fade show';
6+
}
7+
@endphp
8+
9+
<div {{ $attributes->merge(['class' => $classes]) }} role="alert">
10+
@if($icon)
11+
<div class="d-flex align-items-start">
12+
<i class="{{ $icon }} flex-shrink-0 me-2" aria-hidden="true"></i>
13+
<div class="flex-grow-1">
14+
@isset($heading)
15+
<h4 class="alert-heading">{{ $heading }}</h4>
16+
@endisset
17+
18+
{!! $slot !!}
19+
</div>
20+
</div>
21+
@else
22+
@isset($heading)
23+
<h4 class="alert-heading">{{ $heading }}</h4>
24+
@endisset
25+
26+
{!! $slot !!}
27+
@endif
28+
29+
@if($dismissible)
30+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
31+
@endif
32+
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@php
2+
$classes = 'alert alert-' . $type;
3+
4+
if ($dismissible) {
5+
$classes .= ' alert-dismissible fade show';
6+
}
7+
@endphp
8+
9+
<div {{ $attributes->merge(['class' => $classes]) }} role="alert">
10+
@if($icon)
11+
<div class="d-flex align-items-start">
12+
<i class="{{ $icon }} flex-shrink-0 me-2" aria-hidden="true"></i>
13+
<div class="flex-grow-1">
14+
@isset($heading)
15+
<h4 class="alert-heading">{{ $heading }}</h4>
16+
@endisset
17+
18+
{!! $slot !!}
19+
</div>
20+
</div>
21+
@else
22+
@isset($heading)
23+
<h4 class="alert-heading">{{ $heading }}</h4>
24+
@endisset
25+
26+
{!! $slot !!}
27+
@endif
28+
29+
@if($dismissible)
30+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
31+
<span aria-hidden="true">&times;</span>
32+
</button>
33+
@endif
34+
</div>

src/Views/Components/Alert.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Javaabu\Forms\Views\Components;
4+
5+
class Alert extends Component
6+
{
7+
protected string $view = 'alert';
8+
9+
public string $type;
10+
public string $icon;
11+
public bool $dismissible;
12+
13+
public string $heading;
14+
15+
/**
16+
* Create a new component instance.
17+
*
18+
* @return void
19+
*/
20+
public function __construct(
21+
string $type = 'primary',
22+
bool $dismissible = false,
23+
string $icon = null,
24+
string $heading = '',
25+
string $framework = ''
26+
)
27+
{
28+
parent::__construct($framework);
29+
30+
$this->type = $type;
31+
$this->dismissible = $dismissible;
32+
$this->icon = $icon;
33+
$this->heading = $heading;
34+
}
35+
}

0 commit comments

Comments
 (0)