Skip to content

Commit

Permalink
Make iframe height configurable and add border (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
danoc authored Oct 22, 2019
1 parent 85fa537 commit 054513e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions www/src/cms/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import styles from '!css-loader!sass-loader!./preview.scss';
CMS.registerEditorComponent({
id: 'figma',
label: 'Figma',
fields: [{ name: 'id', label: 'Figma URL', widget: 'string' }],
fields: [
{ name: 'id', label: 'Figma URL', widget: 'string' },
{ name: 'height', label: 'Height', widget: 'number', default: 500, min: 350 },
],
// eslint-disable-next-line no-useless-escape
pattern: /<iframe height="500" width="100%" src="https:\/\/www.figma.com\/embed\?embed_host=astra&url=(https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?)" allowfullscreen frameborder="0"><\/iframe>$/,
pattern: /<iframe height="(\d*)" width="100%" src="https:\/\/www.figma.com\/embed\?embed_host=astra&url=(https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?)" allowfullscreen frameborder="0"><\/iframe>$/,
fromBlock: match => ({
id: match[1],
height: match[1],
id: match[2],
}),
toBlock: obj =>
`<iframe height="500" width="100%" src="https://www.figma.com/embed?embed_host=astra&url=${obj.id}" allowfullscreen frameborder="0"></iframe>`,
`<iframe height="${obj.height}" width="100%" src="https://www.figma.com/embed?embed_host=astra&url=${obj.id}" allowfullscreen frameborder="0"></iframe>`,
toPreview: obj =>
`<iframe height="500" width="100%" src="https://www.figma.com/embed?embed_host=astra&url=${obj.id}" allowfullscreen frameborder="0"></iframe>`,
`<iframe height="${obj.height}" width="100%" src="https://www.figma.com/embed?embed_host=astra&url=${obj.id}" allowfullscreen frameborder="0"></iframe>`,
});

CMS.registerPreviewStyle(styles.toString(), { raw: true });
9 changes: 9 additions & 0 deletions www/src/components/mdx/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ export const HR = p => (
<hr {...p} className="bt b-gray-300 mv4" style={{ height: '0', border: '0' }} />
);

export const Iframe = p => (
<iframe
{...p}
className="pa1 mb1 ba bw-2 br2 b-gray-300"
title="Image of component from Figma"
/>
);

export const MDXRenderer = ({ children }) => {
let renderedChildren = children;

Expand All @@ -184,6 +192,7 @@ export const MDXRenderer = ({ children }) => {
td: TD,
th: TH,
hr: HR,
iframe: Iframe,
}}
>
{renderedChildren}
Expand Down

0 comments on commit 054513e

Please sign in to comment.