UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

138 lines (136 loc) 3.97 kB
import { Button_default } from "./chunk-LAYB7IKW.mjs"; import { cn } from "./chunk-53ICLDGS.mjs"; // src/components/AlertDialog/AlertDialog.tsx import { forwardRef, useEffect } from "react"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; var SIZE_CLASSES = { "extra-small": "w-screen max-w-[324px]", small: "w-screen max-w-[378px]", medium: "w-screen max-w-[459px]", large: "w-screen max-w-[578px]", "extra-large": "w-screen max-w-[912px]" }; var AlertDialog = forwardRef( ({ description, cancelButtonLabel = "Cancelar", submitButtonLabel = "Deletar", title, isOpen, closeOnBackdropClick = true, closeOnEscape = true, className = "", onSubmit, onChangeOpen, submitValue, onCancel, cancelValue, size = "medium", submitAction = "negative", ...props }, ref) => { useEffect(() => { if (!isOpen || !closeOnEscape) return; const handleEscape = (event) => { if (event.key === "Escape") { onChangeOpen(false); } }; document.addEventListener("keydown", handleEscape); return () => document.removeEventListener("keydown", handleEscape); }, [isOpen, closeOnEscape]); useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = "unset"; } return () => { document.body.style.overflow = "unset"; }; }, [isOpen]); const handleBackdropClick = (event) => { if (event.target === event.currentTarget && closeOnBackdropClick) { onChangeOpen(false); } }; const handleBackdropKeyDown = (event) => { if (event.key === "Escape" && closeOnEscape) { onChangeOpen(false); } }; const handleSubmit = () => { onChangeOpen(false); onSubmit?.(submitValue); }; const handleCancel = () => { onChangeOpen(false); onCancel?.(cancelValue); }; const sizeClasses = SIZE_CLASSES[size]; return /* @__PURE__ */ jsx(Fragment, { children: isOpen && /* @__PURE__ */ jsx( "div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm", onClick: handleBackdropClick, onKeyDown: handleBackdropKeyDown, "data-testid": "alert-dialog-overlay", children: /* @__PURE__ */ jsxs( "div", { ref, className: cn( "bg-background border border-border-100 rounded-lg shadow-lg p-6 m-3", sizeClasses, className ), ...props, children: [ /* @__PURE__ */ jsx( "h2", { id: "alert-dialog-title", className: "pb-3 text-xl font-semibold text-text-950", children: title } ), /* @__PURE__ */ jsx( "p", { id: "alert-dialog-description", className: "text-text-700 text-sm", children: description } ), /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-end pt-4 gap-3", children: [ /* @__PURE__ */ jsx(Button_default, { variant: "outline", size: "small", onClick: handleCancel, children: cancelButtonLabel }), /* @__PURE__ */ jsx( Button_default, { variant: "solid", size: "small", action: submitAction, onClick: handleSubmit, children: submitButtonLabel } ) ] }) ] } ) } ) }); } ); AlertDialog.displayName = "AlertDialog"; export { AlertDialog }; //# sourceMappingURL=chunk-6E2SCKRJ.mjs.map