import { UseDismissProps, UseFloatingReturn, useInteractions } from "@floating-ui/react"; import { UseFloatingReturn as UseFloatingReturn_Dom } from "@floating-ui/react-dom"; import { type CloseReason, type DismissOptions, type UseOverlayDismissibleProps, type UseOverlayDismissibleReturn } from "@trackunit/react-components"; import { type AriaRole, type Ref, type RefObject } from "react"; import { type UseModalStackResult } from "./useModalStack"; /** * Rendering mode of the Modal. Determined by container/viewport width: * - `"card"`: standard centered card overlay (container width >= 480px) * - `"sheet"`: bottom sheet with gesture support (container width < 480px) */ export type ModalMode = "card" | "sheet"; /** @deprecated Use CloseReason from @trackunit/react-components instead. */ export type ModalCloseReason = CloseReason; /** * Options for configuring modal dismissal behavior. * Extends shared DismissOptions with FloatingUI's useDismiss options. * * @see https://floating-ui.com/docs/usedismiss */ export type ModalDismissOptions = DismissOptions & Omit; export type UseModalProps = UseOverlayDismissibleProps & { /** * The root element to render the modal portal into. */ rootElement?: HTMLElement; /** * Configuration for modal dismissal behavior. * Extends shared DismissOptions with FloatingUI options. * * @default { escapeKey: true, outsidePress: true, gesture: true } * @example * // Disable outside click dismissal * dismiss: { outsidePress: false } */ dismiss?: ModalDismissOptions; /** * Custom ref for the modal container. */ ref?: Ref; /** * The aria role for the modal. */ role?: AriaRole; /** * Scopes the modal to a specific container element. When provided, the modal * portals into this container (instead of the document body), uses its width * to determine whether to render as a bottom sheet (container width < 480px), * and positions the backdrop/overlay relative to the container. * Card width uses container query units (`cqw`) so it tracks a `container-type` * ancestor of the portal root (ensure one exists, e.g. Tailwind `@container`). * When omitted, viewport width is used for breakpoint detection and card sizing. */ container?: RefObject; }; type FloatingUiProps = { refs: UseFloatingReturn_Dom["refs"]; rootElement?: HTMLElement; context: UseFloatingReturn["context"]; getFloatingProps: ReturnType["getFloatingProps"]; }; export type UseModalReturnValue = Omit & { /** * The ref for the modal (RefObject or RefCallback). Provided by `useModal()` hook. */ ref: Ref; /** * The floating UI properties for the modal. Provided by `useModal()` hook. */ floatingUi: FloatingUiProps; /** * The aria role for the modal. */ role?: AriaRole; /** * Resolved dismiss options (defaults applied). Pass to Sheet when in sheet mode. */ dismiss: Required; /** Called after the modal's close animation has finished, allowing the iframe to resize back. */ onCloseComplete: () => void; /** Position and sizing info for this modal within the open-modal stack. */ stack: UseModalStackResult; /** * Current rendering mode of the modal. * - `"card"`: standard centered card overlay * - `"sheet"`: bottom sheet with gesture support */ mode: ModalMode; /** * The container ref passed to useModal, if any. Forwarded to Modal for * portal and positioning decisions. */ container: RefObject | undefined; /** * Close the modal with a specific reason. Used internally by Modal * to preserve the correct CloseReason for gesture-initiated closes. */ requestClose: (event: Event | undefined, reason: CloseReason) => void; }; /** * A hook to handle the state and configuration of Modal components. * * - `useModal` should be used with the `Modal` component. * - const modal = useModal(); * - */ export declare const useModal: (props?: UseModalProps) => UseModalReturnValue; export {};