Connect the live modals to the drawn sent, expired, invalid-email, and send-failed screens, pin the phone footer above the keyboard, and send the light login email.
107 lines
3.6 KiB
TypeScript
107 lines
3.6 KiB
TypeScript
"use client";
|
||
|
||
import type { ReactNode, RefObject } from "react";
|
||
import { createPortal } from "react-dom";
|
||
|
||
/** Matches {@link CreateView} overlay options — shared with {@link DialogView}. */
|
||
export type CreateModalBackdropVariant = "default" | "blurredYellow";
|
||
|
||
const backdropOverlayClasses: Record<CreateModalBackdropVariant, string> = {
|
||
default: "fixed inset-0 bg-black/50 z-[9998]",
|
||
blurredYellow:
|
||
"fixed inset-0 z-[9998] bg-[var(--color-surface-invert-brand-primary)]/85 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--color-surface-invert-brand-primary)]/75",
|
||
};
|
||
|
||
export type CreateModalPresentationValue = "dialog" | "sheet";
|
||
|
||
export type CreateModalFrameViewProps = {
|
||
isOpen: boolean;
|
||
onOverlayClick: () => void;
|
||
backdropVariant: CreateModalBackdropVariant;
|
||
className: string;
|
||
ariaLabel?: string;
|
||
ariaLabelledBy?: string;
|
||
overlayRef: RefObject<HTMLDivElement | null>;
|
||
dialogRef: RefObject<HTMLDivElement | null>;
|
||
children: ReactNode;
|
||
/** Rendered below the dialog card on the backdrop (e.g. “Back to home”). */
|
||
belowCard?: ReactNode;
|
||
/**
|
||
* `sheet` is full-viewport below `md` (Figma 320–639) and a 546px dialog
|
||
* from `md`. `dialog` is the centered card used by Create and Dialog.
|
||
*/
|
||
presentation?: CreateModalPresentationValue;
|
||
/** Visible viewport height so a phone sheet footer rides above the keyboard. */
|
||
viewportHeight?: number;
|
||
};
|
||
|
||
/**
|
||
* Portal + dimmed overlay + centered dialog shell used by Create and Dialog.
|
||
*/
|
||
export function CreateModalFrameView({
|
||
isOpen,
|
||
onOverlayClick,
|
||
backdropVariant,
|
||
className,
|
||
ariaLabel,
|
||
ariaLabelledBy,
|
||
overlayRef,
|
||
dialogRef,
|
||
children,
|
||
belowCard,
|
||
presentation = "dialog",
|
||
viewportHeight,
|
||
}: CreateModalFrameViewProps) {
|
||
if (!isOpen) return null;
|
||
|
||
const isSheet = presentation === "sheet";
|
||
const overlayLayout = isSheet
|
||
? "flex flex-col items-stretch justify-end overflow-hidden p-0 md:items-center md:justify-center md:gap-6 md:overflow-y-auto md:px-4 md:py-8"
|
||
: "flex flex-col items-center justify-center gap-6 overflow-y-auto px-4 py-8";
|
||
const sheetHeight =
|
||
viewportHeight != null ? "h-full max-h-full" : "h-dvh max-h-dvh";
|
||
const dialogShell = isSheet
|
||
? `flex ${sheetHeight} min-h-0 w-full shrink-0 flex-col overflow-hidden rounded-none bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999] md:h-auto md:max-h-[90vh] md:w-[546px] md:max-w-[546px] md:rounded-[var(--radius-500)]`
|
||
: "flex min-h-0 max-h-[90vh] w-full max-w-[560px] shrink-0 flex-col overflow-hidden rounded-[var(--radius-500)] bg-[var(--color-surface-default-primary)] shadow-[0px_0px_48px_0px_rgba(0,0,0,0.1)] z-[9999]";
|
||
const overlayStyle =
|
||
isSheet && viewportHeight != null
|
||
? { height: viewportHeight, maxHeight: viewportHeight }
|
||
: undefined;
|
||
|
||
const content = (
|
||
<div
|
||
ref={overlayRef}
|
||
className={`${backdropOverlayClasses[backdropVariant]} ${overlayLayout}`}
|
||
style={overlayStyle}
|
||
onClick={onOverlayClick}
|
||
role="presentation"
|
||
>
|
||
<div
|
||
ref={dialogRef}
|
||
role="dialog"
|
||
aria-modal="true"
|
||
aria-label={ariaLabel}
|
||
aria-labelledby={ariaLabelledBy}
|
||
className={`${dialogShell} ${className}`}
|
||
onClick={(e) => e.stopPropagation()}
|
||
>
|
||
{children}
|
||
</div>
|
||
{belowCard ? (
|
||
<div
|
||
className={`shrink-0 ${isSheet ? "hidden md:block" : ""}`}
|
||
onClick={(e) => e.stopPropagation()}
|
||
>
|
||
{belowCard}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|
||
|
||
if (typeof window !== "undefined") {
|
||
return createPortal(content, document.body);
|
||
}
|
||
|
||
return null;
|
||
}
|