import React, { useRef } from 'react'; import flatMap from 'lodash/flatMap'; import Iframe from './Iframe'; import { compileJsx } from '../../utils/compileJsx'; import { PlayroomProps } from '../Playroom'; import { Strong } from '../Strong/Strong'; import { Text } from '../Text/Text'; import playroomConfig from '../../config'; import frameSrc from './frameSrc'; // @ts-ignore import styles from './Frames.less'; interface FramesProps { code: string; themes: PlayroomProps['themes']; widths: PlayroomProps['widths']; } export default function Frames({ code, themes, widths }: FramesProps) { const scrollingPanelRef = useRef(null); const frames = flatMap(widths, (width) => themes.map((theme) => ({ theme, width, widthName: `${width}${/\d$/.test(width.toString()) ? 'px' : ''}`, })) ); let renderCode = code; try { renderCode = compileJsx(code); } catch (e) { renderCode = ''; } return (
{frames.map((frame) => (