diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-23 17:11:33 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-10-23 17:11:33 +0700 |
| commit | 90710579ba1c12060877f6ec2d26103f9c31058d (patch) | |
| tree | 307032cfb8cd13b790c569bc443258b00b07684e /src-migrate/common/components | |
| parent | a001da95b9c03167656aec8a573cf60c12164b3f (diff) | |
Refactor and migrate register page
Diffstat (limited to 'src-migrate/common/components')
| -rw-r--r-- | src-migrate/common/components/elements/Modal.tsx | 84 | ||||
| -rw-r--r-- | src-migrate/common/components/skeleton/PageContentSkeleton.tsx | 19 |
2 files changed, 103 insertions, 0 deletions
diff --git a/src-migrate/common/components/elements/Modal.tsx b/src-migrate/common/components/elements/Modal.tsx new file mode 100644 index 00000000..ad1fe51b --- /dev/null +++ b/src-migrate/common/components/elements/Modal.tsx @@ -0,0 +1,84 @@ +import { XMarkIcon } from "@heroicons/react/24/outline"; +import { AnimatePresence, motion } from "framer-motion" +import { useEffect, useState } from "react"; +import ReactDOM from "react-dom"; +import { useWindowSize } from "usehooks-ts"; +import clsxm from "~/common/libs/clsxm"; + + +type Props = { + children: React.ReactNode + active: boolean + title?: string + close?: () => void, + className?: string +} + +const Modal = ({ + children, + active = false, + title, + close, + className +}: Props) => { + const { width } = useWindowSize() + const [rendered, setRendered] = useState<boolean>(false) + + useEffect(() => { + setRendered(true) + }, []) + + const modalClassNames = clsxm( + "fixed bg-white max-h-[80vh] overflow-auto p-4 pt-0 z-[60] border-gray_r-6", + { + "left-1/2 -translate-x-1/2 translate-y-1/2 bottom-1/2 md:w-1/4 lg:w-1/3 border rounded-xl": width >= 768, + "left-0 w-full border-t bottom-0 rounded-t-xl": width < 768 + }, + className + ) + + const variant = { + initial: { bottom: width >= 768 ? '45%' : '-100%', opacity: 0 }, + animate: { bottom: width >= 768 ? '50%' : 0, opacity: 1 }, + exit: { bottom: width >= 768 ? '55%' : '-100%', opacity: 0 }, + transition: { ease: 'linear', duration: 0.25 } + } + + return rendered && ReactDOM.createPortal( + <AnimatePresence> + {active && ( + <motion.div + className="overlay" + initial={{ opacity: 0 }} + animate={{ opacity: 1 }} + exit={{ opacity: 0 }} + onClick={close} + /> + )} + + {active && ( + <motion.div + {...variant} + className={modalClassNames} + > + <div className='flex justify-between py-5 sticky top-0 bg-white'> + <div className='font-semibold text-h-sm md:text-title-sm'> + {title} + </div> + {close && ( + <button type='button' onClick={close}> + <XMarkIcon className='w-5 stroke-2' /> + </button> + )} + </div> + + {children} + </motion.div> + )} + + </AnimatePresence>, + document.querySelector('body')! + ) +} + +export default Modal
\ No newline at end of file diff --git a/src-migrate/common/components/skeleton/PageContentSkeleton.tsx b/src-migrate/common/components/skeleton/PageContentSkeleton.tsx new file mode 100644 index 00000000..bf85cff1 --- /dev/null +++ b/src-migrate/common/components/skeleton/PageContentSkeleton.tsx @@ -0,0 +1,19 @@ +const PageContentSkeleton = () => { + return ( + <div className="animate-pulse grid gap-y-4"> + <div className="w-full h-10 bg-gray-300 rounded" /> + <div className="h-2" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-8/12 h-4 bg-gray-300 rounded" /> + <div className="h-2" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-full h-4 bg-gray-300 rounded" /> + <div className="w-1/2 h-4 bg-gray-300 rounded" /> + </div> + ) +} + +export default PageContentSkeleton
\ No newline at end of file |
