// Copyright 2019-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { PopperArrowProps } from 'react-popper'; import { Placement } from '@popperjs/core'; import * as styles from './StickerPreview.scss'; import { MessageBubble } from './MessageBubble'; import { MessageSticker, Props as MessageStickerProps } from './MessageSticker'; import { useI18n } from '../util/i18n'; export type Props = Pick, 'style'> & { image: string; arrowProps?: PopperArrowProps; placement?: Placement; }; const renderMessages = ( text: string, image: string, kind: MessageStickerProps['kind'] ) => ( <> {text} ); const getArrowClass = (placement?: Placement) => { if (placement === 'top') { return styles.arrowBottom; } if (placement === 'right') { return styles.arrowLeft; } if (placement === 'left') { return styles.arrowRight; } return styles.arrowTop; }; export const StickerPreview = React.memo( React.forwardRef( ({ image, style, arrowProps, placement }: Props, ref) => { const i18n = useI18n(); return (
{arrowProps ? (
) : null}
{renderMessages( i18n('StickerCreator--StickerPreview--light'), image, 'light' )}
{renderMessages( i18n('StickerCreator--StickerPreview--dark'), image, 'dark' )}
); } ) );