/** * External dependencies */ import classnames from 'classnames'; import { createElement, Component, createRef } from '@wordpress/element'; import { noop } from 'lodash'; import PropTypes from 'prop-types'; /** * Internal dependencies */ import Spinner from '../spinner'; /** * WebPreview component to display an iframe of another page. */ class WebPreview extends Component { constructor( props ) { super( props ); this.state = { isLoading: true, }; this.iframeRef = createRef(); this.setLoaded = this.setLoaded.bind( this ); } componentDidMount() { this.iframeRef.current.addEventListener( 'load', this.setLoaded ); } setLoaded() { this.setState( { isLoading: false } ); this.props.onLoad(); } render() { const { className, loadingContent, src, title } = this.props; const { isLoading } = this.state; const classes = classnames( 'woocommerce-web-preview', className, { 'is-loading': isLoading, } ); return (
{ isLoading && loadingContent }