Skip to content

Commit

Permalink
docs: lazy load sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 21, 2023
1 parent a59066f commit c3c530e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const lightCodeTheme = require('prism-react-renderer/themes/github');
const config = {
baseUrl: '/',
favicon: 'favicon.ico',
title: 'Vest Validations Framework',
title: 'Vest',
tagline:
'Declarative validations framework inspired by unit testing libraries',
url: 'https://vestjs.dev',
Expand Down
25 changes: 21 additions & 4 deletions website/src/components/Demo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import clsx from 'clsx';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import styles from './Demo.module.css';
import commonStyles from './Common.module.css';

let initialized = false;

export default function Demo() {
const [currentSandbox, setCurrentSandbox] = useState(0);
const [currentSandbox, setCurrentSandbox] = useState(null);

useEffect(() => {
if (initialized) {
return;
}

setTimeout(() => {
initialized = true;
setCurrentSandbox(currentSandbox => currentSandbox ?? 0);
}, 1500);
}, []);

return (
<section className={clsx(styles.demo, commonStyles.main_section_centered)}>
Expand All @@ -25,7 +38,11 @@ export default function Demo() {
))}
</div>
<div className={styles.demoWrapper}>
<Sandbox {...embedLinks[currentSandbox]} />
{initialized ? (
<Sandbox {...embedLinks[currentSandbox]} />
) : (
<div className={styles.sandbox}></div>
)}
</div>
</div>
</section>
Expand All @@ -36,7 +53,7 @@ function Sandbox({ title, src }) {
return (
<iframe
src={src}
className={styles.sandboxIframe}
className={styles.sandbox}
title={title}
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
Expand Down
3 changes: 2 additions & 1 deletion website/src/components/Demo.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.sandboxIframe {
.sandbox {
width: 100%;
height: 500px;
border: 0;
Expand All @@ -13,6 +13,7 @@
.demoWrapper {
border: 1px solid var(--ifm-color-primary-lighter);
border-radius: 4px;
background: #191919;
}

.demoSwitchWrapper {
Expand Down

2 comments on commit c3c530e

@vercel
Copy link

@vercel vercel bot commented on c3c530e May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest – ./website

vest.vercel.app
vest-ealush.vercel.app
vest-git-latest-ealush.vercel.app
vestjs.dev
www.vestjs.dev

@vercel
Copy link

@vercel vercel bot commented on c3c530e May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-ealush.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next.vercel.app
vest-website.vercel.app

Please sign in to comment.