Skip to content

Commit 73aab24

Browse files
author
Ives van Hoorne
committed
Fix space issue in header
1 parent 917d040 commit 73aab24

File tree

2 files changed

+140
-25
lines changed

2 files changed

+140
-25
lines changed

src/app/components/sandbox/ModeIcons.js

Lines changed: 139 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
import React from 'react';
2-
import styled from 'styled-components';
2+
import styled, { keyframes } from 'styled-components';
33
import theme from 'common/theme';
44

55
import Tooltip from 'app/components/Tooltip';
66

7+
const animation = keyframes`
8+
0% { opacity: 0; transform: translateX(10px); }
9+
100% { opacity: 1; transform: translateX(0px); }
10+
`;
11+
12+
const reverseAnimation = keyframes`
13+
0% { opacity: 0; transform: translateX(-10px); }
14+
100% { opacity: 1; transform: translateX(0px); }
15+
`;
16+
17+
const delayAnimation = (delay: number = 0, reverse: boolean = true) =>
18+
`
19+
animation: ${reverse ? reverseAnimation : animation} 0.3s;
20+
animation-delay: ${delay}s;
21+
animation-fill-mode: forwards;
22+
opacity: 0;
23+
`;
24+
725
const Tooltips = styled.div`
826
display: flex;
927
align-items: center;
@@ -16,7 +34,6 @@ const Tooltips = styled.div`
1634
`;
1735

1836
const ViewIcon = styled.div`
19-
display: block;
2037
height: 1.75rem;
2138
transition: 0.3s ease all;
2239
position: relative;
@@ -33,7 +50,7 @@ const ViewIcon = styled.div`
3350
right: 0;
3451
bottom: 0;
3552
top: 0;
36-
background-color: rgba(0, 0, 0, 0.6);
53+
background-color: rgba(0, 0, 0, 0.3);
3754
opacity: ${props => (props.active ? 0 : 1)};
3855
border-radius: 2px;
3956
overflow: hidden;
@@ -43,9 +60,23 @@ const ViewIcon = styled.div`
4360
}
4461
`;
4562

63+
const Hover = styled.div`
64+
position: relative;
65+
display: flex;
66+
flex-direction: row;
67+
align-items: center;
68+
justify-content: center;
69+
z-index: 200;
70+
`;
71+
72+
const SubMode = styled.div`
73+
${props => delayAnimation(props.i * 0.05, props.i === 1)};
74+
`;
75+
4676
const Icon = styled.div`
4777
display: inline-block;
48-
width: ${props => props.size || (props.half ? 1.5 : 3)}rem;
78+
width: ${({ half }) =>
79+
half ? `calc(1.5rem - 1px)` : `3rem`}; /* 1px is for the middle border */
4980
border: 1px solid rgba(0, 0, 0, 0.1);
5081
height: 100%;
5182
`;
@@ -67,36 +98,119 @@ type Props = {
6798
noPreview: ?boolean,
6899
};
69100

70-
export default function AllIcons({
101+
const getCurrentMode = ({
71102
showEditor,
72103
showPreview,
73-
setEditorView,
74104
setMixedView,
105+
setEditorView,
75106
setPreviewView,
76-
noPreview,
77-
}: Props) {
78-
return (
79-
<Tooltips>
80-
<Tooltip title="Editor view">
81-
<ViewIcon onClick={setEditorView} active={showEditor && !showPreview}>
82-
<EditorIcon />
83-
</ViewIcon>
84-
</Tooltip>
85-
<Tooltip title="Split view">
86-
<ViewIcon onClick={setMixedView} active={showEditor && showPreview}>
87-
<EditorIcon half />
88-
<PreviewIcon half />
89-
</ViewIcon>
90-
</Tooltip>
91-
{!noPreview &&
107+
}: Props) => {
108+
const both = (
109+
<ViewIcon onClick={setMixedView} active={showEditor && showPreview}>
110+
<EditorIcon half />
111+
<PreviewIcon half />
112+
</ViewIcon>
113+
);
114+
115+
const editor = (
116+
<ViewIcon onClick={setEditorView} active={showEditor && !showPreview}>
117+
<EditorIcon />
118+
</ViewIcon>
119+
);
120+
121+
const preview = (
122+
<ViewIcon onClick={setPreviewView} active={!showEditor && showPreview}>
123+
<PreviewIcon />
124+
</ViewIcon>
125+
);
126+
127+
if (showEditor && !showPreview)
128+
return { currentMode: editor, otherModes: [both, preview] };
129+
if (!showEditor && showPreview)
130+
return { currentMode: preview, otherModes: [both, editor] };
131+
132+
return { currentMode: both, otherModes: [editor, preview] };
133+
};
134+
135+
export default class ModeIcons extends React.PureComponent<Props> {
136+
state = {
137+
hovering: false,
138+
};
139+
140+
onMouseEnter = () => {
141+
this.setState({
142+
hovering: true,
143+
});
144+
};
145+
146+
onMouseLeave = () => {
147+
this.setState({
148+
hovering: false,
149+
});
150+
};
151+
152+
render() {
153+
const {
154+
showEditor,
155+
showPreview,
156+
setEditorView,
157+
setMixedView,
158+
setPreviewView,
159+
dropdown,
160+
} = this.props;
161+
162+
if (dropdown) {
163+
const { currentMode, otherModes } = getCurrentMode(this.props);
164+
165+
return (
166+
<Tooltips>
167+
<Hover onMouseLeave={this.onMouseLeave}>
168+
{this.state.hovering &&
169+
<SubMode
170+
onClick={this.onMouseLeave}
171+
hovering={this.state.hovering}
172+
i={0}
173+
>
174+
{otherModes[0]}
175+
</SubMode>}
176+
<div onMouseEnter={this.onMouseEnter}>
177+
{currentMode}
178+
</div>
179+
{this.state.hovering &&
180+
<SubMode
181+
onClick={this.onMouseLeave}
182+
hovering={this.state.hovering}
183+
i={1}
184+
>
185+
{otherModes[1]}
186+
</SubMode>}
187+
</Hover>
188+
</Tooltips>
189+
);
190+
}
191+
192+
return (
193+
<Tooltips>
194+
<Tooltip title="Editor view">
195+
<ViewIcon onClick={setEditorView} active={showEditor && !showPreview}>
196+
<EditorIcon />
197+
</ViewIcon>
198+
</Tooltip>
199+
<Tooltip title="Split view">
200+
<ViewIcon onClick={setMixedView} active={showEditor && showPreview}>
201+
<EditorIcon half />
202+
<PreviewIcon half />
203+
</ViewIcon>
204+
</Tooltip>
92205
<Tooltip title="Preview view">
93206
<ViewIcon
94207
onClick={setPreviewView}
95208
active={!showEditor && showPreview}
96209
>
97210
<PreviewIcon />
98211
</ViewIcon>
99-
</Tooltip>}
100-
</Tooltips>
101-
);
212+
</Tooltip>
213+
</Tooltips>
214+
);
215+
}
102216
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export default class Header extends React.PureComponent<Props> {
170170
<Container>
171171
<ModeIcons
172172
small
173+
dropdown
173174
showEditor={sandbox.showEditor}
174175
showPreview={sandbox.showPreview}
175176
setMixedView={this.setMixedView}

0 commit comments

Comments
 (0)