diff --git a/src/components/preview-form.tsx b/src/components/preview-form.tsx index 7df0cd9..c72031b 100644 --- a/src/components/preview-form.tsx +++ b/src/components/preview-form.tsx @@ -4,7 +4,10 @@ import * as React from 'react'; import * as _ from 'lodash'; +import { Spinner } from '@wordpress/components'; + import { baseUrl } from '@/globals'; +import { ReactComponent as CogIcon } from '@/assets/cogicon.svg'; type PreviewProps = { formId: string; @@ -13,6 +16,7 @@ type PreviewProps = { type PreviewState = { uniqueId: string; + loading: boolean; }; class PreviewForm extends React.Component { @@ -23,11 +27,12 @@ class PreviewForm extends React.Component { // and removed from the page once it is no longer needed. this.state = { uniqueId: _.uniqueId(), + loading: true, }; } componentDidMount() { - this.loadEmbedScript(); + this.loadEmbedScript( this.formReady.bind( this ) ); } componentWillUnmount() { @@ -61,13 +66,32 @@ class PreviewForm extends React.Component { } } + // Check if form is loaded + formReady() { + this.setState( { loading: false } ); + } + render() { return ( -
+
+ { this.state.loading && +
+
+ +
+ +

+ Loading... +

+ + +
+ }
); diff --git a/src/styles/editor.scss b/src/styles/editor.scss index 112089d..b989508 100644 --- a/src/styles/editor.scss +++ b/src/styles/editor.scss @@ -19,9 +19,39 @@ // height: 500px; // } -.focus-grabber { - position: absolute; - width: 100%; - height: 100%; - z-index: 1; +.form-preview { + min-height: 200px; + + .focus-grabber { + position: absolute; + width: 100%; + height: 100%; + z-index: 1; + } + + .loader { + padding: 1em; + background: #fff; + text-align: center; + min-height: 200px; + border-radius: 2px; + box-shadow: inset 0 0 0 1px #1e1e1e; + + display: flex; + gap: 0.5em; + flex-direction: column; + align-items: center; + justify-content: center; + + .icon { + width: 2em; + height: 2em; + margin: 0 auto; + } + + p { + font-size: 13px; + margin: 0; + } + } }