1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\View\Components; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use Illuminate\Contracts\View\View; |
9
|
|
|
use Illuminate\View\Component; |
10
|
|
|
|
11
|
|
|
class Input extends Component |
12
|
|
|
{ |
13
|
|
|
public string $uuid; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Create a new component instance. |
17
|
|
|
*/ |
18
|
|
|
public function __construct( |
19
|
|
|
public ?string $label = null, |
20
|
|
|
public ?string $icon = null, |
21
|
|
|
public ?string $iconRight = null, |
22
|
|
|
public ?string $hint = null, |
23
|
|
|
public ?string $hintClass = 'fieldset-label', |
24
|
|
|
public ?string $prefix = null, |
25
|
|
|
public ?string $suffix = null, |
26
|
|
|
public ?bool $inline = false, |
27
|
|
|
public ?bool $clearable = false, |
28
|
|
|
public ?bool $money = false, |
29
|
|
|
public ?string $locale = 'en-US', |
30
|
|
|
|
31
|
|
|
// Slots |
32
|
|
|
public mixed $prepend = null, |
33
|
|
|
public mixed $append = null, |
34
|
|
|
|
35
|
|
|
// Validations |
36
|
|
|
public ?string $errorClass = 'text-error', |
37
|
|
|
public ?bool $omitError = false, |
38
|
|
|
public ?bool $firstErrorOnly = false, |
39
|
|
|
) { |
40
|
|
|
$this->uuid = md5(serialize($this)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function modelName(): ?string |
44
|
|
|
{ |
45
|
|
|
return $this->attributes->whereStartsWith('wire:model')->first(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function errorFieldName(): ?string |
49
|
|
|
{ |
50
|
|
|
return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function isReadonly(): bool |
54
|
|
|
{ |
55
|
|
|
return $this->attributes->has('readonly') && $this->attributes->get('readonly') === true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function isDisabled(): bool |
59
|
|
|
{ |
60
|
|
|
return $this->attributes->has('disabled') && $this->attributes->get('disabled') === true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function moneySettings(): string |
64
|
|
|
{ |
65
|
|
|
return json_encode([ |
66
|
|
|
'init' => true, |
67
|
|
|
'maskOpts' => [ |
68
|
|
|
'locales' => $this->locale |
69
|
|
|
] |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the view / contents that represent the component. |
75
|
|
|
*/ |
76
|
|
|
public function render(): View|Closure|string |
77
|
|
|
{ |
78
|
|
|
return view('components.input'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|