Repository navigation
Expand file tree
/
Copy pathConfirmationComponent.php
More file actions
82 lines (74 loc) · 2.65 KB
/
Copy pathConfirmationComponent.php
File metadata and controls
82 lines (74 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Modals\View;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use NyonCode\WireCore\Core\Support\Trans;
use NyonCode\WireCore\Foundation\Support\ModalDefaults;
use NyonCode\WireCore\Modals\Support\ConfirmationStyle;
/**
* Blade component: <x-wire-modals::confirmation>
*
* A confirmation dialog with icon, heading, description, and action buttons.
*
* Usage:
* <x-wire-modals::confirmation
* wire:model="showConfirmation"
* heading="Delete record?"
* description="This action cannot be undone."
* icon="trash"
* icon-color="danger"
* submit-label="Delete"
* cancel-label="Cancel"
* color="danger"
* />
*/
class ConfirmationComponent extends Component
{
public function __construct(
public ?string $heading = null,
public ?string $description = null,
public ?string $width = null,
public ?string $icon = null,
public string $iconColor = 'warning',
public ?string $submitLabel = null,
public ?string $cancelLabel = null,
public ?string $color = null,
public bool $isDanger = false,
public bool $isInformative = false,
public ?bool $closeOnClickAway = null,
public ?bool $closeOnEscape = null,
public ?bool $fullScreenOnMobile = null,
public ?bool $slideOverOnMobile = null,
public ?string $breakpoint = null,
public ?string $id = null,
public ?string $closeAction = null,
public ?int $zIndex = null,
public ?string $openOn = null,
) {
// Unset attributes follow config('wire-core.modals') — see ModalDefaults.
$this->width ??= ModalDefaults::width();
$this->closeOnClickAway ??= ModalDefaults::closeOnClickAway();
$this->closeOnEscape ??= ModalDefaults::closeOnEscape();
$this->submitLabel ??= Trans::get('wire-core::actions.confirm_submit');
$this->cancelLabel ??= Trans::get('wire-core::actions.confirm_cancel');
if ($this->isDanger && $this->color === null) {
$this->color = 'danger';
}
}
public function style(): ConfirmationStyle
{
return new ConfirmationStyle(
width: $this->width ?? ModalDefaults::width(),
iconColor: $this->iconColor,
color: $this->color,
fullScreenOnMobile: $this->fullScreenOnMobile,
slideOverOnMobile: $this->slideOverOnMobile,
breakpoint: $this->breakpoint,
);
}
public function render(): View
{
return view('wire-core::modals.confirmation', ['style' => $this->style()]);
}
}