Passed
Push — master ( 2178f0...b67c9a )
by Reza
11:23
created

BaseInput::labelStyle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace EasyPanel\Parsers\HTMLInputs;
4
5
abstract class BaseInput
6
{
7
    protected $key;
8
    protected $action;
9
    protected $mode;
10
    protected $label;
11
    protected $placeholder;
12
    protected $inputStyle;
13
    protected $labelStyle;
14
    protected $provider;
15
    protected $autocomplete = 'on';
16
17
    public function __construct($label)
18
    {
19
        $this->label = $label;
20
        $this->mode = config('easy_panel.lazy_mode') ? 'wire:model.lazy' : 'wire:model';
21
    }
22
23
    public static function label($label)
24
    {
25
        return new static($label);
26
    }
27
28
    public function inputStyle($inputStyle)
29
    {
30
        $this->inputStyle = $inputStyle;
31
32
        return $this;
33
    }
34
35
    public function labelStyle($labelStyle)
36
    {
37
        $this->labelStyle = $labelStyle;
38
39
        return $this;
40
    }
41
42
    public function setKey($key)
43
    {
44
        $this->key = $key;
45
46
        return $this;
47
    }
48
49
    public function setAction($action)
50
    {
51
        $this->action = $action;
52
53
        return $this;
54
    }
55
56
    public function placeholder($placeholder)
57
    {
58
        $this->placeholder = $placeholder;
59
60
        return $this;
61
    }
62
63
    public function lazyMode()
64
    {
65
        $this->mode = 'wire:model.lazy';
66
67
        return $this;
68
    }
69
70
    public function normalMode()
71
    {
72
        $this->mode = 'wire:model';
73
74
        return $this;
75
    }
76
77
    public function deferMode()
78
    {
79
        $this->mode = 'wire:model.defer';
80
81
        return $this;
82
    }
83
84
    public function withoutAutocomplete()
85
    {
86
        $this->autocomplete = 'off';
87
88
        return $this;
89
    }
90
91
    public function withoutAutofill()
92
    {
93
        $this->withoutAutocomplete();
94
95
        return $this;
96
    }
97
98
    public function render()
99
    {
100
        $array = [
101
            '{{ Title }}' => $this->label,
102
            '{{ Name }}' => $this->key,
103
            '{{ Mode }}' => $this->mode,
104
            '{{ Action }}' => $this->action,
105
            '{{ placeholder }}' => $this->placeholder,
106
            '{{ inputStyle }}' => $this->inputStyle,
107
            '{{ autocomplete }}' => $this->autocomplete,
108
            '{{ Provider }}' => $this->provider,
109
            '{{ labelStyle }}' => $this->labelStyle,
110
        ];
111
112
        return str_replace(array_keys($array), array_values($array), file_get_contents(__DIR__.'/stubs/'.$this->stub));
113
    }
114
115
    public function getTitle()
116
    {
117
        return $this->label;
118
    }
119
120
    public function getPlaceholder()
121
    {
122
        return $this->placeholder;
123
    }
124
125
}
126