Files
blitzkit/packages/website/src/components/Embeds/PreviewWrapper/index.tsx
T

36 lines
1007 B
TypeScript
Raw Normal View History

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-26 14:33:04 -05:00
}
export function PreviewWrapper({ name }: 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]);
return (
<Box
ref={wrapper}
className={styles.wrapper}
width={`${width}px`}
height={`${height}px`}
>
<Preview />
</Box>
);
}