Skip to content

Commit 5d4a254

Browse files
authored
Change/splitter (codesandbox#9)
* Ability to hide sidebar * Hide splitter if fullscreen
1 parent 855c2df commit 5d4a254

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

src/app/pages/Sandbox/Editor/Content/Header/index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Fork from 'react-icons/lib/go/repo-forked';
66
import Download from 'react-icons/lib/go/cloud-download';
77
import PlusIcon from 'react-icons/lib/go/plus';
88
import GithubIcon from 'react-icons/lib/go/mark-github';
9+
import ChevronLeft from 'react-icons/lib/go/chevron-left';
910

1011
import type { Sandbox, CurrentUser } from 'common/types';
1112
import sandboxActionCreators from 'app/store/entities/sandboxes/actions';
@@ -45,7 +46,28 @@ const Left = styled.div`
4546
height: 100%;
4647
`;
4748

49+
const Chevron = styled(ChevronLeft)`
50+
transition: 0.3s ease all;
51+
font-size: 1.5rem;
52+
display: flex;
53+
align-items: center;
54+
justify-content: center;
55+
height: 100%;
56+
margin-left: 0.5rem;
57+
z-index: 20;
58+
59+
cursor: pointer;
60+
&:hover {
61+
transform: rotateZ(${props => (props.workspaceHidden ? '135deg' : '45deg')});
62+
color: white;
63+
}
64+
65+
transform: rotateZ(${props => (props.workspaceHidden ? '180deg' : '0')});
66+
`;
67+
4868
type Props = {
69+
toggleWorkspace: () => void,
70+
workspaceHidden: boolean,
4971
sandbox: Sandbox,
5072
sandboxActions: typeof sandboxActionCreators,
5173
userActions: typeof userActionCreators,
@@ -92,11 +114,21 @@ export default class Header extends React.PureComponent {
92114
};
93115

94116
render() {
95-
const { sandbox, userActions, user } = this.props;
117+
const {
118+
sandbox,
119+
userActions,
120+
user,
121+
toggleWorkspace,
122+
workspaceHidden,
123+
} = this.props;
96124
const canSave = sandbox.modules.some(m => m.isNotSynced);
97125
return (
98126
<Container>
99127
<Left>
128+
<Chevron
129+
onClick={toggleWorkspace}
130+
workspaceHidden={workspaceHidden}
131+
/>
100132
<Action onClick={this.forkSandbox} title="Fork" Icon={Fork} />
101133
<Action
102134
onClick={canSave && this.massUpdateModules}

src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Preview from 'app/components/sandbox/Preview';
2323
import Header from './Header';
2424

2525
type Props = {
26+
workspaceHidden: boolean,
27+
toggleWorkspace: () => void,
2628
sandbox: Sandbox,
2729
user: CurrentUser,
2830
preferences: Preferences,
@@ -98,6 +100,8 @@ class EditorPreview extends React.PureComponent {
98100
preferences,
99101
userActions,
100102
user,
103+
workspaceHidden,
104+
toggleWorkspace,
101105
} = this.props;
102106

103107
const { modules, directories } = sandbox;
@@ -157,6 +161,8 @@ class EditorPreview extends React.PureComponent {
157161
sandboxActions={sandboxActions}
158162
userActions={userActions}
159163
user={user}
164+
workspaceHidden={workspaceHidden}
165+
toggleWorkspace={toggleWorkspace}
160166
/>
161167
<SplitPane
162168
onDragStarted={this.startResizing}
@@ -165,6 +171,12 @@ class EditorPreview extends React.PureComponent {
165171
defaultSize="50%"
166172
minSize={360}
167173
paneStyle={{ height: '100%' }}
174+
resizerStyle={{
175+
visibility: (!sandbox.showPreview && sandbox.showEditor) ||
176+
(sandbox.showPreview && !sandbox.showEditor)
177+
? 'hidden'
178+
: 'visible',
179+
}}
168180
pane1Style={{
169181
display: sandbox.showEditor ? 'block' : 'none',
170182
minWidth: !sandbox.showPreview && sandbox.showEditor

src/app/pages/Sandbox/Editor/index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22
import React from 'react';
33
import SplitPane from 'react-split-pane';
4-
import type { Sandbox } from 'app/store/entities/sandboxes/entity';
4+
import type { Sandbox } from 'common/types';
55

66
import Workspace from './Workspace';
77

@@ -14,25 +14,41 @@ type Props = {
1414

1515
export default class ContentSplit extends React.PureComponent {
1616
props: Props;
17-
state = { resizing: false };
17+
state = {
18+
resizing: false,
19+
workspaceHidden: false,
20+
};
1821

1922
startResizing = () => this.setState({ resizing: true });
2023
stopResizing = () => this.setState({ resizing: false });
2124

25+
toggleWorkspace = () =>
26+
this.setState({ workspaceHidden: !this.state.workspaceHidden });
27+
2228
render() {
2329
const { sandbox, match } = this.props;
24-
const { resizing } = this.state;
30+
const { resizing, workspaceHidden } = this.state;
2531
return (
2632
<SplitPane
2733
split="vertical"
28-
minSize={100}
2934
defaultSize={16 * 16}
3035
style={{ top: 0 }}
3136
onDragStarted={this.startResizing}
3237
onDragFinished={this.stopResizing}
38+
resizerStyle={{ visibility: workspaceHidden ? 'hidden' : 'visible' }}
39+
pane1Style={{
40+
visiblity: workspaceHidden ? 'hidden' : 'visible',
41+
maxWidth: workspaceHidden ? 0 : 'inherit',
42+
}}
3343
>
34-
<Workspace sandbox={sandbox} />
35-
<Content sandbox={sandbox} resizing={resizing} match={match} />
44+
{!workspaceHidden && <Workspace sandbox={sandbox} />}
45+
<Content
46+
workspaceHidden={workspaceHidden}
47+
toggleWorkspace={this.toggleWorkspace}
48+
sandbox={sandbox}
49+
resizing={resizing}
50+
match={match}
51+
/>
3652
</SplitPane>
3753
);
3854
}

src/app/split-pane.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
-webkit-box-sizing: border-box;
44
box-sizing: border-box;
55
background: #000;
6-
opacity: .2;
7-
z-index: 1;
6+
opacity: .4;
7+
z-index: 50;
88
-moz-background-clip: padding;
99
-webkit-background-clip: padding;
1010
background-clip: padding-box;
1111
}
1212

1313
.Resizer:hover {
14-
-webkit-transition: all 2s ease;
15-
transition: all 2s ease;
14+
-webkit-transition: all 0.3s ease;
15+
transition: all 0.3s ease;
1616
}
1717

1818
.Resizer.horizontal {
1919
height: 11px;
2020
margin: -5px 0;
21-
border-top: 5px solid rgba(255, 255, 255, 0);
22-
border-bottom: 5px solid rgba(255, 255, 255, 0);
21+
border-top: 5px solid rgba(0, 0, 0, 0);
22+
border-bottom: 5px solid rgba(0, 0, 0, 0);
2323
cursor: row-resize;
2424
width: 100%;
2525
}
@@ -32,8 +32,8 @@
3232
.Resizer.vertical {
3333
width: 11px;
3434
margin: 0 -5px;
35-
border-left: 5px solid rgba(255, 255, 255, 0);
36-
border-right: 5px solid rgba(255, 255, 255, 0);
35+
border-left: 5px solid rgba(0, 0, 0, 0);
36+
border-right: 5px solid rgba(0, 0, 0, 0);
3737
cursor: col-resize;
3838
}
3939

0 commit comments

Comments
 (0)