@shellui/core 0.4.1 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +15 -3
- package/schemas/curated-themes.json +4035 -0
- package/schemas/shellui.config.schema.json +961 -0
- package/schemas/shellui.theme.schema.json +187 -0
- package/src/app.tsx +4 -1
- package/src/components/ContentView.tsx +144 -9
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +23 -5
- package/src/components/ui/drawer.tsx +282 -42
- package/src/components/ui/dropdown-menu.tsx +7 -2
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +220 -0
- package/src/components/ui/sidebar.tsx +785 -221
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/admin/utils.ts +2 -45
- package/src/features/alertDialog/DialogContext.tsx +1 -1
- package/src/features/auth/components/LoginButton.tsx +25 -18
- package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
- package/src/features/auth/components/LoginView.tsx +131 -49
- package/src/features/config/types.ts +64 -82
- package/src/features/drawer/DrawerContext.tsx +55 -19
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +376 -77
- package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
- package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
- package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
- package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
- package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
- package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
- package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
- package/src/features/layouts/chrome/constants.ts +11 -0
- package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
- package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
- package/src/features/layouts/chrome/index.ts +26 -0
- package/src/features/layouts/chrome/runtime.ts +45 -0
- package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
- package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
- package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
- package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
- package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
- package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
- package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
- package/src/features/layouts/sidebar/types.ts +3 -3
- package/src/features/layouts/utils.ts +73 -5
- package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
- package/src/features/modal/ModalContext.tsx +21 -8
- package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
- package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
- package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
- package/src/features/overlays/ResponsiveModal.tsx +483 -0
- package/src/features/overlays/overlaySize.spec.ts +71 -0
- package/src/features/overlays/overlaySize.ts +228 -0
- package/src/features/overlays/useOverlayReportedSize.ts +130 -0
- package/src/features/settings/SettingsProvider.tsx +66 -46
- package/src/features/settings/SettingsView.tsx +42 -47
- package/src/features/settings/components/Appearance.tsx +305 -55
- package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
- package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
- package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
- package/src/features/theme/applyTheme.ts +143 -0
- package/src/features/theme/color.ts +83 -0
- package/src/features/theme/curated/amber-minimal.json +86 -0
- package/src/features/theme/curated/amethyst-haze.json +86 -0
- package/src/features/theme/curated/astro-vista.json +86 -0
- package/src/features/theme/curated/bold-tech.json +86 -0
- package/src/features/theme/curated/bubblegum.json +86 -0
- package/src/features/theme/curated/caffeine.json +83 -0
- package/src/features/theme/curated/candyland.json +86 -0
- package/src/features/theme/curated/catppuccin.json +86 -0
- package/src/features/theme/curated/claude.json +86 -0
- package/src/features/theme/curated/claymorphism.json +86 -0
- package/src/features/theme/curated/clean-slate.json +86 -0
- package/src/features/theme/curated/cosmic-night.json +86 -0
- package/src/features/theme/curated/cyberpunk.json +86 -0
- package/src/features/theme/curated/darkmatter.json +86 -0
- package/src/features/theme/curated/doom-64.json +86 -0
- package/src/features/theme/curated/elegant-luxury.json +86 -0
- package/src/features/theme/curated/graphite.json +86 -0
- package/src/features/theme/curated/index.ts +260 -0
- package/src/features/theme/curated/kodama-grove.json +86 -0
- package/src/features/theme/curated/light-green.json +87 -0
- package/src/features/theme/curated/midnight-bloom.json +86 -0
- package/src/features/theme/curated/mocha-mousse.json +86 -0
- package/src/features/theme/curated/modern-minimal.json +86 -0
- package/src/features/theme/curated/mono.json +84 -0
- package/src/features/theme/curated/nature.json +86 -0
- package/src/features/theme/curated/neo-brutalism.json +86 -0
- package/src/features/theme/curated/northern-lights.json +86 -0
- package/src/features/theme/curated/notebook.json +87 -0
- package/src/features/theme/curated/ocean-breeze.json +86 -0
- package/src/features/theme/curated/pastel-dreams.json +86 -0
- package/src/features/theme/curated/perpetuity.json +86 -0
- package/src/features/theme/curated/quantum-rose.json +86 -0
- package/src/features/theme/curated/retro-arcade.json +86 -0
- package/src/features/theme/curated/sage-garden.json +86 -0
- package/src/features/theme/curated/shadcn.json +83 -0
- package/src/features/theme/curated/shellui.json +82 -0
- package/src/features/theme/curated/soft-pop.json +86 -0
- package/src/features/theme/curated/solar-dusk.json +86 -0
- package/src/features/theme/curated/starry-night.json +86 -0
- package/src/features/theme/curated/sunset-horizon.json +86 -0
- package/src/features/theme/curated/supabase.json +85 -0
- package/src/features/theme/curated/t3-chat.json +83 -0
- package/src/features/theme/curated/tangerine.json +86 -0
- package/src/features/theme/curated/twitter.json +86 -0
- package/src/features/theme/curated/vercel.json +86 -0
- package/src/features/theme/curated/vintage-paper.json +86 -0
- package/src/features/theme/curated/violet-bloom.json +87 -0
- package/src/features/theme/curated/zen-inspired.json +87 -0
- package/src/features/theme/index.ts +76 -0
- package/src/features/theme/normalize.ts +159 -0
- package/src/features/theme/registry.ts +50 -0
- package/src/features/theme/resolveConfig.ts +182 -0
- package/src/features/theme/safeApplyTheme.ts +147 -0
- package/src/features/theme/themes.spec.ts +276 -0
- package/src/features/theme/themes.ts +82 -558
- package/src/features/theme/tokenKeys.ts +60 -0
- package/src/features/theme/types.ts +170 -0
- package/src/features/theme/useTheme.tsx +48 -50
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/i18n/translations/en/common.json +41 -0
- package/src/i18n/translations/en/settings.json +10 -2
- package/src/i18n/translations/fr/common.json +41 -0
- package/src/i18n/translations/fr/settings.json +10 -2
- package/src/index.css +372 -128
- package/src/index.ts +71 -0
- package/src/lib/z-index.ts +4 -1
- package/src/routes/components/IndexRoute.tsx +12 -2
- package/src/routes/components/NavigationItemRoute.tsx +1 -10
- package/src/routes/hooks/useNavigationItems.ts +29 -44
- package/src/routes/routes.tsx +58 -27
- package/tailwind.config.js +27 -27
- package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
- package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useState,
|
|
6
|
+
type CSSProperties,
|
|
7
|
+
type PointerEvent as ReactPointerEvent,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../../components/ui/dialog';
|
|
11
|
+
import { cn } from '../../lib/utils';
|
|
12
|
+
|
|
13
|
+
export type ResponsiveModalPresentation = 'dialog' | 'sheet';
|
|
14
|
+
|
|
15
|
+
const SWIPE_DISMISS_PX = 80;
|
|
16
|
+
const SWIPE_DISMISS_RATIO = 0.2;
|
|
17
|
+
const MIN_WIDTH = 320;
|
|
18
|
+
const MIN_HEIGHT = 240;
|
|
19
|
+
const VIEWPORT_MARGIN = 8;
|
|
20
|
+
|
|
21
|
+
type ResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw';
|
|
22
|
+
|
|
23
|
+
type ModalGeometry = {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface ResponsiveModalProps {
|
|
31
|
+
open: boolean;
|
|
32
|
+
onOpenChange: (open: boolean) => void;
|
|
33
|
+
presentation: ResponsiveModalPresentation;
|
|
34
|
+
/** Size / layout classes for the active presentation. */
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
title: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
showCloseButton?: boolean;
|
|
40
|
+
dismissible?: boolean;
|
|
41
|
+
closeOnOverlayClick?: boolean;
|
|
42
|
+
/** Show drag handle in sheet mode when dismissible. */
|
|
43
|
+
showDragHandle?: boolean;
|
|
44
|
+
/** Desktop dialog: drag by title bar. Default true. */
|
|
45
|
+
movable?: boolean;
|
|
46
|
+
/** Desktop dialog: resize from edges/corners. Default true. */
|
|
47
|
+
resizable?: boolean;
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function clampGeometry(geo: ModalGeometry): ModalGeometry {
|
|
52
|
+
const maxW = Math.max(MIN_WIDTH, window.innerWidth - VIEWPORT_MARGIN * 2);
|
|
53
|
+
const maxH = Math.max(MIN_HEIGHT, window.innerHeight - VIEWPORT_MARGIN * 2);
|
|
54
|
+
const width = Math.min(Math.max(geo.width, MIN_WIDTH), maxW);
|
|
55
|
+
const height = Math.min(Math.max(geo.height, MIN_HEIGHT), maxH);
|
|
56
|
+
const x = Math.min(
|
|
57
|
+
Math.max(geo.x, VIEWPORT_MARGIN),
|
|
58
|
+
Math.max(VIEWPORT_MARGIN, window.innerWidth - width - VIEWPORT_MARGIN),
|
|
59
|
+
);
|
|
60
|
+
const y = Math.min(
|
|
61
|
+
Math.max(geo.y, VIEWPORT_MARGIN),
|
|
62
|
+
Math.max(VIEWPORT_MARGIN, window.innerHeight - height - VIEWPORT_MARGIN),
|
|
63
|
+
);
|
|
64
|
+
return { x, y, width, height };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Shrink to viewport and re-center — used on browser resize so the modal is never cut off. */
|
|
68
|
+
function fitGeometryToViewport(geo: ModalGeometry): ModalGeometry {
|
|
69
|
+
const maxW = Math.max(MIN_WIDTH, window.innerWidth - VIEWPORT_MARGIN * 2);
|
|
70
|
+
const maxH = Math.max(MIN_HEIGHT, window.innerHeight - VIEWPORT_MARGIN * 2);
|
|
71
|
+
const width = Math.min(Math.max(geo.width, MIN_WIDTH), maxW);
|
|
72
|
+
const height = Math.min(Math.max(geo.height, MIN_HEIGHT), maxH);
|
|
73
|
+
const x = Math.max(VIEWPORT_MARGIN, (window.innerWidth - width) / 2);
|
|
74
|
+
const y = Math.max(VIEWPORT_MARGIN, (window.innerHeight - height) / 2);
|
|
75
|
+
return { x, y, width, height };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Match responsive-modal-fade-out so geometry survives the close animation. */
|
|
79
|
+
const CLOSE_GEOMETRY_CLEAR_MS = 250;
|
|
80
|
+
|
|
81
|
+
const RESIZE_HANDLES: { edge: ResizeEdge; className: string; cursor: string }[] = [
|
|
82
|
+
// Top edge is reserved for move (see move handle below), not north-resize
|
|
83
|
+
{ edge: 's', className: 'left-3 right-3 bottom-0 h-1.5 translate-y-1/2', cursor: 'ns-resize' },
|
|
84
|
+
{ edge: 'e', className: 'top-3 bottom-3 right-0 w-1.5 translate-x-1/2', cursor: 'ew-resize' },
|
|
85
|
+
{ edge: 'w', className: 'top-3 bottom-3 left-0 w-1.5 -translate-x-1/2', cursor: 'ew-resize' },
|
|
86
|
+
{
|
|
87
|
+
edge: 'ne',
|
|
88
|
+
className: 'right-0 top-0 h-3 w-3 translate-x-1/2 -translate-y-1/2',
|
|
89
|
+
cursor: 'nesw-resize',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
edge: 'nw',
|
|
93
|
+
className: 'left-0 top-0 h-3 w-3 -translate-x-1/2 -translate-y-1/2',
|
|
94
|
+
cursor: 'nwse-resize',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
edge: 'se',
|
|
98
|
+
className: 'right-0 bottom-0 h-3 w-3 translate-x-1/2 translate-y-1/2',
|
|
99
|
+
cursor: 'nwse-resize',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
edge: 'sw',
|
|
103
|
+
className: 'left-0 bottom-0 h-3 w-3 -translate-x-1/2 translate-y-1/2',
|
|
104
|
+
cursor: 'nesw-resize',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Single Radix Dialog host for `openModal`.
|
|
110
|
+
* Presentation morphs between centered dialog and bottom sheet via CSS —
|
|
111
|
+
* children (iframe) stay mounted across breakpoint changes.
|
|
112
|
+
* Dialog mode is movable/resizable by default.
|
|
113
|
+
*/
|
|
114
|
+
export function ResponsiveModal({
|
|
115
|
+
open,
|
|
116
|
+
onOpenChange,
|
|
117
|
+
presentation,
|
|
118
|
+
className,
|
|
119
|
+
style,
|
|
120
|
+
title,
|
|
121
|
+
description,
|
|
122
|
+
showCloseButton = true,
|
|
123
|
+
dismissible = true,
|
|
124
|
+
closeOnOverlayClick = true,
|
|
125
|
+
showDragHandle = true,
|
|
126
|
+
movable = true,
|
|
127
|
+
resizable = true,
|
|
128
|
+
children,
|
|
129
|
+
}: ResponsiveModalProps) {
|
|
130
|
+
const isSheet = presentation === 'sheet';
|
|
131
|
+
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
132
|
+
const dragStartY = useRef<number | null>(null);
|
|
133
|
+
const dragCurrentY = useRef(0);
|
|
134
|
+
const [sheetDragOffset, setSheetDragOffset] = useState(0);
|
|
135
|
+
const [isSheetDragging, setIsSheetDragging] = useState(false);
|
|
136
|
+
|
|
137
|
+
const [geometry, setGeometry] = useState<ModalGeometry | null>(null);
|
|
138
|
+
const geometryRef = useRef<ModalGeometry | null>(null);
|
|
139
|
+
const dialogGeometryCache = useRef<ModalGeometry | null>(null);
|
|
140
|
+
const interactStart = useRef<{
|
|
141
|
+
pointerX: number;
|
|
142
|
+
pointerY: number;
|
|
143
|
+
geo: ModalGeometry;
|
|
144
|
+
edge?: ResizeEdge;
|
|
145
|
+
} | null>(null);
|
|
146
|
+
const [isWindowInteracting, setIsWindowInteracting] = useState(false);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
geometryRef.current = geometry;
|
|
150
|
+
}, [geometry]);
|
|
151
|
+
|
|
152
|
+
// Keep custom geometry through the close animation; clear after it finishes
|
|
153
|
+
// so the next open starts centered (no snap-back mid-exit).
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (open) {
|
|
156
|
+
// Fresh open — always start from default centered layout
|
|
157
|
+
setGeometry(null);
|
|
158
|
+
dialogGeometryCache.current = null;
|
|
159
|
+
interactStart.current = null;
|
|
160
|
+
setIsWindowInteracting(false);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
interactStart.current = null;
|
|
164
|
+
setIsWindowInteracting(false);
|
|
165
|
+
const t = window.setTimeout(() => {
|
|
166
|
+
setGeometry(null);
|
|
167
|
+
dialogGeometryCache.current = null;
|
|
168
|
+
}, CLOSE_GEOMETRY_CLEAR_MS);
|
|
169
|
+
return () => window.clearTimeout(t);
|
|
170
|
+
}, [open]);
|
|
171
|
+
|
|
172
|
+
// Browser resize: never leave a custom-sized modal larger than the viewport.
|
|
173
|
+
// Re-center so it isn't cut off at the edges.
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (!open || isSheet) return;
|
|
176
|
+
|
|
177
|
+
const fitToWindow = () => {
|
|
178
|
+
const current = geometryRef.current;
|
|
179
|
+
if (current) {
|
|
180
|
+
const next = fitGeometryToViewport(current);
|
|
181
|
+
setGeometry(next);
|
|
182
|
+
dialogGeometryCache.current = next;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// Default (centered) layout — if it overflows after a shrink, lock to fitted geometry
|
|
186
|
+
const el = contentRef.current;
|
|
187
|
+
if (!el) return;
|
|
188
|
+
const rect = el.getBoundingClientRect();
|
|
189
|
+
const maxW = window.innerWidth - VIEWPORT_MARGIN * 2;
|
|
190
|
+
const maxH = window.innerHeight - VIEWPORT_MARGIN * 2;
|
|
191
|
+
if (rect.width > maxW + 1 || rect.height > maxH + 1) {
|
|
192
|
+
const next = fitGeometryToViewport({
|
|
193
|
+
x: rect.left,
|
|
194
|
+
y: rect.top,
|
|
195
|
+
width: rect.width,
|
|
196
|
+
height: rect.height,
|
|
197
|
+
});
|
|
198
|
+
setGeometry(next);
|
|
199
|
+
dialogGeometryCache.current = next;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
window.addEventListener('resize', fitToWindow);
|
|
204
|
+
return () => window.removeEventListener('resize', fitToWindow);
|
|
205
|
+
}, [open, isSheet]);
|
|
206
|
+
|
|
207
|
+
// Sheet ignores custom geometry; restore cached dialog geometry when returning to dialog
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (isSheet) {
|
|
210
|
+
if (geometryRef.current) {
|
|
211
|
+
dialogGeometryCache.current = geometryRef.current;
|
|
212
|
+
}
|
|
213
|
+
setGeometry(null);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (dialogGeometryCache.current) {
|
|
217
|
+
setGeometry(fitGeometryToViewport(dialogGeometryCache.current));
|
|
218
|
+
}
|
|
219
|
+
}, [isSheet]);
|
|
220
|
+
|
|
221
|
+
const captureCurrentGeometry = useCallback((): ModalGeometry | null => {
|
|
222
|
+
const el = contentRef.current;
|
|
223
|
+
if (!el) return null;
|
|
224
|
+
const rect = el.getBoundingClientRect();
|
|
225
|
+
return clampGeometry({
|
|
226
|
+
x: rect.left,
|
|
227
|
+
y: rect.top,
|
|
228
|
+
width: rect.width,
|
|
229
|
+
height: rect.height,
|
|
230
|
+
});
|
|
231
|
+
}, []);
|
|
232
|
+
|
|
233
|
+
const beginWindowInteract = useCallback(
|
|
234
|
+
(e: ReactPointerEvent, edge?: ResizeEdge) => {
|
|
235
|
+
if (isSheet) return;
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
const base = geometryRef.current ?? captureCurrentGeometry();
|
|
239
|
+
if (!base) return;
|
|
240
|
+
interactStart.current = {
|
|
241
|
+
pointerX: e.clientX,
|
|
242
|
+
pointerY: e.clientY,
|
|
243
|
+
geo: base,
|
|
244
|
+
edge,
|
|
245
|
+
};
|
|
246
|
+
setGeometry(base);
|
|
247
|
+
setIsWindowInteracting(true);
|
|
248
|
+
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
249
|
+
},
|
|
250
|
+
[captureCurrentGeometry, isSheet],
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const onWindowPointerMove = useCallback((e: ReactPointerEvent) => {
|
|
254
|
+
const start = interactStart.current;
|
|
255
|
+
if (!start) return;
|
|
256
|
+
const dx = e.clientX - start.pointerX;
|
|
257
|
+
const dy = e.clientY - start.pointerY;
|
|
258
|
+
const { geo, edge } = start;
|
|
259
|
+
|
|
260
|
+
if (!edge) {
|
|
261
|
+
// Move
|
|
262
|
+
setGeometry(clampGeometry({ ...geo, x: geo.x + dx, y: geo.y + dy }));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let { x, y, width, height } = geo;
|
|
267
|
+
if (edge.includes('e')) width = geo.width + dx;
|
|
268
|
+
if (edge.includes('w')) {
|
|
269
|
+
width = geo.width - dx;
|
|
270
|
+
x = geo.x + dx;
|
|
271
|
+
}
|
|
272
|
+
if (edge.includes('s')) height = geo.height + dy;
|
|
273
|
+
if (edge.includes('n')) {
|
|
274
|
+
height = geo.height - dy;
|
|
275
|
+
y = geo.y + dy;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Keep opposite edge fixed when hitting min size
|
|
279
|
+
if (edge.includes('w') && width < MIN_WIDTH) {
|
|
280
|
+
x = geo.x + geo.width - MIN_WIDTH;
|
|
281
|
+
width = MIN_WIDTH;
|
|
282
|
+
}
|
|
283
|
+
if (edge.includes('n') && height < MIN_HEIGHT) {
|
|
284
|
+
y = geo.y + geo.height - MIN_HEIGHT;
|
|
285
|
+
height = MIN_HEIGHT;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const next = clampGeometry({ x, y, width, height });
|
|
289
|
+
setGeometry(next);
|
|
290
|
+
}, []);
|
|
291
|
+
|
|
292
|
+
const endWindowInteract = useCallback((e: ReactPointerEvent) => {
|
|
293
|
+
if (!interactStart.current) return;
|
|
294
|
+
try {
|
|
295
|
+
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
|
|
296
|
+
} catch {
|
|
297
|
+
// ignore
|
|
298
|
+
}
|
|
299
|
+
interactStart.current = null;
|
|
300
|
+
setIsWindowInteracting(false);
|
|
301
|
+
if (geometryRef.current) {
|
|
302
|
+
dialogGeometryCache.current = geometryRef.current;
|
|
303
|
+
}
|
|
304
|
+
}, []);
|
|
305
|
+
|
|
306
|
+
const resetSheetDrag = useCallback(() => {
|
|
307
|
+
dragStartY.current = null;
|
|
308
|
+
dragCurrentY.current = 0;
|
|
309
|
+
setSheetDragOffset(0);
|
|
310
|
+
setIsSheetDragging(false);
|
|
311
|
+
}, []);
|
|
312
|
+
|
|
313
|
+
const handleSheetPointerDown = useCallback(
|
|
314
|
+
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
315
|
+
if (!isSheet || !dismissible) return;
|
|
316
|
+
dragStartY.current = e.clientY;
|
|
317
|
+
dragCurrentY.current = 0;
|
|
318
|
+
setIsSheetDragging(true);
|
|
319
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
320
|
+
},
|
|
321
|
+
[isSheet, dismissible],
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const handleSheetPointerMove = useCallback((e: ReactPointerEvent<HTMLDivElement>) => {
|
|
325
|
+
if (dragStartY.current === null) return;
|
|
326
|
+
const delta = Math.max(0, e.clientY - dragStartY.current);
|
|
327
|
+
dragCurrentY.current = delta;
|
|
328
|
+
setSheetDragOffset(delta);
|
|
329
|
+
}, []);
|
|
330
|
+
|
|
331
|
+
const handleSheetPointerUp = useCallback(
|
|
332
|
+
(e: ReactPointerEvent<HTMLDivElement>) => {
|
|
333
|
+
if (dragStartY.current === null) return;
|
|
334
|
+
try {
|
|
335
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
336
|
+
} catch {
|
|
337
|
+
// ignore
|
|
338
|
+
}
|
|
339
|
+
const delta = dragCurrentY.current;
|
|
340
|
+
const height = contentRef.current?.offsetHeight ?? window.innerHeight;
|
|
341
|
+
const shouldDismiss = delta >= SWIPE_DISMISS_PX || delta >= height * SWIPE_DISMISS_RATIO;
|
|
342
|
+
resetSheetDrag();
|
|
343
|
+
if (shouldDismiss && dismissible) {
|
|
344
|
+
onOpenChange(false);
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
[dismissible, onOpenChange, resetSheetDrag],
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
const canMove = movable && !isSheet;
|
|
351
|
+
const canResize = resizable && !isSheet;
|
|
352
|
+
const hasCustomGeometry = !isSheet && geometry !== null;
|
|
353
|
+
|
|
354
|
+
const sheetTransform =
|
|
355
|
+
isSheet && sheetDragOffset > 0 ? `translateY(${sheetDragOffset}px)` : undefined;
|
|
356
|
+
|
|
357
|
+
const geometryStyle: CSSProperties | undefined = hasCustomGeometry
|
|
358
|
+
? {
|
|
359
|
+
left: geometry.x,
|
|
360
|
+
top: geometry.y,
|
|
361
|
+
width: geometry.width,
|
|
362
|
+
height: geometry.height,
|
|
363
|
+
maxWidth: 'none',
|
|
364
|
+
maxHeight: 'none',
|
|
365
|
+
transform: 'none',
|
|
366
|
+
right: 'auto',
|
|
367
|
+
bottom: 'auto',
|
|
368
|
+
}
|
|
369
|
+
: undefined;
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
<Dialog
|
|
373
|
+
open={open}
|
|
374
|
+
onOpenChange={onOpenChange}
|
|
375
|
+
>
|
|
376
|
+
<DialogContent
|
|
377
|
+
ref={(node) => {
|
|
378
|
+
contentRef.current = node;
|
|
379
|
+
}}
|
|
380
|
+
data-presentation={presentation}
|
|
381
|
+
data-geometry={hasCustomGeometry ? 'custom' : 'auto'}
|
|
382
|
+
data-window-interacting={isWindowInteracting ? 'true' : undefined}
|
|
383
|
+
showCloseButton={showCloseButton}
|
|
384
|
+
className={cn(
|
|
385
|
+
'gap-0 p-0 overflow-hidden flex flex-col',
|
|
386
|
+
isSheet
|
|
387
|
+
? 'left-0 right-0 top-auto bottom-0 max-w-none w-full translate-x-0 translate-y-0 rounded-t-xl rounded-b-none border-x-0 border-b-0'
|
|
388
|
+
: cn('rounded-lg', hasCustomGeometry && 'translate-x-0 translate-y-0 max-w-none'),
|
|
389
|
+
className,
|
|
390
|
+
)}
|
|
391
|
+
style={{
|
|
392
|
+
...style,
|
|
393
|
+
...geometryStyle,
|
|
394
|
+
...(sheetTransform
|
|
395
|
+
? {
|
|
396
|
+
transform: sheetTransform,
|
|
397
|
+
transition: isSheetDragging ? 'none' : style?.transition,
|
|
398
|
+
}
|
|
399
|
+
: {}),
|
|
400
|
+
...((isSheetDragging || isWindowInteracting) && { transition: 'none' }),
|
|
401
|
+
}}
|
|
402
|
+
onPointerDownOutside={(e) => {
|
|
403
|
+
if (!closeOnOverlayClick || !dismissible) {
|
|
404
|
+
e.preventDefault();
|
|
405
|
+
}
|
|
406
|
+
}}
|
|
407
|
+
onEscapeKeyDown={(e) => {
|
|
408
|
+
if (!dismissible) {
|
|
409
|
+
e.preventDefault();
|
|
410
|
+
}
|
|
411
|
+
}}
|
|
412
|
+
onInteractOutside={(e) => {
|
|
413
|
+
if (!closeOnOverlayClick || !dismissible) {
|
|
414
|
+
e.preventDefault();
|
|
415
|
+
}
|
|
416
|
+
}}
|
|
417
|
+
>
|
|
418
|
+
<DialogTitle className="sr-only">{title}</DialogTitle>
|
|
419
|
+
{description ? (
|
|
420
|
+
<DialogDescription className="sr-only">{description}</DialogDescription>
|
|
421
|
+
) : (
|
|
422
|
+
<DialogDescription className="sr-only">{title}</DialogDescription>
|
|
423
|
+
)}
|
|
424
|
+
|
|
425
|
+
{canMove && (
|
|
426
|
+
<div
|
|
427
|
+
data-responsive-modal-titlebar
|
|
428
|
+
className={cn(
|
|
429
|
+
// Invisible hit target on the top border only — sits mostly outside content
|
|
430
|
+
// so buttons/iframe controls underneath stay clickable (pointer-events none on the
|
|
431
|
+
// content side). Use grab cursor when hovering the edge.
|
|
432
|
+
'pointer-events-none absolute inset-x-0 top-0 z-10 h-7',
|
|
433
|
+
)}
|
|
434
|
+
aria-hidden
|
|
435
|
+
>
|
|
436
|
+
{/* Narrow edge strip re-enables hit-testing for drag without covering content */}
|
|
437
|
+
<div
|
|
438
|
+
className="pointer-events-auto absolute inset-x-3 top-0 h-2 -translate-y-1/2 cursor-grab touch-none active:cursor-grabbing"
|
|
439
|
+
onPointerDown={(e) => beginWindowInteract(e)}
|
|
440
|
+
onPointerMove={onWindowPointerMove}
|
|
441
|
+
onPointerUp={endWindowInteract}
|
|
442
|
+
onPointerCancel={endWindowInteract}
|
|
443
|
+
role="presentation"
|
|
444
|
+
aria-label="Move modal"
|
|
445
|
+
/>
|
|
446
|
+
</div>
|
|
447
|
+
)}
|
|
448
|
+
|
|
449
|
+
<div className="relative flex min-h-0 flex-1 flex-col overflow-hidden">{children}</div>
|
|
450
|
+
|
|
451
|
+
{isSheet && showDragHandle && dismissible && (
|
|
452
|
+
<div
|
|
453
|
+
data-responsive-modal-handle
|
|
454
|
+
className="pointer-events-none absolute inset-x-0 top-0 z-20 flex touch-none items-center justify-center bg-transparent py-3"
|
|
455
|
+
role="presentation"
|
|
456
|
+
>
|
|
457
|
+
<div
|
|
458
|
+
className="pointer-events-auto h-1.5 w-12 cursor-grab rounded-full bg-muted-foreground/40 active:cursor-grabbing"
|
|
459
|
+
onPointerDown={handleSheetPointerDown}
|
|
460
|
+
onPointerMove={handleSheetPointerMove}
|
|
461
|
+
onPointerUp={handleSheetPointerUp}
|
|
462
|
+
onPointerCancel={resetSheetDrag}
|
|
463
|
+
/>
|
|
464
|
+
</div>
|
|
465
|
+
)}
|
|
466
|
+
|
|
467
|
+
{canResize &&
|
|
468
|
+
RESIZE_HANDLES.map(({ edge, className: handleClass, cursor }) => (
|
|
469
|
+
<div
|
|
470
|
+
key={edge}
|
|
471
|
+
data-resize-handle={edge}
|
|
472
|
+
className={cn('absolute z-20 touch-none', handleClass)}
|
|
473
|
+
style={{ cursor }}
|
|
474
|
+
onPointerDown={(e) => beginWindowInteract(e, edge)}
|
|
475
|
+
onPointerMove={onWindowPointerMove}
|
|
476
|
+
onPointerUp={endWindowInteract}
|
|
477
|
+
onPointerCancel={endWindowInteract}
|
|
478
|
+
/>
|
|
479
|
+
))}
|
|
480
|
+
</DialogContent>
|
|
481
|
+
</Dialog>
|
|
482
|
+
);
|
|
483
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
DYNAMIC_DRAWER_PENDING_PX,
|
|
4
|
+
DYNAMIC_OVERLAY_PENDING_PX,
|
|
5
|
+
isOverlaySizePreset,
|
|
6
|
+
resolveDialogSize,
|
|
7
|
+
resolveDismissOptions,
|
|
8
|
+
resolveDrawerSize,
|
|
9
|
+
toCssLength,
|
|
10
|
+
} from './overlaySize';
|
|
11
|
+
|
|
12
|
+
describe('overlaySize', () => {
|
|
13
|
+
it('exposes compact pending sizes for dynamic overlays', () => {
|
|
14
|
+
expect(DYNAMIC_OVERLAY_PENDING_PX).toBeGreaterThan(0);
|
|
15
|
+
expect(DYNAMIC_OVERLAY_PENDING_PX).toBeLessThan(200);
|
|
16
|
+
expect(DYNAMIC_DRAWER_PENDING_PX).toBe(40);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('recognizes size presets', () => {
|
|
20
|
+
expect(isOverlaySizePreset('sm')).toBe(true);
|
|
21
|
+
expect(isOverlaySizePreset('content')).toBe(true);
|
|
22
|
+
expect(isOverlaySizePreset('400px')).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('converts numbers to px', () => {
|
|
26
|
+
expect(toCssLength(320)).toBe('320px');
|
|
27
|
+
expect(toCssLength('50vh')).toBe('50vh');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('defaults dialog to lg with horizontal gutters', () => {
|
|
31
|
+
const resolved = resolveDialogSize(null);
|
|
32
|
+
expect(resolved.className).toContain('max-w-4xl');
|
|
33
|
+
expect(resolved.className).toContain('calc(100vw-5rem)');
|
|
34
|
+
expect(resolved.contentSized).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('marks content preset as contentSized', () => {
|
|
38
|
+
const resolved = resolveDialogSize({ size: 'content' });
|
|
39
|
+
expect(resolved.contentSized).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('marks dynamicSizing as contentSized', () => {
|
|
43
|
+
expect(resolveDialogSize({ dynamicSizing: true }).contentSized).toBe(true);
|
|
44
|
+
expect(resolveDrawerSize({ dynamicSizing: true }, 'bottom').contentSized).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('resolves drawer CSS lengths', () => {
|
|
48
|
+
const resolved = resolveDrawerSize({ size: '400px' }, 'right');
|
|
49
|
+
expect(resolved.drawerSize).toBe('400px');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('resolves drawer presets by direction', () => {
|
|
53
|
+
expect(resolveDrawerSize({ size: 'sm' }, 'bottom').drawerSize).toBe('40dvh');
|
|
54
|
+
expect(resolveDrawerSize({ size: 'sm' }, 'left').drawerSize).toBe('20rem');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('defaults dismiss options', () => {
|
|
58
|
+
expect(resolveDismissOptions(null)).toEqual({
|
|
59
|
+
showCloseButton: true,
|
|
60
|
+
dismissible: true,
|
|
61
|
+
closeOnOverlayClick: true,
|
|
62
|
+
showDragHandle: true,
|
|
63
|
+
});
|
|
64
|
+
expect(resolveDismissOptions({ showCloseButton: false, dismissible: false })).toEqual({
|
|
65
|
+
showCloseButton: false,
|
|
66
|
+
dismissible: false,
|
|
67
|
+
closeOnOverlayClick: true,
|
|
68
|
+
showDragHandle: false,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|