import React, {CSSProperties} from 'react'; import {Loader} from 'superdesk-ui-framework/react/components/Loader'; interface IProps { loading: boolean; } /** * Displays last HTML snapshot when loading. */ export class SmoothLoader extends React.Component { private wrapper: HTMLDivElement; private lastSnapshotHtml: string; constructor(props: IProps) { super(props); this.saveSnapshot = this.saveSnapshot.bind(this); } saveSnapshot() { if (this.props.loading !== true) { this.lastSnapshotHtml = this.wrapper.innerHTML; } } componentDidMount() { this.saveSnapshot(); } componentDidUpdate() { this.saveSnapshot(); } render() { const {loading, children} = this.props; const style: CSSProperties = loading ? {position: 'absolute', left: -9999, top: -9999, visibility: 'hidden'} : {height: '100%'}; return (
{ this.wrapper = ref; }} style={{height: '100%'}} > {/** * Children have to be rendered unconditionally in the same place in the component tree * to prevent React reconciliation algorithm from remounting it. */}
{children}
{ loading && (
'}} style={{height: '100%'}} />
) }
); } }