Passed
Push — master ( e474fe...0e65bf )
by Diego
02:30
created

Card::makeCardHeaderClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components\Widget;
4
5
use Illuminate\View\Component;
6
7
class Card extends Component
8
{
9
    /**
10
     * The title for the card header.
11
     *
12
     * @var string
13
     */
14
    public $title;
15
16
    /**
17
     * A Font Awesome icon for the card header.
18
     *
19
     * @var string
20
     */
21
    public $icon;
22
23
    /**
24
     * The card theme (light, dark, primary, secondary, info, success,
25
     * warning, danger or any other AdminLTE color like lighblue or teal).
26
     *
27
     * @var string
28
     */
29
    public $theme;
30
31
    /**
32
     * The theme mode (full or outline).
33
     *
34
     * @var string
35
     */
36
    public $themeMode;
37
38
    /**
39
     * Indicates if the card is disabled. When enabled, an overay will show
40
     * over the card.
41
     *
42
     * @var bool|mixed
43
     */
44
    public $disabled;
45
46
    /**
47
     * Indicates if the card is collapsible. When enabled, a button to
48
     * collapse/expand the card will be available. If is set to 'collapsed'
49
     * string, the card will be initiated on collapsed mode.
50
     *
51
     * @var mixed
52
     */
53
    public $collapsible;
54
55
    /**
56
     * Indicates if the card is removable. When enabled, a button to remove
57
     * the card will be available.
58
     *
59
     * @var bool|mixed
60
     */
61
    public $removable;
62
63
    /**
64
     * Indicates if the card is maximizable. When enabled, a button to maximize
65
     * the card will be available.
66
     *
67
     * @var bool|mixed
68
     */
69
    public $maximizable;
70
71
    /**
72
     * Create a new component instance.
73
     *
74
     * @return void
75
     */
76 2
    public function __construct(
77
        $title = null, $icon = null, $theme = null, $themeMode = null,
78
        $disabled = null, $collapsible = null, $removable = null,
79
        $maximizable = null
80
    ) {
81 2
        $this->title = $title;
82 2
        $this->icon = $icon;
83 2
        $this->theme = $theme;
84 2
        $this->themeMode = $themeMode;
85 2
        $this->disabled = $disabled;
86 2
        $this->removable = $removable;
87 2
        $this->collapsible = $collapsible;
88 2
        $this->maximizable = $maximizable;
89 2
    }
90
91
    /**
92
     * Make the class attribute for the card.
93
     *
94
     * @return string
95
     */
96 1
    public function makeCardClass()
97
    {
98 1
        $classes = ['card'];
99
100 1
        if (isset($this->theme)) {
101 1
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
102 1
            $classes[] = "{$base}-{$this->theme}";
103
104 1
            if ($this->themeMode === 'outline') {
105 1
                $classes[] = 'card-outline';
106
            }
107
        }
108
109 1
        if ($this->collapsible === 'collapsed') {
110 1
            $classes[] = 'collapsed-card';
111
        }
112
113 1
        return implode(' ', $classes);
114
    }
115
116
    /**
117
     * Make the class attribute for the card header.
118
     *
119
     * @return string
120
     */
121 1
    public function makeCardHeaderClass()
122
    {
123 1
        $classes = ['card-header'];
124
125 1
        if ($this->isCardHeaderEmpty()) {
126 1
            $classes[] = 'd-none';
127
        }
128
129 1
        return implode(' ', $classes);
130
    }
131
132
    /**
133
     * Make the class attribute for the card title.
134
     *
135
     * @return string
136
     */
137 1
    public function makeCardTitleClass()
138
    {
139 1
        $classes = ['card-title'];
140
141 1
        if (isset($this->theme) && $this->themeMode === 'outline') {
142 1
            $classes[] = "text-{$this->theme}";
143
        }
144
145 1
        return implode(' ', $classes);
146
    }
147
148
    /**
149
     * Check if the card header is empty (no items defined for the header).
150
     *
151
     * @return bool
152
     */
153 1
    protected function isCardHeaderEmpty()
154
    {
155 1
        $hasTools = isset($this->collapsible) ||
156 1
                    isset($this->maximizable) ||
157 1
                    isset($this->removable);
158
159 1
        return empty($this->title) && empty($this->icon) && ! $hasTools;
160
    }
161
162
    /**
163
     * Get the view / contents that represent the component.
164
     *
165
     * @return \Illuminate\View\View|string
166
     */
167 1
    public function render()
168
    {
169 1
        return view('adminlte::components.widget.card');
170
    }
171
}
172