File tree Expand file tree Collapse file tree 7 files changed +81
-3
lines changed
pages/Sandbox/Editor/Content Expand file tree Collapse file tree 7 files changed +81
-3
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,10 @@ class Preview extends React.Component<Props, State> {
220220 code : store . editor . currentPackageJSONCode ,
221221 } ;
222222
223+ if ( ! store . editor . previewWindow . content ) {
224+ return null ;
225+ }
226+
223227 return (
224228 < FlyingContainer onPositionChange = { this . resetAlignment } >
225229 { ( { resize } ) => (
Original file line number Diff line number Diff line change 11import styled , { css } from 'styled-components' ;
22import PrettierIcon from 'react-icons/lib/md/brush' ;
3+ import WindowIcon from 'react-icons/lib/md/web-asset' ;
34
45export const Container = styled . div `
56 position : absolute;
@@ -35,6 +36,8 @@ export const StyledPrettierIcon = styled(PrettierIcon)`
3536 height: 1.125rem;
3637 cursor: pointer;
3738
39+ padding-right: 0.5rem;
40+
3841 opacity: 0.6;
3942
4043 &:hover {
@@ -56,3 +59,39 @@ export const IconContainer = styled.div`
5659 flex-shrink : 1 ;
5760 padding : 0 0.75rem ;
5861` ;
62+
63+ export const Line = styled . div `
64+ height : 12px ;
65+ width : 1px ;
66+
67+ background-color : rgba (255 , 255 , 255 , 0.3 );
68+ ` ;
69+
70+ export const StyledWindowIcon = styled ( WindowIcon ) `
71+ transition: 0.3s ease opacity;
72+ width: 1.25rem;
73+ height: 1.25rem;
74+ cursor: pointer;
75+
76+ opacity: 0.6;
77+
78+ padding-left: 0.5rem;
79+
80+ &:hover {
81+ opacity: 1;
82+ }
83+
84+ ${ props =>
85+ props . active &&
86+ css `
87+ opacity : 1 ;
88+ color : white;
89+ ` } ;
90+
91+ ${ props =>
92+ props . disabled &&
93+ css `
94+ opacity : 0 ;
95+ pointer-events : none;
96+ ` } ;
97+ ` ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import {
1010 TabsContainer ,
1111 IconContainer ,
1212 StyledPrettierIcon ,
13+ StyledWindowIcon ,
14+ Line ,
1315} from './elements' ;
1416
1517class EditorTabs extends React . Component {
@@ -109,6 +111,8 @@ class EditorTabs extends React.Component {
109111
110112 const currentModule = store . editor . currentModule ;
111113
114+ const previewVisible = ! ! store . editor . previewWindow . content ;
115+
112116 return (
113117 < Container >
114118 < TabsContainer
@@ -169,13 +173,30 @@ class EditorTabs extends React.Component {
169173 ) ;
170174 } ) }
171175 </ TabsContainer >
176+
172177 < IconContainer >
173178 < Tooltip title = "Prettify" >
174179 < StyledPrettierIcon
175180 disabled = { ! this . canPrettify ( currentModule ) }
176181 onClick = { this . prettifyModule }
177182 />
178183 </ Tooltip >
184+ < Line />
185+
186+ < Tooltip title = { previewVisible ? 'Hide Browser' : 'Show Browser' } >
187+ < StyledWindowIcon
188+ onClick = { ( ) =>
189+ previewVisible
190+ ? this . props . signals . editor . setPreviewContent ( {
191+ content : undefined ,
192+ } )
193+ : this . props . signals . editor . setPreviewContent ( {
194+ content : 'browser' ,
195+ } )
196+ }
197+ active = { previewVisible }
198+ />
199+ </ Tooltip >
179200 </ IconContainer >
180201 </ Container >
181202 ) ;
Original file line number Diff line number Diff line change @@ -240,18 +240,25 @@ class EditorPreview extends React.Component<Props, State> {
240240 const notSynced = ! store . editor . isAllModulesSynced ;
241241 const sandbox = store . editor . currentSandbox ;
242242 const preferences = store . preferences ;
243- const { x, y, width } = store . editor . previewWindow ;
243+ const { x, y, width, content } = store . editor . previewWindow ;
244+
245+ const windowVisible = ! ! content ;
244246
245247 const windowRightSize = - x + width + 16 ;
246248
247249 const isVerticalMode = this . state . width
248250 ? this . state . width / 4 > this . state . width - windowRightSize
249251 : false ;
250252
251- const editorWidth = isVerticalMode
253+ let editorWidth = isVerticalMode
252254 ? '100%'
253255 : `calc(100% - ${ windowRightSize } px)` ;
254- const editorHeight = isVerticalMode ? `${ y + 16 } px` : '100%' ;
256+ let editorHeight = isVerticalMode ? `${ y + 16 } px` : '100%' ;
257+
258+ if ( ! windowVisible ) {
259+ editorWidth = '100%' ;
260+ editorHeight = '100%' ;
261+ }
255262
256263 return (
257264 < ThemeProvider
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ export default Module({
4141 width : undefined ,
4242 x : 0 ,
4343 y : 0 ,
44+ content : 'browser' ,
4445 } ,
4546 } ,
4647 getters : {
@@ -80,5 +81,6 @@ export default Module({
8081 quickActionsOpened : sequences . openQuickActions ,
8182 quickActionsClosed : sequences . closeQuickActions ,
8283 setPreviewBounds : sequences . setPreviewBounds ,
84+ setPreviewContent : sequences . setPreviewContent ,
8385 } ,
8486} ) ;
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ export default {
136136 isUpdatingPrivacy : types . boolean ,
137137 quickActionsOpen : types . boolean ,
138138 previewWindow : types . model ( {
139+ content : types . maybe ( types . string ) ,
139140 width : types . maybe ( types . number ) ,
140141 height : types . maybe ( types . number ) ,
141142 x : types . maybe ( types . number ) ,
Original file line number Diff line number Diff line change @@ -202,3 +202,7 @@ export const handlePreviewAction = [
202202] ;
203203
204204export const setPreviewBounds = [ actions . setPreviewBounds ] ;
205+
206+ export const setPreviewContent = [
207+ set ( state `editor.previewWindow.content` , props `content` ) ,
208+ ] ;
You can’t perform that action at this time.
0 commit comments