import React, { ComponentType } from 'react'; import lzString from 'lz-string'; import { useParams } from '../utils/params'; import { compileJsx } from '../utils/compileJsx'; import SplashScreen from './SplashScreen/SplashScreen'; // @ts-ignore import styles from './Preview.less'; // @ts-ignore import CatchErrors from './CatchErrors/CatchErrors'; // @ts-ignore import RenderCode from './RenderCode/RenderCode'; interface PreviewState { code?: string; themeName?: string; } export interface PreviewProps { components: Record; themes: Record; FrameComponent: ComponentType<{ themeName: string; theme: any }>; } export default ({ themes, components, FrameComponent }: PreviewProps) => { const { themeName, code } = useParams( (rawParams): PreviewState => { if (rawParams.code) { const result = JSON.parse( lzString.decompressFromEncodedURIComponent(String(rawParams.code)) ?? '' ); return { code: compileJsx(result.code), themeName: result.theme, }; } return {}; } ); const resolvedTheme = themeName ? themes[themeName] : null; return (
); };