Passed
Pull Request — master (#721)
by Florian
02:33
created

InputDate::makeItemClass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
class InputDate extends InputGroupComponent
6
{
7
    /**
8
     * The default set of icons for the Tempus Dominus plugin configuration.
9
     */
10
    protected $icons = [
11
        'time'     => 'fas fa-clock',
12
        'date'     => 'fas fa-calendar-alt',
13
        'up'       => 'fas fa-arrow-up',
14
        'down'     => 'fas fa-arrow-down',
15
        'previous' => 'fas fa-chevron-left',
16
        'next'     => 'fas fa-chevron-right',
17
        'today'    => 'fas fa-calendar-check-o',
18
        'clear'    => 'fas fa-trash',
19
        'close'    => 'fas fa-times',
20
    ];
21
22
    /**
23
     * The default set of buttons for the Tempus Dominus plugin configuration.
24
     */
25
    protected $buttons = [
26
        'showClose' => true,
27
    ];
28
29
    /**
30
     * The Tempus Dominus plugin configuration parameters. Array with
31
     * key => value pairs, where the key should be an existing configuration
32
     * property of the plugin.
33
     *
34
     * @var array
35
     */
36
    public $config;
37
38
    /**
39
     * Create a new component instance.
40
     * Note this component requires the 'Tempus Dominus' plugin.
41
     *
42
     * @return void
43
     */
44 2
    public function __construct(
45
        $name, $label = null, $size = null, $labelClass = null,
46
        $topClass = null, $disableFeedback = null, $config = []
47
    ) {
48 2
        parent::__construct(
49 2
            $name, $label, $size, $labelClass, $topClass, $disableFeedback
50
        );
51
52 2
        $this->config = is_array($config) ? $config : [];
53
54
        // Setup the default plugin icons option.
55
56 2
        $this->config['icons'] = $this->config['icons'] ?? $this->icons;
57
58
        // Setup the default plugin buttons option.
59
60 2
        $this->config['buttons'] = $this->config['buttons'] ?? $this->buttons;
61 2
    }
62
63
    /**
64
     * Make the class attribute for the input group item.
65
     *
66
     * @param string $invalid
67
     * @return string
68
     */
69 1
    public function makeItemClass($invalid)
70
    {
71 1
        $classes = ['form-control', 'datetimepicker'];
72
73 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
74 1
            $classes[] = 'is-invalid';
75
        }
76
77 1
        return implode(' ', $classes);
78
    }
79
80
    /**
81
     * Get the view / contents that represent the component.
82
     *
83
     * @return \Illuminate\View\View|string
84
     */
85 1
    public function render()
86
    {
87 1
        return view('adminlte::components.input-date');
88
    }
89
}
90