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 File extends Component |
||
12 | { |
||
13 | public string $uuid; |
||
14 | |||
15 | public function __construct( |
||
16 | public ?string $id = null, |
||
17 | public ?string $label = null, |
||
18 | public ?string $hint = null, |
||
19 | public ?string $hintClass = 'fieldset-label', |
||
20 | public ?bool $hideProgress = false, |
||
21 | public ?bool $cropAfterChange = false, |
||
22 | public ?string $changeText = "Change", |
||
23 | public ?string $cropTitleText = "Crop image", |
||
24 | public ?string $cropCancelText = "Cancel", |
||
25 | public ?string $cropSaveText = "Crop", |
||
26 | public ?array $cropConfig = [], |
||
27 | public ?string $cropMimeType = "image/png", |
||
28 | |||
29 | // Validations |
||
30 | public ?string $errorClass = 'text-error', |
||
31 | public ?bool $omitError = false, |
||
32 | public ?bool $firstErrorOnly = false, |
||
33 | ) { |
||
34 | $this->uuid = md5(serialize($this)) . $id; |
||
35 | } |
||
36 | |||
37 | public function modelName(): ?string |
||
38 | { |
||
39 | return $this->attributes->whereStartsWith('wire:model')->first(); |
||
40 | } |
||
41 | |||
42 | public function errorFieldName(): ?string |
||
43 | { |
||
44 | return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first(); |
||
45 | } |
||
46 | |||
47 | public function cropSetup(): string |
||
48 | { |
||
49 | return json_encode(array_merge([ |
||
50 | 'autoCropArea' => 1, |
||
51 | 'viewMode' => 1, |
||
52 | 'dragMode' => 'move' |
||
53 | ], $this->cropConfig)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get the view / contents that represent the component. |
||
58 | */ |
||
59 | public function render(): View|Closure|string |
||
60 | { |
||
61 | return view('components.file'); |
||
62 | } |
||
63 | } |
||
64 |