Passed
Pull Request — master (#1022)
by Diego
02:37
created

Alert::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Widget;
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 2
    public function __construct(
60
        $theme = null, $icon = null, $title = null, $dismissable = null
61
    ) {
62 2
        $this->theme = $theme;
63 2
        $this->icon = $icon;
64 2
        $this->title = $title;
65 2
        $this->dismissable = $dismissable;
66
67
        // When a theme is provided, use the default theme icon if no other
68
        // icon is provided.
69
70 2
        if (! isset($icon) && ! empty($theme)) {
71 1
            $this->icon = $this->icons[$theme];
72
        }
73 2
    }
74
75
    /**
76
     * Make the class attribute for the alert item.
77
     *
78
     * @return string
79
     */
80 1
    public function makeAlertClass()
81
    {
82 1
        $classes = ['alert'];
83
84 1
        if (! empty($this->theme)) {
85 1
            $classes[] = "alert-{$this->theme}";
86
        } else {
87 1
            $classes[] = 'border';
88
        }
89
90 1
        if (! empty($this->dismissable)) {
91 1
            $classes[] = 'alert-dismissable';
92
        }
93
94 1
        return implode(' ', $classes);
95
    }
96
97
    /**
98
     * Get the view / contents that represent the component.
99
     *
100
     * @return \Illuminate\View\View|string
101
     */
102 1
    public function render()
103
    {
104 1
        return view('adminlte::components.widget.alert');
105
    }
106
}
107