Passed
Pull Request — master (#941)
by Diego
07:10
created

Card::makeCardTitleClass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 2
cts 2
cp 1
crap 3
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
     * Extra classes for the "card-body" element. This provides a way to
40
     * customize the card body container style.
41
     *
42
     * @var string
43
     */
44
    public $bodyClass;
45
46
    /**
47
     * Indicates if the card is disabled. When enabled, an overay will show
48
     * over the card.
49
     *
50
     * @var bool|mixed
51
     */
52
    public $disabled;
53
54
    /**
55
     * Indicates if the card is collapsible. When enabled, a button to
56
     * collapse/expand the card will be available. If is set to 'collapsed'
57
     * string, the card will be initiated on collapsed mode.
58
     *
59
     * @var mixed
60
     */
61
    public $collapsible;
62
63
    /**
64
     * Indicates if the card is removable. When enabled, a button to remove
65
     * the card will be available.
66
     *
67
     * @var bool|mixed
68
     */
69
    public $removable;
70
71
    /**
72
     * Indicates if the card is maximizable. When enabled, a button to maximize
73
     * the card will be available.
74
     *
75
     * @var bool|mixed
76 2
     */
77
    public $maximizable;
78
79
    /**
80
     * Create a new component instance.
81 2
     *
82 2
     * @return void
83 2
     */
84 2
    public function __construct(
85 2
        $title = null, $icon = null, $theme = null, $themeMode = null,
86 2
        $bodyClass = null, $disabled = null, $collapsible = null,
87 2
        $removable = null, $maximizable = null
88 2
    ) {
89 2
        $this->title = $title;
90
        $this->icon = $icon;
91
        $this->theme = $theme;
92
        $this->themeMode = $themeMode;
93
        $this->bodyClass = $bodyClass;
94
        $this->disabled = $disabled;
95
        $this->removable = $removable;
96 1
        $this->collapsible = $collapsible;
97
        $this->maximizable = $maximizable;
98 1
    }
99
100 1
    /**
101 1
     * Make the class attribute for the card.
102 1
     *
103
     * @return string
104 1
     */
105 1
    public function makeCardClass()
106
    {
107
        $classes = ['card'];
108
109 1
        if (isset($this->theme)) {
110 1
            $base = $this->themeMode === 'full' ? 'bg-gradient' : 'card';
111
            $classes[] = "{$base}-{$this->theme}";
112
113 1
            if ($this->themeMode === 'outline') {
114
                $classes[] = 'card-outline';
115
            }
116
        }
117
118
        if ($this->collapsible === 'collapsed') {
119
            $classes[] = 'collapsed-card';
120
        }
121 1
122
        return implode(' ', $classes);
123 1
    }
124
125 1
    /**
126 1
     * Make the class attribute for the card body.
127
     *
128
     * @return string
129 1
     */
130
    public function makeCardBodyClass()
131
    {
132
        $classes = ['card-body'];
133
134
        if (isset($this->bodyClass)) {
135
            $classes[] = $this->bodyClass;
136
        }
137 1
138
        return implode(' ', $classes);
139 1
    }
140
141 1
    /**
142 1
     * Make the class attribute for the card header.
143
     *
144
     * @return string
145 1
     */
146
    public function makeCardHeaderClass()
147
    {
148
        $classes = ['card-header'];
149
150
        if ($this->isCardHeaderEmpty()) {
151
            $classes[] = 'd-none';
152
        }
153 1
154
        return implode(' ', $classes);
155 1
    }
156 1
157 1
    /**
158
     * Make the class attribute for the card title.
159 1
     *
160
     * @return string
161
     */
162
    public function makeCardTitleClass()
163
    {
164
        $classes = ['card-title'];
165
166
        if (isset($this->theme) && $this->themeMode === 'outline') {
167 1
            $classes[] = "text-{$this->theme}";
168
        }
169 1
170
        return implode(' ', $classes);
171
    }
172
173
    /**
174
     * Check if the card header is empty (no items defined for the header).
175
     *
176
     * @return bool
177
     */
178
    protected function isCardHeaderEmpty()
179
    {
180
        $hasTools = isset($this->collapsible) ||
181
                    isset($this->maximizable) ||
182
                    isset($this->removable);
183
184
        return empty($this->title) && empty($this->icon) && ! $hasTools;
185
    }
186
187
    /**
188
     * Get the view / contents that represent the component.
189
     *
190
     * @return \Illuminate\View\View|string
191
     */
192
    public function render()
193
    {
194
        return view('adminlte::components.widget.card');
195
    }
196
}
197