import { ChakraProps, Flex, Icon, Image, useColorMode, useColorModeValue, } from '@chakra-ui/react'; import { TypesafeDraggableData, TypesafeDroppableData, } from 'app/components/ImageDnd/typesafeDnd'; import IAIIconButton from 'common/components/IAIIconButton'; import { IAINoContentFallback } from 'common/components/IAIImageFallback'; import ImageMetadataOverlay from 'common/components/ImageMetadataOverlay'; import { useImageUploadButton } from 'common/hooks/useImageUploadButton'; import { MouseEvent, ReactElement, SyntheticEvent, memo } from 'react'; import { FaImage, FaUndo, FaUpload } from 'react-icons/fa'; import { PostUploadAction } from 'services/api/thunks/image'; import { ImageDTO } from 'services/api/types'; import { mode } from 'theme/util/mode'; import IAIDraggable from './IAIDraggable'; import IAIDroppable from './IAIDroppable'; type IAIDndImageProps = { imageDTO: ImageDTO | undefined; onError?: (event: SyntheticEvent) => void; onLoad?: (event: SyntheticEvent) => void; onClick?: (event: MouseEvent) => void; onClickReset?: (event: MouseEvent) => void; withResetIcon?: boolean; resetIcon?: ReactElement; resetTooltip?: string; withMetadataOverlay?: boolean; isDragDisabled?: boolean; isDropDisabled?: boolean; isUploadDisabled?: boolean; minSize?: number; postUploadAction?: PostUploadAction; imageSx?: ChakraProps['sx']; fitContainer?: boolean; droppableData?: TypesafeDroppableData; draggableData?: TypesafeDraggableData; dropLabel?: string; isSelected?: boolean; thumbnail?: boolean; noContentFallback?: ReactElement; }; const IAIDndImage = (props: IAIDndImageProps) => { const { imageDTO, onClickReset, onError, onClick, withResetIcon = false, withMetadataOverlay = false, isDropDisabled = false, isDragDisabled = false, isUploadDisabled = false, minSize = 24, postUploadAction, imageSx, fitContainer = false, droppableData, draggableData, dropLabel, isSelected = false, thumbnail = false, resetTooltip = 'Reset', resetIcon = , noContentFallback = , } = props; const { colorMode } = useColorMode(); const { getUploadButtonProps, getUploadInputProps } = useImageUploadButton({ postUploadAction, isDisabled: isUploadDisabled, }); const resetIconShadow = useColorModeValue( `drop-shadow(0px 0px 0.1rem var(--invokeai-colors-base-600))`, `drop-shadow(0px 0px 0.1rem var(--invokeai-colors-base-800))` ); const uploadButtonStyles = isUploadDisabled ? {} : { cursor: 'pointer', bg: mode('base.200', 'base.800')(colorMode), _hover: { bg: mode('base.300', 'base.650')(colorMode), color: mode('base.500', 'base.300')(colorMode), }, }; return ( {imageDTO && ( } width={imageDTO.width} height={imageDTO.height} onError={onError} draggable={false} sx={{ objectFit: 'contain', maxW: 'full', maxH: 'full', borderRadius: 'base', shadow: isSelected ? 'selected.light' : undefined, _dark: { shadow: isSelected ? 'selected.dark' : undefined }, ...imageSx, }} /> {withMetadataOverlay && } )} {!imageDTO && !isUploadDisabled && ( <> )} {!imageDTO && isUploadDisabled && noContentFallback} {!isDropDisabled && ( )} {imageDTO && !isDragDisabled && ( )} {onClickReset && withResetIcon && imageDTO && ( )} ); }; export default memo(IAIDndImage);