|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xetaravel\View\Components; |
|
4
|
|
|
|
|
5
|
|
|
use Closure; |
|
6
|
|
|
use Illuminate\Contracts\View\View; |
|
7
|
|
|
use Illuminate\Support\Collection; |
|
8
|
|
|
use Illuminate\View\Component; |
|
9
|
|
|
|
|
10
|
|
|
class Select extends Component |
|
11
|
|
|
{ |
|
12
|
|
|
public string $uuid; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct( |
|
15
|
|
|
public ?string $label = null, |
|
16
|
|
|
public ?string $icon = null, |
|
17
|
|
|
public ?string $iconRight = null, |
|
18
|
|
|
public ?string $hint = null, |
|
19
|
|
|
public ?string $hintClass = 'fieldset-label', |
|
20
|
|
|
public ?string $prefix = null, |
|
21
|
|
|
public ?string $suffix = null, |
|
22
|
|
|
public ?string $placeholder = null, |
|
23
|
|
|
public ?string $placeholderValue = null, |
|
24
|
|
|
public ?bool $inline = false, |
|
25
|
|
|
public ?string $optionValue = 'id', |
|
26
|
|
|
public ?string $optionLabel = 'name', |
|
27
|
|
|
public ?string $optionClass = '', |
|
28
|
|
|
public ?string $optionStyle = '', |
|
29
|
|
|
public Collection|array $options = new Collection(), |
|
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
|
|
|
/** |
|
54
|
|
|
* Get the view / contents that represent the component. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function render(): View|Closure|string |
|
57
|
|
|
{ |
|
58
|
|
|
return view('components.select'); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|