Skip to content

Commit 0fce644

Browse files
committed
Introduce vertical mode to embeds
1 parent e39c793 commit 0fce644

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

packages/app/src/embed/components/Content/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { MenuIcon } from '../legacy/Header/elements';
3838
import SplitPane from '../SplitPane';
3939
import { CodeEditor } from './CodeEditor';
4040
import { Container, MenuInTabs, Tabs } from './elements';
41+
import { isSmallScreen } from '../../util/mobile';
4142

4243
type Props = {
4344
showEditor: boolean;
@@ -407,10 +408,9 @@ export default class Content extends React.PureComponent<Props, State> {
407408
sidebarOpen,
408409
toggleSidebar,
409410
toggleLike,
410-
editorSize,
411411
} = this.props;
412412

413-
const { isInProjectView } = this.state;
413+
const { isInProjectView, editorSize } = this.state;
414414

415415
const mainModule = isInProjectView
416416
? findMainModule(sandbox)
@@ -489,17 +489,13 @@ export default class Content extends React.PureComponent<Props, State> {
489489
actions: [],
490490
};
491491

492-
// TODO: we use verticalMode as a very very bad proxy
493-
// for identifying mobile mode
494-
// mobile isn't even vertical anymore!
495-
// we should really rename it
496492
return (
497493
<Container style={{ flexDirection: verticalMode ? 'column' : 'row' }}>
498494
<SplitPane
499495
sandbox={sandbox}
500496
showEditor={showEditor}
501497
showPreview={showPreview}
502-
isSmallScreen={verticalMode}
498+
isSmallScreen={isSmallScreen()}
503499
sidebarOpen={sidebarOpen}
504500
showNavigationActions={hideNavigation}
505501
refresh={this.refresh}
@@ -509,6 +505,7 @@ export default class Content extends React.PureComponent<Props, State> {
509505
setEditorSize={this.setEditorSize}
510506
hideDevTools={hideDevTools}
511507
setDragging={this.setDragging}
508+
verticalMode={verticalMode}
512509
>
513510
<>
514511
<Tabs>
@@ -577,7 +574,9 @@ export default class Content extends React.PureComponent<Props, State> {
577574
onChange={this.setCode}
578575
onModuleChange={this.setCurrentModule}
579576
highlightedLines={this.props.highlightedLines}
580-
width={this.state.editorSize}
577+
{...(verticalMode
578+
? { height: editorSize }
579+
: { width: editorSize })}
581580
/>
582581
</div>
583582
</>

packages/app/src/embed/components/SplitPane/elements.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export const KNOB_WIDTH = 4;
88
*/
99
export const RESIZER_GRAB_EXTRA_WIDTH = 4;
1010

11+
const getKnobSizeKey = props => (props.verticalMode ? 'height' : 'width');
12+
const getKnobHeightKey = props => (props.verticalMode ? 'width' : 'height');
13+
const getContainerSizeKey = props => (props.verticalMode ? 'width' : 'height');
14+
const getKnobOffsetKey = props => (props.verticalMode ? 'left' : 'top');
15+
const getKnobMarginKey = props =>
16+
props.verticalMode ? 'margin-top' : 'margin-left';
17+
1118
export const Container = styled.div`
1219
width: 100%;
1320
height: 100%;
@@ -22,10 +29,10 @@ export const Container = styled.div`
2229
transform: translateZ(0);
2330
2431
background-color: ${props => props.theme.colors.separator.background};
25-
width: ${RESIZER_WIDTH}px;
32+
${getKnobSizeKey}: ${RESIZER_WIDTH}px;
2633
display: block;
27-
height: 100%;
28-
cursor: ew-resize;
34+
${getContainerSizeKey}: 100%;
35+
cursor: ${props => (props.verticalMode ? 'ns-resize' : 'ew-resize')};
2936
z-index: 50;
3037
}
3138
@@ -36,10 +43,10 @@ export const Container = styled.div`
3643
border-radius: 50px;
3744
position: absolute;
3845
39-
width: ${KNOB_WIDTH}px;
40-
height: 41px;
41-
top: calc(50% - 20px);
42-
margin-left: ${Math.floor(RESIZER_WIDTH / 2 - KNOB_WIDTH / 2)}px;
46+
${getKnobSizeKey}: ${KNOB_WIDTH}px;
47+
${getKnobHeightKey}: 41px;
48+
${getKnobOffsetKey}: calc(50% - 20px);
49+
${getKnobMarginKey}: ${Math.floor(RESIZER_WIDTH / 2 - KNOB_WIDTH / 2)}px;
4350
opacity: 1;
4451
}
4552
@@ -48,13 +55,18 @@ export const Container = styled.div`
4855
position: absolute;
4956
top: 0;
5057
bottom: 0;
51-
margin-left: -${RESIZER_GRAB_EXTRA_WIDTH}px;
52-
width: ${RESIZER_WIDTH + RESIZER_GRAB_EXTRA_WIDTH * 2}px;
58+
left: 0;
59+
right: 0;
60+
${getKnobMarginKey}: -${RESIZER_GRAB_EXTRA_WIDTH}px;
61+
${getKnobSizeKey}: ${RESIZER_WIDTH + RESIZER_GRAB_EXTRA_WIDTH * 2}px;
5362
z-index: 50;
5463
}
5564
5665
.Pane {
57-
transition: ${props => (props.isDragging ? null : 'width 200ms ease')};
66+
transition: ${props =>
67+
props.isDragging
68+
? null
69+
: `${props.verticalMode ? 'height' : 'width'} 200ms ease`};
5870
overflow: hidden;
5971
}
6072
`;
@@ -63,4 +75,5 @@ export const PaneContainer = styled.div`
6375
display: flex;
6476
flex-direction: column;
6577
height: 100%;
78+
width: 100%;
6679
`;

packages/app/src/embed/components/SplitPane/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function SplitView({
1818
initialEditorSize = 50, // in percent
1919
hideDevTools,
2020
setEditorSize,
21+
verticalMode,
2122
setDragging: setDraggingProp,
2223
...props
2324
}) {
@@ -29,12 +30,14 @@ export default function SplitView({
2930
5. introduce the resizer element with animation
3031
*/
3132

32-
const windowWidth = document.body.clientWidth;
33+
const windowSize = verticalMode
34+
? document.body.clientHeight
35+
: document.body.clientWidth;
3336
// TODO: pick this from the sidebar or ref instead of hardcoding
34-
const sidebarWidth = 250;
37+
const sidebarWidth = verticalMode ? 0 : 250;
3538

3639
const maxSize =
37-
(sidebarOpen ? windowWidth - sidebarWidth : windowWidth) - RESIZER_WIDTH;
40+
(sidebarOpen ? windowSize - sidebarWidth : windowSize) - RESIZER_WIDTH;
3841

3942
// #1. set initial size based on props
4043
let initialSize = null;
@@ -131,6 +134,7 @@ export default function SplitView({
131134
size={size}
132135
maxSize={maxSize}
133136
fullSize={size === maxSize}
137+
verticalMode={verticalMode}
134138
>
135139
<GlobalActions
136140
sandbox={sandbox}
@@ -143,7 +147,7 @@ export default function SplitView({
143147
smallTouchScreen={smallTouchScreen}
144148
/>
145149
<SplitPane
146-
split="vertical"
150+
split={verticalMode ? 'horizontal' : 'vertical'}
147151
onDragStarted={onDragStarted}
148152
onDragFinished={onDragFinished}
149153
minSize="0%"
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const isTouch = !matchMedia('(pointer:fine)').matches;
22

3-
export function isSmallMobileScreen() {
3+
export function isSmallScreen() {
44
if (typeof screen === 'undefined') {
55
return false;
66
}
77

8-
return screen.width < 800 && isTouch;
8+
return screen.width < 800;
9+
}
10+
11+
export function isSmallMobileScreen() {
12+
return isSmallScreen() && isTouch;
913
}

0 commit comments

Comments
 (0)