"use client"; import * as DialogPrimitive from "@radix-ui/react-dialog"; import { cva, type VariantProps } from "class-variance-authority"; import type { ForwardRefExoticComponent, ReactNode } from "react"; import React from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import type { ButtonProps } from "../button"; import { Button } from "../button"; import type { IconName } from "../icon"; import { Icon } from "../icon"; const dialogClasses = cva( "fadeIn bg-default scroll-bar fixed left-1/2 top-1/2 z-50 w-[95vw] m-auto -translate-x-1/2 -translate-y-1/2 rounded-2xl text-left shadow-xl focus-visible:outline-none sm:align-middle", { variants: { size: { xl: "px-8 pt-8 sm:max-w-[90rem]", lg: "px-8 pt-8 sm:max-w-[70rem]", md: "px-8 pt-8 sm:max-w-[48rem]", default: "px-8 pt-8 sm:max-w-[35rem]", }, }, defaultVariants: { size: "default", }, } ); export type DialogProps = React.ComponentProps<(typeof DialogPrimitive)["Root"]>; export function Dialog(props: DialogProps) { const { children, ...dialogProps } = props; return {children}; } type DialogContentProps = React.ComponentProps<(typeof DialogPrimitive)["Content"]> & { type?: "creation" | "confirmation"; title?: string; description?: string | JSX.Element | null; closeText?: string; actionDisabled?: boolean; Icon?: IconName; enableOverflow?: boolean; forceOverlayWhenNoModal?: boolean; /** * Disables the ability to close the dialog by clicking outside of it. Could be useful when the dialog is doing something critical which might be in progress. */ preventCloseOnOutsideClick?: boolean; } & VariantProps; // enableOverflow:- use this prop whenever content inside DialogContent could overflow and require scrollbar export const DialogContent = React.forwardRef( ( { children, title, Icon: icon, enableOverflow, forceOverlayWhenNoModal, type = "creation", preventCloseOnOutsideClick, ...props }, forwardedRef ) => { return ( {forceOverlayWhenNoModal ? (
) : ( )} { if (preventCloseOnOutsideClick) { e.preventDefault(); } }} className={classNames( dialogClasses({ size: props.size }), "max-h-[95vh]", enableOverflow ? "overflow-y-auto" : "overflow-visible", `${props.className || ""}` )} ref={forwardedRef}> {type === "creation" && (
{children}
)} {type === "confirmation" && (
{icon && (
)}
{children}
)} {!type && children}
); } ); type DialogHeaderProps = { title: React.ReactNode; subtitle?: React.ReactNode; } & React.HTMLAttributes; export function DialogHeader(props: DialogHeaderProps) { if (!props.title) return null; return (
{props.subtitle && (

{props.subtitle}

)}
); } type DialogFooterProps = { children: React.ReactNode; showDivider?: boolean; noSticky?: boolean; } & React.HTMLAttributes; export function DialogFooter(props: DialogFooterProps) { return (
{props.showDivider &&
}
{props.children}
); } DialogContent.displayName = "DialogContent"; export const DialogTrigger: ForwardRefExoticComponent< DialogPrimitive.DialogTriggerProps & React.RefAttributes > = React.forwardRef((props, ref) => { return ; }); DialogTrigger.displayName = "DialogTrigger"; export function DialogClose( props: { "data-testid"?: string; dialogCloseProps?: React.ComponentProps<(typeof DialogPrimitive)["Close"]>; children?: ReactNode; onClick?: (e: React.MouseEvent) => void; disabled?: boolean; color?: ButtonProps["color"]; } & React.ComponentProps ) { const { t } = useLocale(); const { className, ...buttonProps } = props; return ( ); }