Skip to content

Commit 63ca334

Browse files
Merge pull request #124 from gridaco/editor/preview-full-screen
Full-screen instant preview
2 parents 1f7f64f + 43f94f8 commit 63ca334

File tree

6 files changed

+326
-34
lines changed

6 files changed

+326
-34
lines changed

editor/components/canvas/isolated-canvas.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import styled from "@emotion/styled";
33
import { useGesture } from "@use-gesture/react";
44
import useMeasure from "react-use-measure";
@@ -61,10 +61,12 @@ export function IsolatedCanvas({
6161
children,
6262
defaultSize,
6363
onExit,
64+
onFullscreen,
6465
}: {
6566
defaultSize: { width: number; height: number };
6667
children?: React.ReactNode;
6768
onExit?: () => void;
69+
onFullscreen?: () => void;
6870
}) {
6971
const _margin = 20;
7072
const [canvasSizingRef, canvasBounds] = useMeasure();
@@ -136,7 +138,12 @@ export function IsolatedCanvas({
136138
scale={scale}
137139
onChange={setScale}
138140
/>
139-
{onExit && <ExitButton onClick={onExit}>End Isolation</ExitButton>}
141+
{onFullscreen && (
142+
<ActionButton onClick={onFullscreen}>Full Screen</ActionButton>
143+
)}
144+
{onExit && (
145+
<ActionButton onClick={onExit}>End Isolation</ActionButton>
146+
)}
140147
</Controls>
141148
{/* <ScalingAreaStaticRoot> */}
142149
<TransformContainer
@@ -155,7 +162,7 @@ export function IsolatedCanvas({
155162
);
156163
}
157164

158-
const ExitButton = styled.button`
165+
const ActionButton = styled.button`
159166
align-self: center;
160167
background-color: ${colors.color_editor_bg_on_dark};
161168
box-shadow: ${colors.color_editor_bg_on_dark} 0px 0px 0px 16px inset;

editor/layouts/default-editor-workspace-layout.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ export function DefaultEditorWorkspaceLayout(props: {
77
rightbar?: JSX.Element;
88
appbar?: JSX.Element;
99
children: JSX.Element | Array<JSX.Element>;
10+
display?: "none" | "initial"; // set to none when to hide.
1011
backgroundColor?: string;
1112
}) {
1213
return (
13-
<WorkspaceRoot backgroundColor={props.backgroundColor}>
14+
<WorkspaceRoot
15+
display={props.display}
16+
backgroundColor={props.backgroundColor}
17+
>
1418
<AppBarMenuAndBelowContentWrap>
1519
{props.appbar && <AppBarWrap>{props.appbar}</AppBarWrap>}
1620
<NonMenuContentZoneWrap>
@@ -27,7 +31,11 @@ export function DefaultEditorWorkspaceLayout(props: {
2731
);
2832
}
2933

30-
const WorkspaceRoot = styled.div<{ backgroundColor: string }>`
34+
const WorkspaceRoot = styled.div<{
35+
display?: "none" | "initial";
36+
backgroundColor: string;
37+
}>`
38+
${(props) => props.display && `display: ${props.display};`}
3139
width: 100vw;
3240
height: 100vh;
3341
background-color: ${(p) => p.backgroundColor ?? "transparent"};

editor/scaffolds/canvas/isolate-mode.tsx

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import { IsolatedCanvas } from "components/canvas";
88
import { PreviewAndRunPanel } from "components/preview-and-run";
99
import { useEditorState } from "core/states";
1010
import { useTargetContainer } from "hooks";
11+
import { Dialog } from "@material-ui/core";
12+
import { FullScreenPreview } from "scaffolds/preview-full-screen";
1113

1214
export function IsolateModeCanvas({ onClose }: { onClose: () => void }) {
1315
const [state] = useEditorState();
1416
const [preview, setPreview] = useState<Result>();
17+
const [fullscreen, setFullscreen] = useState(false);
1518

1619
const { target, root } = useTargetContainer();
1720

@@ -69,30 +72,49 @@ export function IsolateModeCanvas({ onClose }: { onClose: () => void }) {
6972
}, [target?.id]);
7073

7174
return (
72-
<IsolatedCanvas
73-
key={target?.id}
74-
onExit={onClose}
75-
defaultSize={{
76-
width: target?.width ?? 375,
77-
height: target?.height ?? 812,
78-
}}
79-
>
80-
{preview ? (
81-
<VanillaRunner
82-
key={preview.scaffold.raw}
83-
style={{
84-
borderRadius: 4,
85-
boxShadow: "0px 0px 48px #00000020",
75+
<>
76+
<Dialog
77+
fullScreen
78+
onClose={() => {
79+
setFullscreen(false);
80+
}}
81+
open={fullscreen}
82+
>
83+
<FullScreenPreview
84+
onClose={() => {
85+
setFullscreen(false);
8686
}}
87-
source={preview.scaffold.raw}
88-
width="100%"
89-
height="100%"
90-
componentName={preview.name}
9187
/>
92-
) : (
93-
<EditorCanvasSkeleton />
94-
)}
95-
</IsolatedCanvas>
88+
</Dialog>
89+
90+
<IsolatedCanvas
91+
key={target?.id}
92+
onExit={onClose}
93+
onFullscreen={() => {
94+
setFullscreen(true);
95+
}}
96+
defaultSize={{
97+
width: target?.width ?? 375,
98+
height: target?.height ?? 812,
99+
}}
100+
>
101+
{preview ? (
102+
<VanillaRunner
103+
key={preview.scaffold.raw}
104+
style={{
105+
borderRadius: 4,
106+
boxShadow: "0px 0px 48px #00000020",
107+
}}
108+
source={preview.scaffold.raw}
109+
width="100%"
110+
height="100%"
111+
componentName={preview.name}
112+
/>
113+
) : (
114+
<EditorCanvasSkeleton />
115+
)}
116+
</IsolatedCanvas>
117+
</>
96118
);
97119
}
98120

editor/scaffolds/editor/editor.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import React, { useEffect, useRef, useState } from "react";
1+
import React, { useEffect } from "react";
22
import { DefaultEditorWorkspaceLayout } from "layouts/default-editor-workspace-layout";
33
import {
44
WorkspaceContentPanel,
55
WorkspaceContentPanelGridLayout,
66
} from "layouts/panel";
7-
import { WorkspaceBottomPanelDockLayout } from "layouts/panel/workspace-bottom-panel-dock-layout";
87
import { EditorSidebar } from "components/editor";
98
import { useEditorState, useWorkspaceState } from "core/states";
10-
119
import { Canvas } from "scaffolds/canvas";
1210
import { CodeSegment } from "scaffolds/code";
13-
import { Inspector } from "scaffolds/inspector";
14-
1511
import { EditorSkeleton } from "./skeleton";
1612
import { colors } from "theme";
17-
import { Debugger } from "@code-editor/debugger";
18-
1913
import { RemoteImageRepositories } from "@design-sdk/figma-remote/lib/asset-repository/image-repository";
2014
import {
2115
ImageRepository,
@@ -76,6 +70,7 @@ export function Editor({
7670
{(loading || !_initially_loaded) && (
7771
<EditorSkeleton percent={_initial_load_progress * 100} />
7872
)}
73+
7974
<DefaultEditorWorkspaceLayout
8075
backgroundColor={colors.color_editor_bg_on_dark}
8176
leftbar={<EditorSidebar />}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Full screen previewer

0 commit comments

Comments
 (0)