Skip to content

Commit

Permalink
feat: Support custom frame URLs (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles authored Jun 1, 2020
1 parent f5ad5ff commit 8fc0b83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Playroom/Frames/Frames.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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';
Expand Down Expand Up @@ -54,11 +55,10 @@ export default function Frames({ code, themes, widths }: FramesProps) {
</div>
<Iframe
intersectionRootRef={scrollingPanelRef}
src={`${playroomConfig.baseUrl}frame.html${
playroomConfig.paramType === 'hash' ? '#' : ''
}?themeName=${encodeURIComponent(
frame.theme
)}&code=${encodeURIComponent(renderCode)}`}
src={frameSrc(
{ themeName: frame.theme, code: renderCode },
playroomConfig
)}
className={styles.frame}
style={{ width: frame.width }}
data-testid="previewFrame"
Expand Down
19 changes: 19 additions & 0 deletions src/Playroom/Frames/frameSrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable-next-line import/no-unresolved */
// @ts-ignore
import { frameSrc } from '__PLAYROOM_ALIAS__FRAME_COMPONENT__';

interface FrameParams {
code: string;
themeName: string;
}
const defaultFrameSrc = (
{ code, themeName }: FrameParams,
{ baseUrl, paramType }: InternalPlayroomConfig
) =>
`${baseUrl}frame.html${
paramType === 'hash' ? '#' : ''
}?themeName=${encodeURIComponent(themeName)}&code=${encodeURIComponent(
code
)}`;

export default frameSrc ? frameSrc : defaultFrameSrc;

0 comments on commit 8fc0b83

Please sign in to comment.