Skip to content

Commit 15a371d

Browse files
add fullscreen preview mode on isolated canvas
1 parent af99311 commit 15a371d

4 files changed

Lines changed: 58 additions & 42 deletions

File tree

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/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+
;
89+
</Dialog>
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
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 { FullScreenPreview } from "scaffolds/preview-full-screen";
87
import { EditorSidebar } from "components/editor";
98
import { useEditorState, useWorkspaceState } from "core/states";
109
import { Canvas } from "scaffolds/canvas";
@@ -66,23 +65,15 @@ export function Editor({
6665
// this key is used for force re-rendering canvas after the whole file is fetched.
6766
const _refreshkey = loading || !_initially_loaded ? "1" : "0";
6867

69-
// TODO: migrate this to wsstate or editor state, - only for development.
70-
const [mode, setMode] = useState<"edit" | "fullscreen-preview">("edit");
71-
72-
const FullscreenPreviewMode = () => {
73-
return <FullScreenPreview />;
74-
};
75-
7668
return (
7769
<>
7870
{(loading || !_initially_loaded) && (
7971
<EditorSkeleton percent={_initial_load_progress * 100} />
8072
)}
81-
{mode == "fullscreen-preview" && <FullscreenPreviewMode />}
73+
8274
<DefaultEditorWorkspaceLayout
8375
backgroundColor={colors.color_editor_bg_on_dark}
8476
leftbar={<EditorSidebar />}
85-
display={mode == "fullscreen-preview" ? "none" : undefined}
8677
// rightbar={<Inspector />}
8778
>
8879
<WorkspaceContentPanelGridLayout>

editor/scaffolds/preview-full-screen/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useTargetContainer, useWindowSize } from "hooks";
1414
import Close from "@material-ui/icons/Close";
1515
import ClientOnly from "components/client-only";
1616

17-
export function FullScreenPreview() {
17+
export function FullScreenPreview({ onClose }: { onClose: () => void }) {
1818
const [state] = useEditorState();
1919
const [preview, setPreview] = useState<Result>();
2020
const windowsize = useWindowSize();
@@ -97,11 +97,7 @@ export function FullScreenPreview() {
9797
<StaticSizeInput value={windowsize.height ?? 0} suffix={"H"} />
9898
</AppbarControlSizeInputs>
9999
<AppbarActionsSegment>
100-
<CloseButton
101-
onClick={() => {
102-
// TODO: end preview mode
103-
}}
104-
/>
100+
<CloseButton onClick={onClose} />
105101
</AppbarActionsSegment>
106102
</FullscreenPreviewAppbar>
107103
<Body>

0 commit comments

Comments
 (0)