@scbt-ecom/ui 0.140.2 → 0.140.3
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as r,jsxs as
|
|
1
|
+
import{jsx as r,jsxs as D,Fragment as M}from"react/jsx-runtime";import{useEffect as R,useRef as f}from"react";import{createPortal as y}from"react-dom";import{modalOverlayAnimation as N,modalContentAnimation as j}from"./model/helpers.js";import{IframeModalContent as k}from"./ui/IframeModalContent.js";import{ModalHeader as A}from"./ui/ModalHeader.js";import{cn as e}from"../../utils/cn.js";import{mergeRefs as C}from"../../utils/mergeRefs.js";import{AnimatePresence as E}from"../../../../node_modules/framer-motion/dist/es/components/AnimatePresence/index.js";import{motion as l}from"../../../../node_modules/framer-motion/dist/es/render/components/motion/proxy.js";const q=({title:c,children:u,isModalOpen:n,isPortal:a=!0,portalContainer:v=(h=>(h=globalThis==null?void 0:globalThis.document)==null?void 0:h.body)(),closeModal:m,classes:o,iframe:w})=>{R(()=>(n&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow="visible"}),[n]);const x=f(null),i=f(null),d=f(!1),b=t=>{t.target===i.current&&(d.current=!0)},g=t=>{d.current&&t.target===i.current&&m(),d.current=!1},p=r(E,{children:n&&r(l.div,{ref:C(t=>t==null?void 0:t.focus(),i),tabIndex:-1,onMouseDown:b,onMouseUp:g,className:e("fixed inset-0 flex h-screen w-screen items-center justify-center bg-color-overlay",{"z-1000":!a},o==null?void 0:o.overlay),onKeyDown:t=>{t.key==="Escape"&&m()},"data-test-id":"modal-overlay",...N,children:D(l.div,{onMouseDown:t=>t.stopPropagation(),className:e("w-full max-w-[600px] rounded-md bg-color-white px-4 py-6 shadow-sm desktop:px-6 desktop:py-8",o==null?void 0:o.modal),"data-test-id":"modal",...j,children:[r(A,{title:c,closeModal:m,classes:o==null?void 0:o.modalHeader}),w?r(k,{ref:x,className:e("mt-4",o==null?void 0:o.content),children:t=>y(u,t)}):r("div",{className:e("mt-4",o==null?void 0:o.content),children:u})]})})});return r(M,{children:a?y(p,v):p})};export{q as Modal};
|
|
2
2
|
//# sourceMappingURL=Modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sources":["../../../../../lib/shared/ui/modal/Modal.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useEffect, useRef } from 'react'
|
|
1
|
+
{"version":3,"file":"Modal.js","sources":["../../../../../lib/shared/ui/modal/Modal.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useEffect, useRef } from 'react' // useState больше не нужен\nimport { createPortal } from 'react-dom'\nimport { AnimatePresence, motion } from 'framer-motion'\nimport { modalContentAnimation, modalOverlayAnimation } from './model/helpers'\nimport { IframeModalContent } from './ui/IframeModalContent'\nimport { ModalHeader, type TModalHeaderClasses } from './ui/ModalHeader'\nimport { cn, mergeRefs } from '$/shared/utils'\n\ntype ModalClasses = {\n overlay?: string\n modal?: string\n content?: string\n modalHeader?: TModalHeaderClasses\n}\n\nexport interface ModalProps {\n children: React.ReactElement\n isModalOpen: boolean\n classes?: ModalClasses\n isPortal?: boolean\n portalContainer?: HTMLElement\n title?: string | React.ReactElement\n closeModal: () => void\n iframe?: boolean\n}\n\nexport const Modal = ({\n title,\n children,\n isModalOpen,\n isPortal = true,\n portalContainer = globalThis?.document?.body,\n closeModal,\n classes,\n iframe\n}: ModalProps) => {\n useEffect(() => {\n if (isModalOpen) {\n document.body.style.overflow = 'hidden'\n }\n return () => {\n document.body.style.overflow = 'visible'\n }\n }, [isModalOpen])\n\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const overlayRef = useRef<HTMLDivElement>(null)\n const isMouseDownOnOverlayRef = useRef(false)\n\n const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {\n if (e.target === overlayRef.current) {\n isMouseDownOnOverlayRef.current = true\n }\n }\n\n const handleMouseUp = (e: React.MouseEvent<HTMLDivElement>) => {\n if (isMouseDownOnOverlayRef.current && e.target === overlayRef.current) {\n closeModal()\n }\n isMouseDownOnOverlayRef.current = false\n }\n\n const modalBody = (\n <AnimatePresence>\n {isModalOpen && (\n <motion.div\n ref={mergeRefs((node) => node?.focus(), overlayRef)}\n tabIndex={-1}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n className={cn(\n 'fixed inset-0 flex h-screen w-screen items-center justify-center bg-color-overlay',\n { 'z-1000': !isPortal },\n classes?.overlay\n )}\n onKeyDown={(event) => {\n if (event.key === 'Escape') {\n closeModal()\n }\n }}\n data-test-id='modal-overlay'\n {...modalOverlayAnimation}\n >\n <motion.div\n onMouseDown={(event) => event.stopPropagation()}\n className={cn(\n 'w-full max-w-[600px] rounded-md bg-color-white px-4 py-6 shadow-sm desktop:px-6 desktop:py-8',\n classes?.modal\n )}\n data-test-id='modal'\n {...modalContentAnimation}\n >\n <ModalHeader title={title} closeModal={closeModal} classes={classes?.modalHeader} />\n {iframe ? (\n <IframeModalContent ref={iframeRef} className={cn('mt-4', classes?.content)}>\n {(iframeBody) => createPortal(children, iframeBody)}\n </IframeModalContent>\n ) : (\n <div className={cn('mt-4', classes?.content)}>{children}</div>\n )}\n </motion.div>\n </motion.div>\n )}\n </AnimatePresence>\n )\n return <>{isPortal ? createPortal(modalBody, portalContainer) : modalBody}</>\n}\n"],"names":["Modal","title","children","isModalOpen","isPortal","portalContainer","_a","closeModal","classes","iframe","useEffect","iframeRef","useRef","overlayRef","isMouseDownOnOverlayRef","handleMouseDown","e","handleMouseUp","modalBody","jsx","AnimatePresence","motion","mergeRefs","node","cn","event","modalOverlayAnimation","jsxs","modalContentAnimation","ModalHeader","IframeModalContent","iframeBody","createPortal"],"mappings":"0pBA6BO,MAAMA,EAAQ,CAAC,CACpB,MAAAC,EACA,SAAAC,EACA,YAAAC,EACA,SAAAC,EAAW,GACX,gBAAAC,GAAkBC,MAAA,mCAAY,WAAZ,YAAAA,EAAsB,QACxC,WAAAC,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