Card::isCardHeaderEmpty()   A
last analyzed

Complexity

Conditions 6
Paths 12

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 5
nc 12
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Widget;
4
5
use Illuminate\View\Component;
6
use JeroenNoten\LaravelAdminLte\Helpers\UtilsHelper;
7
8
class Card extends Component
9
{
10
    /**
11
     * The title for the card header.
12
     *
13
     * @var string
14
     */
15
    public $title;
16
17
    /**
18
     * A Font Awesome icon for the card header.
19
     *
20
     * @var string
21
     */
22
    public $icon;
23
24
    /**
25
     * The card theme (light, dark, primary, secondary, info, success,
26
     * warning, danger or any other AdminLTE color like lighblue or teal).
27
     *
28
     * @var string
29
     */
30
    public $theme;
31
32
    /**
33
     * The theme mode (full or outline).
34
     *
35
     * @var string
36
     */
37
    public $themeMode;
38
39
    /**
40
     * Extra classes for the "card-header" element. This provides a way to
41
     * customize the card header container style.
42
     *
43
     * @var string
44
     */
45
    public $headerClass;
46
47
    /**
48
     * Extra classes for the "card-body" element. This provides a way to
49
     * customize the card body container style.
50
     *
51
     * @var string
52
     */
53
    public $bodyClass;
54
55
    /**
56
     * Extra classes for the "card-footer" element. This provides a way to
57
     * customize the card footer container style.
58
     *
59
     * @var string
60
     */
61
    public $footerClass;
62
63
    /**
64
     * Indicates if the card is disabled. When enabled, an overay will show
65
     * over the card.
66
     *
67
     * @var bool|mixed
68
     */
69
    public $disabled;
70
71
    /**
72
     * Indicates if the card is collapsible. When enabled, a button to
73
     * collapse/expand the card will be available. If is set to 'collapsed'
74
     * string, the card will be initiated on collapsed mode.
75
     *
76
     * @var mixed
77
     */
78
    public $collapsible;
79
80
    /**
81
     * Indicates if the card is removable. When enabled, a button to remove
82
     * the card will be available.
83
     *
84
     * @var bool|mixed
85
     */
86
    public $removable;
87
88
    /**
89
     * Indicates if the card is maximizable. When enabled, a button to maximize
90
     * the card will be available.
91
     *
92
     * @var bool|mixed
93
     */
94
    public $maximizable;
95
96
    /**
97
     * Create a new component instance.
98
     *
99
     * @return void
100
     */
101 5
    public function __construct(
102
        $title = null, $icon = null, $theme = null, $themeMode = null,
103
        $headerClass = null, $bodyClass = null, $footerClass = null,
104
        $disabled = null, $collapsible = null, $removable = null,
105
        $maximizable = null
106
    ) {
107 5
        $this->title = UtilsHelper::applyHtmlEntityDecoder($title);
108 5
        $this->icon = $icon;
109 5
        $this->theme = $theme;
110 5
        $this->themeMode = $themeMode;
111 5
        $this->headerClass = $headerClass;
112 5
        $this->bodyClass = $bodyClass;
113 5
        $this->footerClass = $footerClass;
114 5
        $this->disabled = $disabled;
115 5
        $this->removable = $removable;
116 5
        $this->collapsible = $collapsible;
117 5
        $this->maximizable = $maximizable;
118
    }
119
120
    /**
121
     * Make the class attribute for the card.
122
     *
123
     * @return string
124
     */
125 4
    public function makeCardClass()
126
    {
127 4
        $classes = ['card'];
128
129 4
        if (isset($this->theme)) {
130 4
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
131 4
            $classes[] = "{$base}-{$this->theme}";
132
133 4
            if ($this->themeMode === 'outline') {
134 1
                $classes[] = 'card-outline';
135
            }
136
        }
137
138 4
        if ($this->collapsible === 'collapsed') {
139 1
            $classes[] = 'collapsed-card';
140
        }
141
142 4
        return implode(' ', $classes);
143
    }
144
145
    /**
146
     * Make the class attribute for the card header.
147
     *
148
     * @return string
149
     */
150 2
    public function makeCardHeaderClass()
151
    {
152 2
        $classes = ['card-header'];
153
154 2
        if (isset($this->headerClass)) {
155 1
            $classes[] = $this->headerClass;
156
        }
157
158 2
        return implode(' ', $classes);
159
    }
160
161
    /**
162
     * Make the class attribute for the card body.
163
     *
164
     * @return string
165
     */
166 2
    public function makeCardBodyClass()
167
    {
168 2
        $classes = ['card-body'];
169
170 2
        if (isset($this->bodyClass)) {
171 1
            $classes[] = $this->bodyClass;
172
        }
173
174 2
        return implode(' ', $classes);
175
    }
176
177
    /**
178
     * Make the class attribute for the card footer.
179
     *
180
     * @return string
181
     */
182 2
    public function makeCardFooterClass()
183
    {
184 2
        $classes = ['card-footer'];
185
186 2
        if (isset($this->footerClass)) {
187 1
            $classes[] = $this->footerClass;
188
        }
189
190 2
        return implode(' ', $classes);
191
    }
192
193
    /**
194
     * Make the class attribute for the card title.
195
     *
196
     * @return string
197
     */
198 2
    public function makeCardTitleClass()
199
    {
200 2
        $classes = ['card-title'];
201
202 2
        if (isset($this->theme) && $this->themeMode === 'outline') {
203 1
            $classes[] = "text-{$this->theme}";
204
        }
205
206 2
        return implode(' ', $classes);
207
    }
208
209
    /**
210
     * Check if the card header is empty (no items defined for the header).
211
     *
212
     * @param  bool  $hasSlot  Whether the card header slot is defined
213
     * @return bool
214
     */
215 1
    public function isCardHeaderEmpty($hasSlot = false)
216
    {
217 1
        $hasTools = isset($this->collapsible) ||
218 1
                    isset($this->maximizable) ||
219 1
                    isset($this->removable) ||
220 1
                    $hasSlot;
221
222 1
        return empty($this->title) && empty($this->icon) && ! $hasTools;
223
    }
224
225
    /**
226
     * Get the view / contents that represent the component.
227
     *
228
     * @return \Illuminate\View\View|string
229
     */
230 1
    public function render()
231
    {
232 1
        return view('adminlte::components.widget.card');
233
    }
234
}
235