Repository navigation
Expand file tree
/
Copy pathConfirmationStyle.php
More file actions
129 lines (110 loc) · 4.21 KB
/
Copy pathConfirmationStyle.php
File metadata and controls
129 lines (110 loc) · 4.21 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Modals\Support;
use NyonCode\WireCore\Foundation\Concerns\HasColor;
/**
* Presentation resolver for the confirmation dialog shell.
*
* Extracted verbatim from `ConfirmationComponent` (Rule 5 framework-wide,
* Phase 0) so the confirmation shell can be rendered without the Blade
* component and unit-tested in isolation. Per AI_CODING_STANDARD, presentation
* logic belongs in a Support value object, not in the component.
*
* The mobile-sheet variant (bottom-sheet / full-screen below the breakpoint) is
* owned canonically by {@see ModalStyle}; this resolver composes one and
* delegates every variant class to it rather than re-encoding a parallel map, so
* a confirmation honours `slideOverOnMobile()` / `fullScreenOnMobile()` exactly
* like a form modal does.
*/
final class ConfirmationStyle
{
private readonly ModalStyle $layout;
public function __construct(
private readonly string $width = 'md',
private readonly string $iconColor = 'warning',
private readonly ?string $color = null,
?bool $fullScreenOnMobile = null,
?bool $slideOverOnMobile = null,
?string $breakpoint = null,
) {
$this->layout = new ModalStyle(
width: $width,
fullScreenOnMobile: $fullScreenOnMobile,
slideOverOnMobile: $slideOverOnMobile,
iconColor: $iconColor,
breakpoint: $breakpoint,
);
}
/**
* The mobile (< breakpoint) presentation variant: 'bottom-sheet',
* 'full-screen', or null for the default centered dialog.
*/
public function mobileVariant(): ?string
{
return $this->layout->mobileVariant();
}
public function widthClass(): string
{
return $this->layout->widthClass();
}
/** Whether the panel carries a drag handle — see {@see ModalStyle::hasGrabber()}. */
public function hasGrabber(): bool
{
return $this->layout->hasGrabber();
}
/** The breakpoint token the grabber switches at. */
public function breakpoint(): string
{
return $this->layout->breakpoint();
}
/** Bottom padding that keeps the buttons above the home indicator — see {@see ModalStyle::footerSafeAreaClass()}. */
public function footerSafeAreaClass(): string
{
return $this->layout->footerSafeAreaClass();
}
/**
* Panel width behaviour: a mobile sheet is edge-to-edge below the breakpoint
* (`w-full`); the centered dialog keeps its historical shrink-to-content
* width (`sm:w-full`). Both cap at the same gated max-width above it.
*/
public function panelWidthClass(): string
{
$stretch = $this->mobileVariant() !== null ? 'w-full' : 'sm:w-full';
return $stretch.' '.$this->layout->widthClass();
}
/** Wrapper classes positioning the dialog/sheet on mobile. */
public function containerClasses(): string
{
return $this->layout->containerClasses();
}
/** Panel classes for the mobile variant (rounding / flex column / sheet). */
public function panelVariantClasses(): string
{
return $this->layout->panelVariantClasses();
}
/**
* Alpine transition classes per variant: a mobile sheet slides up from the
* bottom; the centered dialog keeps the fade + scale transition.
*
* @return array{enterStart: string, enterEnd: string, leaveStart: string, leaveEnd: string}
*/
public function transitionClasses(): array
{
return $this->layout->transitionClasses();
}
public function iconBgClass(): string
{
return HasColor::getModalIconBgClass($this->iconColor);
}
public function iconColorClass(): string
{
return HasColor::getModalIconTextClass($this->iconColor);
}
public function submitButtonClasses(): string
{
$base = 'inline-flex w-full justify-center rounded-xl px-4 py-2.5 text-sm font-semibold text-white shadow-sm sm:w-auto';
// Delegate the hue map to the canonical owner so this footer stays in
// sync with the table action modal footers instead of re-encoding it.
return "{$base} ".HasColor::getModalSubmitButtonClasses($this->color ?? 'primary');
}
}