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