Skip to content

Commit f6e507c

Browse files
committed
feat: 🎸 add CodeSandbox support
1 parent 215d50f commit f6e507c

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
<div align="center">
7777
<div>DailyMotion</div>
78+
<div>CodeSandbox</div>
7879
<div>Facebook Video</div>
7980
<div>Figma</div>
8081
<div>Gfycat</div>

‎src/ReactEmbed.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const defaultBlocks: Blocks = {
4141
soundcloud: React.lazy(() => import('./blocks/soundcloud')),
4242
tweet: React.lazy(() => import('./blocks/tweet')),
4343
youtube: React.lazy(() => import('./blocks/youtube')),
44+
codesandbox: React.lazy(() => import('./blocks/codesandbox')),
4445
};
4546

4647
export type ReactEmbedRouterResult = undefined | [undefined | React.ComponentType<BlockProps>, EmbedBlockId];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import {storiesOf} from '@storybook/react';
3+
import Embed from '..';
4+
import {Box} from './Box';
5+
6+
storiesOf('codesandbox', module)
7+
.add('Default', () => {
8+
return <Embed url={'https://codesandbox.io/embed/react-new?fontsize=14&hidenavigation=1&theme=dark'} />;
9+
})
10+
.add('Fitted', () => {
11+
return (
12+
<Box>
13+
<Embed url={'https://codesandbox.io/embed/react-new?fontsize=14&hidenavigation=1&theme=dark'} />
14+
</Box>
15+
);
16+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react';
2+
import {BlockProps} from '../..';
3+
4+
export interface CodeSandboxProps extends BlockProps {}
5+
6+
const CodeSandbox: React.FC<CodeSandboxProps> = ({
7+
url,
8+
renderWrap,
9+
}) => {
10+
11+
return renderWrap(
12+
<iframe
13+
src={url}
14+
style={{
15+
width: '100%',
16+
height: '500px',
17+
border: 0,
18+
borderRadius: '4px',
19+
overflow: 'hidden',
20+
}}
21+
width="100%"
22+
height="500"
23+
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
24+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
25+
/>
26+
);
27+
};
28+
29+
export default CodeSandbox;

‎src/routeToBlock.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ const routeToBlock: ReactEmbedRouter = (blocks: Blocks, parsed: ParsedUrl) => {
9292
case 'dropbox.com':
9393
case 'www.dropbox.com':
9494
return [blocks.dropbox, ''];
95+
case 'codesandbox.io':
96+
if (url.includes('codesandbox.io/embed/')) return [blocks.codesandbox, ''];
97+
return undefined;
9598
default:
9699
if (canPlayPdf(url)) {
97100
return [blocks.pdf, ''];

0 commit comments

Comments
 (0)