'use client'; import React from 'react'; import { createModal } from '@gluestack-ui/modal'; import { Pressable, View, ScrollView, ViewStyle } from 'react-native'; import { Motion, AnimatePresence, createMotionAnimatedComponent, MotionComponentProps, } from '@legendapp/motion'; import { tva } from '@gluestack-ui/nativewind-utils/tva'; import { withStyleContext, useStyleContext, } from '@gluestack-ui/nativewind-utils/withStyleContext'; import { cssInterop } from 'nativewind'; import type { VariantProps } from '@gluestack-ui/nativewind-utils'; type IAnimatedPressableProps = React.ComponentProps & MotionComponentProps; const AnimatedPressable = createMotionAnimatedComponent( Pressable ) as React.ComponentType; const SCOPE = 'MODAL'; type IMotionViewProps = React.ComponentProps & MotionComponentProps; const MotionView = Motion.View as React.ComponentType; const UIModal = createModal({ Root: withStyleContext(View, SCOPE), Backdrop: AnimatedPressable, Content: MotionView, Body: ScrollView, CloseButton: Pressable, Footer: View, Header: View, AnimatePresence: AnimatePresence, }); cssInterop(AnimatedPressable, { className: 'style' }); cssInterop(MotionView, { className: 'style' }); const modalStyle = tva({ base: 'group/modal w-full h-full justify-center items-center web:pointer-events-none', variants: { size: { xs: '', sm: '', md: '', lg: '', full: '', }, }, }); const modalBackdropStyle = tva({ base: 'absolute left-0 top-0 right-0 bottom-0 bg-background-dark web:cursor-default', }); const modalContentStyle = tva({ base: 'bg-background-0 rounded-md overflow-hidden border border-outline-100 shadow-hard-2 p-6', parentVariants: { size: { xs: 'w-[60%] max-w-[360px]', sm: 'w-[70%] max-w-[420px]', md: 'w-[80%] max-w-[510px]', lg: 'w-[90%] max-w-[640px]', full: 'w-full', }, }, }); const modalBodyStyle = tva({ base: 'mt-2 mb-6', }); const modalCloseButtonStyle = tva({ base: 'group/modal-close-button z-10 rounded data-[focus-visible=true]:web:bg-background-100 web:outline-0 cursor-pointer', }); const modalHeaderStyle = tva({ base: 'justify-between items-center flex-row', }); const modalFooterStyle = tva({ base: 'flex-row justify-end items-center gap-2', }); type IModalProps = React.ComponentProps & VariantProps & { className?: string }; type IModalBackdropProps = React.ComponentProps & VariantProps & { className?: string }; type IModalContentProps = React.ComponentProps & VariantProps & { className?: string }; type IModalHeaderProps = React.ComponentProps & VariantProps & { className?: string }; type IModalBodyProps = React.ComponentProps & VariantProps & { className?: string }; type IModalFooterProps = React.ComponentProps & VariantProps & { className?: string }; type IModalCloseButtonProps = React.ComponentProps & VariantProps & { className?: string }; const Modal = React.forwardRef, IModalProps>( ({ className, size = 'md', ...props }, ref) => ( ) ); const ModalBackdrop = React.forwardRef< React.ComponentRef, IModalBackdropProps >(function ModalBackdrop({ className, ...props }, ref) { return ( ); }); const ModalContent = React.forwardRef< React.ComponentRef, IModalContentProps >(function ModalContent({ className, size, ...props }, ref) { const { size: parentSize } = useStyleContext(SCOPE); return ( ); }); const ModalHeader = React.forwardRef< React.ComponentRef, IModalHeaderProps >(function ModalHeader({ className, ...props }, ref) { return ( ); }); const ModalBody = React.forwardRef< React.ComponentRef, IModalBodyProps >(function ModalBody({ className, ...props }, ref) { return ( ); }); const ModalFooter = React.forwardRef< React.ComponentRef, IModalFooterProps >(function ModalFooter({ className, ...props }, ref) { return ( ); }); const ModalCloseButton = React.forwardRef< React.ComponentRef, IModalCloseButtonProps >(function ModalCloseButton({ className, ...props }, ref) { return ( ); }); Modal.displayName = 'Modal'; ModalBackdrop.displayName = 'ModalBackdrop'; ModalContent.displayName = 'ModalContent'; ModalHeader.displayName = 'ModalHeader'; ModalBody.displayName = 'ModalBody'; ModalFooter.displayName = 'ModalFooter'; ModalCloseButton.displayName = 'ModalCloseButton'; export { Modal, ModalBackdrop, ModalContent, ModalCloseButton, ModalHeader, ModalBody, ModalFooter, };