-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathPreview.jsx
More file actions
88 lines (83 loc) · 2.6 KB
/
Preview.jsx
File metadata and controls
88 lines (83 loc) · 2.6 KB
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
84
85
86
87
88
import {
faChevronDown,
faExternalLinkAlt,
faSyncAlt,
} from '@fortawesome/free-solid-svg-icons';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import classnames from 'classnames';
import partial from 'lodash-es/partial';
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PreviewFrame from './PreviewFrame';
export default function Preview({
compiledProjects,
consoleEntries,
currentProjectKey,
isOpen,
showingErrors,
title,
onConsoleError,
onConsoleLog,
onConsoleValue,
onPopOutProject,
onRefreshClick,
onRuntimeError,
onToggleVisible,
onSave,
}) {
if (showingErrors) {
return null;
}
const projectFrames = compiledProjects.map((compiledProject, key) => (
<PreviewFrame
compiledProject={compiledProject}
consoleEntries={consoleEntries}
isActive={key === compiledProjects.keySeq().last()}
key={compiledProject.compiledProjectKey}
onConsoleError={onConsoleError}
onConsoleLog={onConsoleLog}
onConsoleValue={onConsoleValue}
onRuntimeError={onRuntimeError}
onSave={onSave}
/>
));
return (
<div
className={classnames('preview', 'output__item', {u__hidden: !isOpen})}
>
<div className="preview__title-bar">
<span className="preview__button preview__button_pop-out">
<FontAwesomeIcon icon={faExternalLinkAlt} onClick={onPopOutProject} />
</span>
<span className="preview__title-text">{title}</span>
<span className="preview__button preview__button_toggle-visibility">
<FontAwesomeIcon
icon={faChevronDown}
onClick={partial(onToggleVisible, currentProjectKey)}
/>
</span>
<span className="preview__button preview__button_reset">
<FontAwesomeIcon icon={faSyncAlt} onClick={onRefreshClick} />
</span>
</div>
{projectFrames}
</div>
);
}
Preview.propTypes = {
compiledProjects: ImmutablePropTypes.iterable.isRequired,
consoleEntries: ImmutablePropTypes.iterable.isRequired,
currentProjectKey: PropTypes.string.isRequired,
isOpen: PropTypes.bool.isRequired,
showingErrors: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
onConsoleError: PropTypes.func.isRequired,
onConsoleLog: PropTypes.func.isRequired,
onConsoleValue: PropTypes.func.isRequired,
onPopOutProject: PropTypes.func.isRequired,
onRefreshClick: PropTypes.func.isRequired,
onRuntimeError: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired,
onToggleVisible: PropTypes.func.isRequired,
};