'use client'; import { createModal } from '@gluestack-ui/core/modal/creator'; import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils'; import { tva, useStyleContext, withStyleContext } from '@gluestack-ui/utils/nativewind-utils'; import { styled } from 'nativewind'; import React from 'react'; import { Pressable, ScrollView, View } from 'react-native'; import Animated, { Easing, FadeIn, FadeOut, ZoomIn } from 'react-native-reanimated'; const AnimatedPressable = Animated.createAnimatedComponent(Pressable); const AnimatedView = Animated.createAnimatedComponent(View); const SCOPE = 'MODAL'; const StyledAnimatedPressable = styled(AnimatedPressable, { className: 'style' }); const StyledAnimatedView = styled(AnimatedView, { className: 'style' }); const UIModal = createModal({ Root: withStyleContext(View as any, SCOPE), Backdrop: StyledAnimatedPressable, Content: StyledAnimatedView, Body: ScrollView, CloseButton: Pressable, Footer: View, Header: View, }); const modalStyle = tva({ base: 'group/modal w-full h-full justify-center items-center web:pointer-events-auto', variants: { size: { xs: '', sm: '', md: '', lg: '', full: '', }, }, }); const modalBackdropStyle = tva({ base: 'absolute left-0 top-0 right-0 bottom-0 bg-[#000]/50 web:cursor-default web:pointer-events-auto', }); const modalContentStyle = tva({ base: 'bg-background rounded-md overflow-hidden border border-border/80 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/90 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', style, ...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); const { style, ...restProps } = props; 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, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader };