Passed
Pull Request — master (#832)
by Florian
09:14
created

Alert::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
use Illuminate\View\Component;
6
7
class Alert extends Component
8
{
9
    /**
10
     * The default icon for each alert theme.
11
     *
12
     * @var array
13
     */
14
    protected $icons = [
15
        'dark'      => 'fas fa-bolt',
16
        'light'     => 'far fa-lightbulb',
17
        'primary'   => 'fas fa-bell',
18
        'secondary' => 'fas fa-tag',
19
        'info'      => 'fas fa-info-circle',
20
        'success'   => 'fas fa-check-circle',
21
        'warning'   => 'fas fa-exclamation-triangle',
22
        'danger'    => 'fas fa-ban',
23
    ];
24
25
    /**
26
     * The alert icon (a Font Awesome icon).
27
     *
28
     * @var string
29
     */
30
    public $icon;
31
32
    /**
33
     * The alert theme (dark, light, primary, secondary, info, success, warning
34
     * or danger).
35
     *
36
     * @var string
37
     */
38
    public $theme;
39
40
    /**
41
     * The alert title.
42
     *
43
     * @var string
44
     */
45
    public $title;
46
47
    /**
48
     * Indicates if the alert is dismissable.
49
     *
50
     * @var bool|mixed
51
     */
52
    public $dismissable;
53
54
    /**
55
     * Create a new component instance.
56
     *
57
     * @return void
58
     */
59
    public function __construct(
60
        $theme = 'info', $icon = null, $title = null, $dismissable = null
61
    ) {
62
        $this->theme = $theme;
63
        $this->icon = $icon ?? $this->icons[$theme];
64
        $this->title = $title;
65
        $this->dismissable = $dismissable;
66
    }
67
68
    /**
69
     * Make the class attribute for the alert item.
70
     *
71
     * @return string
72
     */
73
    public function makeAlertClass()
74
    {
75
        $classes = ['alert', "alert-{$this->theme}"];
76
77
        if (! empty($this->dismissable)) {
78
            $classes[] = 'alert-dismissable';
79
        }
80
81
        return implode(' ', $classes);
82
    }
83
84
    /**
85
     * Get the view / contents that represent the component.
86
     *
87
     * @return \Illuminate\View\View|string
88
     */
89
    public function render()
90
    {
91
        return view('adminlte::components.alert');
92
    }
93
}
94