Repository navigation
Expand file tree
/
Copy pathSlideOverStyle.php
More file actions
173 lines (150 loc) · 6.56 KB
/
Copy pathSlideOverStyle.php
File metadata and controls
173 lines (150 loc) · 6.56 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Modals\Support;
use NyonCode\WireCore\Foundation\Concerns\HasModalProperties;
use NyonCode\WireCore\Foundation\Support\MobileSheet;
/**
* Presentation/layout resolver for the slide-over panel shell.
*
* Extracted verbatim from `SlideOverComponent` (Rule 5 framework-wide, Phase 0)
* so the slide-over 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.
*
* All class strings are full literals — Tailwind scans this file as text, so an
* interpolated `{$bp}:{$x}` would never generate its CSS.
*/
final class SlideOverStyle
{
public function __construct(
private readonly string $width = 'md',
private readonly string $position = 'right',
private readonly bool $bottomSheetOnMobile = false,
private readonly ?string $breakpoint = null,
) {}
private function bp(): string
{
return MobileSheet::breakpoint($this->breakpoint);
}
/** Whether the panel carries a drag handle: only as a bottom sheet, below the breakpoint. */
public function hasGrabber(): bool
{
return $this->bottomSheetOnMobile;
}
/** The breakpoint token the grabber switches at. */
public function breakpoint(): string
{
return $this->bp();
}
public function widthClass(): string
{
// A responsive width (mobile full-width, capped above the breakpoint) lets
// the bottom-sheet span edge-to-edge; the plain slide-over keeps its fixed
// width at every breakpoint. Gate tracks the global mobile breakpoint.
return HasModalProperties::getMaxWidthClass(
$this->width,
responsive: $this->bottomSheetOnMobile,
breakpoint: $this->bp(),
);
}
/**
* Off-screen resting position the panel enters from / leaves to. The plain
* slide-over always slides horizontally from its edge; the bottom-sheet
* mobile mode slides up from the bottom (<sm) and only slides horizontally
* from ≥sm where it becomes a real slide-over.
*/
public function translateEnterStart(): string
{
return $this->offscreenTranslate();
}
public function translateLeaveEnd(): string
{
return $this->offscreenTranslate();
}
public function translateEnterEnd(): string
{
if (! $this->bottomSheetOnMobile) {
return 'translate-x-0';
}
return match ($this->bp()) {
'md' => 'translate-y-0 md:translate-x-0',
'lg' => 'translate-y-0 lg:translate-x-0',
default => 'translate-y-0 sm:translate-x-0',
};
}
public function translateLeaveStart(): string
{
return $this->translateEnterEnd();
}
private function offscreenTranslate(): string
{
if ($this->bottomSheetOnMobile) {
$left = $this->position === 'left';
return match ($this->bp()) {
'md' => $left
? 'translate-y-full motion-reduce:translate-y-0 md:translate-y-0 md:-translate-x-full'
: 'translate-y-full motion-reduce:translate-y-0 md:translate-y-0 md:translate-x-full',
'lg' => $left
? 'translate-y-full motion-reduce:translate-y-0 lg:translate-y-0 lg:-translate-x-full'
: 'translate-y-full motion-reduce:translate-y-0 lg:translate-y-0 lg:translate-x-full',
default => $left
? 'translate-y-full motion-reduce:translate-y-0 sm:translate-y-0 sm:-translate-x-full'
: 'translate-y-full motion-reduce:translate-y-0 sm:translate-y-0 sm:translate-x-full',
};
}
return $this->position === 'left' ? '-translate-x-full' : 'translate-x-full';
}
public function positionClasses(): string
{
// Mobile: full-width tray pinned to the bottom edge. From the breakpoint
// up: edge-pinned slide-over (full height, breathing gap on the inner
// side). Literal strings per (breakpoint, position) so every utility is
// scannable by Tailwind.
if ($this->bottomSheetOnMobile) {
$left = $this->position === 'left';
return match ($this->bp()) {
'md' => $left
? 'inset-x-0 bottom-0 md:inset-x-auto md:top-0 md:bottom-0 md:left-0 md:pr-10'
: 'inset-x-0 bottom-0 md:inset-x-auto md:top-0 md:bottom-0 md:right-0 md:pl-10',
'lg' => $left
? 'inset-x-0 bottom-0 lg:inset-x-auto lg:top-0 lg:bottom-0 lg:left-0 lg:pr-10'
: 'inset-x-0 bottom-0 lg:inset-x-auto lg:top-0 lg:bottom-0 lg:right-0 lg:pl-10',
default => $left
? 'inset-x-0 bottom-0 sm:inset-x-auto sm:top-0 sm:bottom-0 sm:left-0 sm:pr-10'
: 'inset-x-0 bottom-0 sm:inset-x-auto sm:top-0 sm:bottom-0 sm:right-0 sm:pl-10',
};
}
return $this->position === 'left'
? 'inset-y-0 left-0 pr-10'
: 'inset-y-0 right-0 pl-10';
}
public function widthWrapperClasses(): string
{
if (! $this->bottomSheetOnMobile) {
return 'w-screen';
}
return match ($this->bp()) {
'md' => 'w-full md:w-screen',
'lg' => 'w-full lg:w-screen',
default => 'w-full sm:w-screen',
};
}
public function panelClasses(): string
{
// Bottom-sheet mobile: capped height with rounded top corners so the body
// scrolls inside the tray; above the breakpoint it returns to the
// full-height square slide-over panel.
if (! $this->bottomSheetOnMobile) {
return 'h-full';
}
// `overflow-hidden` is what makes the rounding visible: the panel's own
// children paint their own backgrounds (a sticky header is opaque by
// definition), and a square child corner over a rounded parent is simply
// a square corner. It goes away again with the rounding.
return match ($this->bp()) {
'md' => 'max-h-[var(--wire-sheet-h,92dvh)] overflow-hidden rounded-t-2xl md:h-full md:max-h-none md:overflow-visible md:rounded-none',
'lg' => 'max-h-[var(--wire-sheet-h,92dvh)] overflow-hidden rounded-t-2xl lg:h-full lg:max-h-none lg:overflow-visible lg:rounded-none',
default => 'max-h-[var(--wire-sheet-h,92dvh)] overflow-hidden rounded-t-2xl sm:h-full sm:max-h-none sm:overflow-visible sm:rounded-none',
};
}
}