import styled from 'styled-components'; import { Text, Flex, Box, BoxProps, Button, Icon } from '../../../general'; import { capitalizeFirstLetter } from '../../util/strings'; import { BubbleAuthor } from './Bubble.styles'; import { FragmentBlock, FragmentPlain, FragmentBlockquote, renderFragment, FragmentImage, } from './fragment-lib'; import { FragmentType, FragmentImageType, TEXT_TYPES } from './Bubble.types'; import { useMemo } from 'react'; import { convertDarkText } from '../../../util'; const ReplyContainer = styled(Flex)` flex-direction: column; justify-content: flex-end; overflow: hidden; blockquote { margin: 0px 0px; } width: 100%; `; export type ReplyProps = { id: string; author: string; authorColor?: string; sentAt: string; message?: FragmentType[]; containerWidth?: number; themeMode?: 'light' | 'dark'; onClick?: (evt: React.MouseEvent) => void; onCancel?: () => void; } & BoxProps; export const Reply = (props: ReplyProps) => { const { id, author, authorColor, message, containerWidth, themeMode, onClick = () => {}, onCancel, } = props; const authorColorDisplay = useMemo( () => (authorColor && convertDarkText(authorColor, themeMode)) || 'rgba(var(--rlm-text-rgba))', [authorColor] ); if (!message) return null; const fragmentType: string = Object.keys(message[0])[0]; let replyContent = null; let mediaContent = null; if ( (!TEXT_TYPES.includes(fragmentType) && fragmentType !== 'image' && fragmentType !== 'reply') || fragmentType === 'code' ) { replyContent = ( {capitalizeFirstLetter(fragmentType)} ); } else if (fragmentType === 'image') { replyContent = ( {capitalizeFirstLetter(fragmentType)} ); const link: string = (message[0] as FragmentImageType).image; mediaContent = ( ); } else { replyContent = renderFragment( id, message[0], 0, author, containerWidth ? containerWidth - 16 - 22 : undefined ); } let additionalWidth = mediaContent ? 100 : 0; return ( {mediaContent} {author} {replyContent} {onCancel && ( ) => { evt.stopPropagation(); onCancel(); }} > )} ); };