Skip to content

Commit ffaa7c3

Browse files
Tushar SonawaneCompuIves
authored andcommitted
update new sandbox menu into a modal (codesandbox#201)
* update new sandbox menu into a modal * fix lint issues * Add background hover effect * remove unused files
1 parent b27b4ac commit ffaa7c3

File tree

11 files changed

+315
-147
lines changed

11 files changed

+315
-147
lines changed

src/app/components/MenuItem.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/app/components/logos/Preact.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
3+
export default ({
4+
width = 35,
5+
height = 35,
6+
className,
7+
}: {
8+
width: number,
9+
height: number,
10+
className: ?string,
11+
}) => (
12+
<svg
13+
className={className}
14+
width={`${width}px`}
15+
height={`${height}px`}
16+
viewBox="0 0 256 296"
17+
>
18+
<g>
19+
<polygon
20+
fill="#673AB8"
21+
points="128 0 256 73.8999491 256 221.699847 128 295.599796 0 221.699847 0 73.8999491"
22+
/>
23+
<path
24+
d="M34.8647584,220.478469 C51.8814262,242.25881 105.959701,225.662965 157.014868,185.774297 C208.070035,145.885628 237.255632,97.428608 220.238964,75.6482664 C203.222296,53.8679249 149.144022,70.4637701 98.0888543,110.352439 C47.0336869,150.241107 17.8480906,198.698127 34.8647584,220.478469 Z M42.1343351,214.798853 C36.4908625,207.575537 38.9565723,193.395881 49.7081913,175.544904 C61.0297348,156.747677 80.2490923,135.997367 103.76847,117.622015 C127.287848,99.2466634 152.071368,85.6181573 173.049166,79.1803727 C192.970945,73.066665 207.325915,74.1045667 212.969387,81.3278822 C218.61286,88.5511977 216.14715,102.730854 205.395531,120.581832 C194.073987,139.379058 174.85463,160.129368 151.335252,178.50472 C127.815874,196.880072 103.032354,210.508578 82.054556,216.946362 C62.1327769,223.06007 47.7778077,222.022168 42.1343351,214.798853 Z"
25+
fill="#FFFFFF"
26+
/>
27+
<path
28+
d="M220.238964,220.478469 C237.255632,198.698127 208.070035,150.241107 157.014868,110.352439 C105.959701,70.4637701 51.8814262,53.8679249 34.8647584,75.6482664 C17.8480906,97.428608 47.0336869,145.885628 98.0888543,185.774297 C149.144022,225.662965 203.222296,242.25881 220.238964,220.478469 Z M212.969387,214.798853 C207.325915,222.022168 192.970945,223.06007 173.049166,216.946362 C152.071368,210.508578 127.287848,196.880072 103.76847,178.50472 C80.2490923,160.129368 61.0297348,139.379058 49.7081913,120.581832 C38.9565723,102.730854 36.4908625,88.5511977 42.1343351,81.3278822 C47.7778077,74.1045667 62.1327769,73.066665 82.054556,79.1803727 C103.032354,85.6181573 127.815874,99.2466634 151.335252,117.622015 C174.85463,135.997367 194.073987,156.747677 205.395531,175.544904 C216.14715,193.395881 218.61286,207.575537 212.969387,214.798853 Z"
29+
fill="#FFFFFF"
30+
/>
31+
<path
32+
d="M127.551861,167.666971 C138.378632,167.666971 147.155465,158.890139 147.155465,148.063368 C147.155465,137.236596 138.378632,128.459764 127.551861,128.459764 C116.72509,128.459764 107.948257,137.236596 107.948257,148.063368 C107.948257,158.890139 116.72509,167.666971 127.551861,167.666971 L127.551861,167.666971 Z"
33+
fill="#FFFFFF"
34+
/>
35+
</g>
36+
</svg>
37+
);

src/app/components/logos/React.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/components/logos/Svelte.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
export default ({
4+
width = 35,
5+
height = 35,
6+
className,
7+
}: {
8+
width: number,
9+
height: number,
10+
className: ?string,
11+
}) => (
12+
<svg
13+
className={className}
14+
width={`${width}px`}
15+
height={`${height}px`}
16+
viewBox="0 0 200 200"
17+
>
18+
<path
19+
d="M0 100v100h200V0H0v100zm140.9-71.6c.7.9 1.1 4.2.9 8.8l-.3 7.3-27 .5c-23.2.5-27.5.8-30.6 2.3-6.4 3.1-8.3 6-8.7 13.1-.5 7.5 1.4 12.4 6.2 16.1 1.8 1.3 13.5 7 26.1 12.6 24.7 11 29.6 13.8 34.5 19.6 6.8 8.3 9.7 30.1 5.6 42.3-2.7 7.8-10.1 14.9-18.6 18-6.2 2.2-8.1 2.3-39.1 2.8-38 .5-35.9 1-35.9-9.2 0-3.9.5-6.8 1.3-7.4.8-.7 11.9-1.2 30.2-1.4 32.3-.4 35.3-.9 39.8-7.2 1.9-2.7 2.2-4.4 2.2-12.1-.1-15-2.7-17.8-24.9-27-33.6-14-41.2-18.8-46.1-29.1-4.5-9.4-4.4-24.5.2-34.2 2.3-4.8 8.3-10.7 13-12.8 7.8-3.5 15.3-4.2 42.9-4.3 22.2-.1 27.4.2 28.3 1.3z"
20+
fill="#A82022"
21+
/>
22+
</svg>
23+
);

src/app/components/logos/Vue.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
3+
export default ({
4+
width = 35,
5+
height = 35,
6+
className,
7+
}: {
8+
width: number,
9+
height: number,
10+
className: ?string,
11+
}) => (
12+
<svg
13+
className={className}
14+
width={`${width}px`}
15+
height={`${height}px`}
16+
viewBox="0 0 256 221"
17+
>
18+
<g>
19+
<path
20+
d="M204.8,0 L256,0 L128,220.8 L0,0 L50.56,0 L97.92,0 L128,51.2 L157.44,0 L204.8,0 Z"
21+
fill="#41B883"
22+
/>
23+
<path
24+
d="M0,0 L128,220.8 L256,0 L204.8,0 L128,132.48 L50.56,0 L0,0 Z"
25+
fill="#41B883"
26+
/>
27+
<path
28+
d="M50.56,0 L128,133.12 L204.8,0 L157.44,0 L128,51.2 L97.92,0 L50.56,0 Z"
29+
fill="#35495E"
30+
/>
31+
</g>
32+
</svg>
33+
);

src/app/containers/Navigation/index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// @flow
22
import * as React from 'react';
33
import styled from 'styled-components';
4-
import { connect } from 'react-redux';
54
import { Link } from 'react-router-dom';
5+
import { connect } from 'react-redux';
6+
import { bindActionCreators } from 'redux';
67

78
import SignInButton from 'app/containers/SignInButton';
9+
import NewSandbox from 'app/containers/modals/NewSandbox';
810

11+
import PlusIcon from 'react-icons/lib/go/plus';
912
import Logo from 'app/components/Logo';
1013
import Row from 'app/components/flex/Row';
1114
import Tooltip from 'app/components/Tooltip';
1215
import HeaderSearchBar from 'app/components/HeaderSearchBar';
1316

1417
import { jwtSelector, isPatronSelector } from 'app/store/user/selectors';
18+
import modalActionCreators from 'app/store/modal/actions';
1519
import { patronUrl } from 'app/utils/url-generator';
1620
// $FlowIssue
1721
import PatronBadge from '-!svg-react-loader!app/utils/badges/svg/patron-4.svg'; // eslint-disable-line import/no-webpack-loader-syntax
1822

19-
import NewSandboxAction from '../../pages/Sandbox/Editor/Content/Header/NewSandboxAction';
20-
2123
import UserMenu from '../UserMenu';
2224

2325
const LogoWithBorder = styled(Logo)`padding-right: 1rem;`;
@@ -48,23 +50,35 @@ const Action = styled.div`
4850
margin: 0 1rem;
4951
cursor: pointer;
5052
color: white;
53+
opacity: 0.8;
5154
5255
&:hover {
53-
color: white;
56+
opacity: 1;
5457
}
5558
`;
5659

5760
type Props = {
5861
title: string,
5962
hasLogin: boolean,
6063
isPatron: boolean,
64+
modalActions: typeof modalActionCreators,
6165
};
6266

6367
const mapStateToProps = state => ({
6468
hasLogin: !!jwtSelector(state),
6569
isPatron: isPatronSelector(state),
6670
});
71+
const mapDispatchToProps = dispatch => ({
72+
modalActions: bindActionCreators(modalActionCreators, dispatch),
73+
});
6774
class Navigation extends React.PureComponent<Props> {
75+
openNewSandbox = () => {
76+
this.props.modalActions.openModal({
77+
width: 900,
78+
Body: <NewSandbox />,
79+
});
80+
};
81+
6882
render() {
6983
const { title, hasLogin, isPatron } = this.props;
7084

@@ -91,7 +105,11 @@ class Navigation extends React.PureComponent<Props> {
91105
</Tooltip>
92106
</Action>
93107
)}
94-
<NewSandboxAction />
108+
<Action onClick={this.openNewSandbox}>
109+
<Tooltip position="bottom" title="New Sandbox">
110+
<PlusIcon height={35} />
111+
</Tooltip>
112+
</Action>
95113
</Actions>
96114
{hasLogin ? <UserMenu /> : <SignInButton />}
97115
</Row>
@@ -100,4 +118,4 @@ class Navigation extends React.PureComponent<Props> {
100118
}
101119
}
102120

103-
export default connect(mapStateToProps)(Navigation);
121+
export default connect(mapStateToProps, mapDispatchToProps)(Navigation);
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
import styled from 'styled-components';
4+
import { connect } from 'react-redux';
5+
import { bindActionCreators } from 'redux';
6+
7+
import GithubIcon from 'react-icons/lib/go/mark-github';
8+
import TerminalIcon from 'react-icons/lib/go/terminal';
9+
10+
import modalActionCreators from 'app/store/modal/actions';
11+
import {
12+
newSandboxUrl,
13+
newReactTypeScriptSandboxUrl,
14+
newPreactSandboxUrl,
15+
newVueSandboxUrl,
16+
newSvelteSandboxUrl,
17+
importFromGitHubUrl,
18+
uploadFromCliUrl,
19+
} from 'app/utils/url-generator';
20+
21+
import ReactIcon from '../../components/logos/React';
22+
import PreactIcon from '../../components/logos/Preact';
23+
import VueIcon from '../../components/logos/Vue';
24+
import SvelteIcon from '../../components/logos/Svelte';
25+
26+
import Row from '../../components/flex/Row';
27+
28+
const Container = styled.div`
29+
display: flex;
30+
flex-direction: column;
31+
background-color: ${props => props.theme.background};
32+
`;
33+
34+
const RowContainer = styled(Row)`
35+
justify-content: center;
36+
color: rgba(255, 255, 255, 0.8);
37+
padding-top: 1.5rem;
38+
&:last-of-type {
39+
padding-bottom: 1.5rem;
40+
}
41+
`;
42+
43+
const LogoContainer = styled.div`
44+
display: flex;
45+
flex-direction: column;
46+
align-items: center;
47+
cursor: pointer;
48+
transition: 0.3s ease all;
49+
opacity: 0.8;
50+
51+
padding: 1.5rem 0;
52+
53+
&:hover {
54+
opacity: 1;
55+
background-color: rgba(0, 0, 0, 0.2);
56+
}
57+
`;
58+
59+
const Text = styled.div`margin-top: 1rem;`;
60+
61+
const LogoLink = styled(Link)`
62+
text-decoration: none;
63+
color: rgba(255, 255, 255, 0.8);
64+
width: 140px;
65+
margin: 0 1rem;
66+
`;
67+
type LogoProps = {
68+
Icon: any,
69+
width: number,
70+
height: number,
71+
text: string,
72+
href: string,
73+
onClick: () => {},
74+
};
75+
76+
const Logo = ({ Icon, width, height, text, href, onClick }: LogoProps) => (
77+
<LogoLink to={href} onClick={onClick}>
78+
<LogoContainer>
79+
<Icon width={width} height={height} />
80+
<Text>{text}</Text>
81+
</LogoContainer>
82+
</LogoLink>
83+
);
84+
85+
const mapDispatchToProps = dispatch => ({
86+
modalActions: bindActionCreators(modalActionCreators, dispatch),
87+
});
88+
const NewSandbox = ({
89+
modalActions,
90+
}: {
91+
modalActions: typeof modalActionCreators,
92+
}) => (
93+
<Container>
94+
<RowContainer>
95+
<Logo
96+
Icon={ReactIcon}
97+
width={50}
98+
height={50}
99+
text="React"
100+
href={newSandboxUrl()}
101+
onClick={modalActions.closeModal}
102+
/>
103+
<Logo
104+
Icon={ReactIcon}
105+
width={50}
106+
height={50}
107+
text="React TypeScript"
108+
href={newReactTypeScriptSandboxUrl()}
109+
onClick={modalActions.closeModal}
110+
/>
111+
<Logo
112+
Icon={PreactIcon}
113+
width={50}
114+
height={50}
115+
text="Preact"
116+
href={newPreactSandboxUrl()}
117+
onClick={modalActions.closeModal}
118+
/>
119+
<Logo
120+
Icon={VueIcon}
121+
width={50}
122+
height={50}
123+
text="Vue"
124+
href={newVueSandboxUrl()}
125+
onClick={modalActions.closeModal}
126+
/>
127+
<Logo
128+
Icon={SvelteIcon}
129+
width={50}
130+
height={50}
131+
text="Svelte"
132+
href={newSvelteSandboxUrl()}
133+
onClick={modalActions.closeModal}
134+
/>
135+
</RowContainer>
136+
<RowContainer>
137+
<Logo
138+
Icon={GithubIcon}
139+
width={50}
140+
height={50}
141+
text="Import from Github"
142+
href={importFromGitHubUrl()}
143+
onClick={modalActions.closeModal}
144+
/>
145+
<Logo
146+
Icon={TerminalIcon}
147+
width={50}
148+
height={50}
149+
text="Upload from CLI"
150+
href={uploadFromCliUrl()}
151+
onClick={modalActions.closeModal}
152+
/>
153+
</RowContainer>
154+
</Container>
155+
);
156+
157+
export default connect(null, mapDispatchToProps)(NewSandbox);

0 commit comments

Comments
 (0)