Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make iframe height configurable and add border #520

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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