BaseInput::setAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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