Repository navigation
Expand file tree
/
Copy pathModalComponent.php
More file actions
75 lines (69 loc) · 2.43 KB
/
Copy pathModalComponent.php
File metadata and controls
75 lines (69 loc) · 2.43 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
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Modals\View;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use NyonCode\WireCore\Foundation\Support\ModalDefaults;
use NyonCode\WireCore\Modals\Support\ModalStyle;
/**
* Blade component: <x-wire-modals::modal>
*
* A general-purpose modal dialog with Alpine.js transitions.
*
* Usage:
* <x-wire-modals::modal
* wire:model="showModal"
* heading="Edit Record"
* description="Update the details."
* width="lg"
* >
* {{-- Modal body content --}}
* </x-wire-modals::modal>
*
* The consumer-facing tag; the framework itself renders the same shell via
* `@include('wire-core::modals.modal', ['style' => new ModalStyle(...), ...])`
* so the core renderer does not depend on this Blade component (Rule 5). All
* presentation/layout logic lives in {@see ModalStyle}.
*/
class ModalComponent extends Component
{
public function __construct(
public ?string $heading = null,
public ?string $description = null,
public ?string $width = null,
public ?string $icon = null,
public string $iconColor = 'gray',
public ?string $maxHeight = null,
public ?bool $closeOnClickAway = null,
public ?bool $closeOnEscape = null,
public ?bool $fullScreenOnMobile = null,
public ?bool $slideOverOnMobile = null,
public bool $stickyFooter = false,
public bool $stickyHeader = false,
public ?string $id = null,
public ?string $closeAction = null,
public ?string $breakpoint = 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();
}
public function style(): ModalStyle
{
return new ModalStyle(
width: $this->width ?? ModalDefaults::width(),
maxHeight: $this->maxHeight,
fullScreenOnMobile: $this->fullScreenOnMobile,
slideOverOnMobile: $this->slideOverOnMobile,
iconColor: $this->iconColor,
breakpoint: $this->breakpoint,
);
}
public function render(): View
{
return view('wire-core::modals.modal', ['style' => $this->style()]);
}
}