File size: 1,869 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { ThemePreview } from '@automattic/design-picker';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import photon from 'photon';
import AnimatedFullscreen from './animated-fullscreen';

interface SitePreviewProps {
	url: string;
	siteInfo?: {
		title: string;
		tagline: string;
	};
	inlineCss?: string;
	isFullscreen?: boolean;
	animated?: boolean;
	isExternallyManaged?: boolean;
	screenshot?: string;
	title: string;
	recordDeviceClick: ( device: string ) => void;
}

const SitePreview: React.FC< SitePreviewProps > = ( {
	url,
	siteInfo,
	inlineCss = '',
	isFullscreen,
	animated,
	isExternallyManaged,
	screenshot,
	title,
	recordDeviceClick,
} ) => {
	const translate = useTranslate();

	if ( isExternallyManaged ) {
		if ( screenshot === undefined ) {
			return null;
		}

		const width = 1000;
		const photonSrc = screenshot && photon( screenshot, { width } );
		const scrSet =
			photonSrc &&
			`${ photon( screenshot, { width, zoom: 2 } ) } 2x,
		${ photon( screenshot, { width, zoom: 3 } ) } 3x`;

		return (
			<div className="design-preview__screenshot-wrapper">
				<img
					className="design-preview__screenshot"
					alt={ translate( 'Screenshot of the %(themeName)s theme', {
						args: { themeName: title },
					} ).toString() }
					src={ photonSrc || screenshot }
					srcSet={ scrSet || undefined }
				/>
			</div>
		);
	}

	return (
		<AnimatedFullscreen
			className={ clsx( 'design-preview__site-preview', {
				'design-preview__site-preview--animated': animated,
			} ) }
			isFullscreen={ isFullscreen }
			enabled={ animated }
		>
			<ThemePreview
				url={ url }
				siteInfo={ siteInfo }
				inlineCss={ inlineCss }
				isShowFrameBorder
				isShowDeviceSwitcher
				isFullscreen={ isFullscreen }
				recordDeviceClick={ recordDeviceClick }
			/>
		</AnimatedFullscreen>
	);
};

export default SitePreview;