Skip to content

Commit

Permalink
feat: add iframe recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Jan 1, 2025
1 parent 8eb950b commit 38cd1e7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions recipe-gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function Recipe() {
<li>
<a href="./three-buttons-dialog.html">Yes/No/Cancel Dialog</a>
</li>
<li>
<a href="./modal-with-iframe.html">Modal with iframe inside</a>
</li>
<li>
<a href="./draw-attention.html">Draw Attention / Persistent Dialog</a>
</li>
Expand Down
13 changes: 13 additions & 0 deletions recipe-gallery/modal-with-iframe-src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Swal from 'sweetalert2'
import './styles.css'

Swal.fire({
title: 'Modal with iframe',
html: '<iframe frameborder="0" src="https://www.youtube.com/embed/6JxAis_v2mw"></iframe>',
showCloseButton: true,
showConfirmButton: false,
customClass: {
popup: 'swal-with-iframe',
},
width: 1000,
})
15 changes: 15 additions & 0 deletions recipe-gallery/modal-with-iframe-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.swal-with-iframe {
padding-bottom: 0;
}

.swal-with-iframe .swal2-html-container {
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
}

.swal-with-iframe iframe {
aspect-ratio: 16 / 9;
width: 100%;
float: left;
}
8 changes: 8 additions & 0 deletions recipe-gallery/modal-with-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<load ="partials/head.html" title="Modal with iframe inside" />
<body>
<div id="root"></div>
<script type="module" src="./modal-with-iframe.tsx"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions recipe-gallery/modal-with-iframe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ReactDOM from 'react-dom/client'
import { Nav } from '../src/components'
import { Sandpack } from './components/Sandpack'

const styles = (await import(`./modal-with-iframe-styles.css?raw`)).default
const src = (await import('./modal-with-iframe-src?raw')).default

function Recipe() {
return (
<>
<Nav recipeGallery />
<h1>Modal with <strong>iframe</strong> inside</h1>

<p>
The important detail here is to keep the aspect ratio of the iframe. This is done by using CSS property <strong>aspect-ratio: 16 / 9;</strong>
</p>

<p>
The rest of CSS styles are to remove the default paddings and make iframe take all the space available.
</p>

<Sandpack
files={{
'/App.ts': src,
'/styles.css': styles,
}}
editorHeight={350}
previewHeight={600}
/>
</>
)
}

ReactDOM.createRoot(document.getElementById('root')!).render(<Recipe />)

0 comments on commit 38cd1e7

Please sign in to comment.