2024-10-26 14:33:04 -05:00
|
|
|
import { Box } from '@radix-ui/themes';
|
|
|
|
|
import { useEffect, useRef } from 'react';
|
2024-10-26 19:46:35 -05:00
|
|
|
import { embedPreviews } from '../../../constants/embeds';
|
2024-10-26 14:33:04 -05:00
|
|
|
import { useEmbedStateCurry } from '../../../stores/embedState/utilities';
|
|
|
|
|
import * as styles from './index.css';
|
|
|
|
|
|
|
|
|
|
interface PreviewWrapperProps {
|
2024-10-26 19:46:35 -05:00
|
|
|
name: keyof typeof embedPreviews;
|
2024-10-28 10:57:42 -05:00
|
|
|
naked?: boolean;
|
2024-10-26 14:33:04 -05:00
|
|
|
}
|
|
|
|
|
|
2024-10-28 10:57:42 -05:00
|
|
|
export function PreviewWrapper({ name, naked }: PreviewWrapperProps) {
|
2024-10-28 10:30:53 -05:00
|
|
|
const { useEmbedState } = useEmbedStateCurry();
|
|
|
|
|
const width = useEmbedState('width');
|
|
|
|
|
const height = useEmbedState('height');
|
2024-10-26 19:46:35 -05:00
|
|
|
const Preview = embedPreviews[name];
|
2024-10-26 14:33:04 -05:00
|
|
|
const wrapper = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!wrapper.current) return;
|
|
|
|
|
|
|
|
|
|
wrapper.current.classList.remove(styles.animated);
|
|
|
|
|
void wrapper.current.offsetWidth;
|
|
|
|
|
wrapper.current.classList.add(styles.animated);
|
|
|
|
|
}, [width, height]);
|
|
|
|
|
|
2024-10-28 10:57:42 -05:00
|
|
|
if (naked) {
|
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
position="absolute"
|
|
|
|
|
top="0"
|
|
|
|
|
left="50%"
|
|
|
|
|
style={{ transform: 'translate(-50%, 0) scale(0.75)' }}
|
|
|
|
|
width={`${width}px`}
|
|
|
|
|
height={`${height}px`}
|
|
|
|
|
>
|
|
|
|
|
<Preview />
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-26 14:33:04 -05:00
|
|
|
return (
|
|
|
|
|
<Box
|
2024-10-28 10:57:42 -05:00
|
|
|
position="absolute"
|
|
|
|
|
top="50%"
|
|
|
|
|
left="50%"
|
|
|
|
|
overflow="hidden"
|
|
|
|
|
style={{ transform: naked ? 'scale(0.25)' : 'translate(-50%, -50%)' }}
|
2024-10-26 14:33:04 -05:00
|
|
|
ref={wrapper}
|
|
|
|
|
width={`${width}px`}
|
|
|
|
|
height={`${height}px`}
|
|
|
|
|
>
|
|
|
|
|
<Preview />
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|