Skip to content

Commit 820cf05

Browse files
authored
Fix/ui improvements (codesandbox#41)
* Basic improvements to UI * Change location of UI elements
1 parent 2f55f48 commit 820cf05

File tree

12 files changed

+298
-132
lines changed

12 files changed

+298
-132
lines changed

src/app/components/sandbox/CodeEditor/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ export default class CodeEditor extends React.PureComponent {
153153
} else if (kind[1] === 'html') {
154154
await System.import('codemirror/mode/htmlmixed/htmlmixed');
155155
return 'htmlmixed';
156+
} else if (kind[1] === 'md') {
157+
await System.import('codemirror/mode/markdown/markdown');
158+
return 'markdown';
156159
}
157160
}
158161

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import styled, { css } from 'styled-components';
3+
4+
import GithubIcon from 'react-icons/lib/go/mark-github';
5+
6+
const BorderRadius = styled.div`
7+
transition: 0.3s ease all;
8+
border-radius: 4px;
9+
border: 1px solid #4f5459;
10+
font-size: .75rem;
11+
margin-right: 1rem;
12+
13+
${props =>
14+
props.hasUrl &&
15+
css`
16+
&:hover {
17+
background-color: #4f5459;
18+
}
19+
`};
20+
`;
21+
22+
const Text = styled.span`
23+
display: inline-block;
24+
font-weight: .875rem;
25+
26+
color: rgba(255, 255, 255, 0.6);
27+
border-radius: 4px;
28+
padding: 3px 5px;
29+
`;
30+
31+
const Icon = styled.span`
32+
display: inline-block;
33+
padding: 3px 5px;
34+
background-color: #4f5459;
35+
border-radius: 2px;
36+
color: ${props => props.theme.background};
37+
`;
38+
39+
const StyledA = styled.a`text-decoration: none;`;
40+
41+
type Props = {
42+
username: string,
43+
repo: string,
44+
url: ?string,
45+
};
46+
47+
const DivOrA = ({ href, ...props }) =>
48+
href
49+
? <StyledA
50+
target="_blank"
51+
rel="noopener noreferrer"
52+
href={href}
53+
{...props}
54+
/>
55+
: <div {...props} />;
56+
57+
export default ({ username, repo, url }: Props) =>
58+
<DivOrA href={url}>
59+
<BorderRadius hasUrl={!!url}>
60+
<Icon>
61+
<GithubIcon />
62+
</Icon>
63+
<Text>
64+
{username}/{repo}
65+
</Text>
66+
</BorderRadius>
67+
</DivOrA>;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
const CenteredText = styled.div`
5+
display: inline-flex;
6+
justify-content: center;
7+
align-items: center;
8+
flex-direction: row;
9+
10+
svg {
11+
opacity: 0.8;
12+
}
13+
`;
14+
15+
type Props = {
16+
Icon: React.CElement,
17+
count: number,
18+
};
19+
20+
export default ({ Icon, count }: Props) =>
21+
<CenteredText>
22+
{Icon}
23+
<span
24+
style={{
25+
marginLeft: '0.5em',
26+
fontWeight: 300,
27+
}}
28+
>
29+
{count.toLocaleString()}
30+
</span>
31+
</CenteredText>;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
import EyeIcon from 'react-icons/lib/fa/eye';
5+
import ForkIcon from 'react-icons/lib/go/repo-forked';
6+
7+
import Stat from './Stat';
8+
import LikeHeart from '../../../containers/LikeHeart/index';
9+
10+
const Stats = styled.div`
11+
display: flex;
12+
justify-content: center;
13+
align-items: center;
14+
flex-direction: row;
15+
justify-content: space-around;
16+
`;
17+
18+
type Props = {
19+
viewCount: number,
20+
forkCount: number,
21+
likeCount: number,
22+
sandboxId: string,
23+
};
24+
25+
export default ({ viewCount, forkCount, likeCount, sandboxId }: Props) =>
26+
<Stats>
27+
<Stat Icon={<EyeIcon />} count={viewCount} />
28+
<Stat
29+
Icon={<LikeHeart colorless sandboxId={sandboxId} />}
30+
count={likeCount}
31+
/>
32+
<Stat Icon={<ForkIcon />} count={forkCount} />
33+
</Stats>;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
const CenteredText = styled.div`
5+
display: inline-flex;
6+
justify-content: center;
7+
align-items: center;
8+
flex-direction: row;
9+
`;
10+
11+
const AuthorName = styled.span`
12+
text-transform: uppercase;
13+
margin: 0 0.5em;
14+
margin-right: 1em;
15+
font-weight: 400;
16+
`;
17+
18+
const Image = styled.img`
19+
width: 1.75em;
20+
height: 1.75em;
21+
border-radius: 4px;
22+
`;
23+
24+
type Props = {
25+
avatarUrl: string,
26+
username: string,
27+
};
28+
29+
export default ({ avatarUrl, username }: Props) =>
30+
<CenteredText>
31+
<Image src={avatarUrl} alt={username} />
32+
<AuthorName>
33+
{username}
34+
</AuthorName>
35+
</CenteredText>;

src/app/containers/LikeHeart/LikeHeart.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import styled from 'styled-components';
2+
import styled, { css } from 'styled-components';
33
import HeartIcon from 'react-icons/lib/fa/heart-o';
44
import FullHeartIcon from 'react-icons/lib/fa/heart';
55

@@ -18,16 +18,20 @@ const Container = styled.div`
1818
display: inline-block;
1919
transition: 0.3s ease all;
2020
21-
cursor: pointer;
22-
2321
transform: scale(1);
2422
23+
${props =>
24+
props.loggedIn &&
25+
css`
26+
cursor: pointer;
2527
&:hover {
2628
transform: scale(1.1);
27-
color: #E01F4E;
28-
}
29+
}`};
2930
`;
3031

32+
const MaybeTooltip = ({ loggedIn, ...props }) =>
33+
loggedIn ? <Tooltip {...props} /> : <div {...props} />;
34+
3135
export default class LikeHeart extends React.PureComponent {
3236
props: Props;
3337

@@ -40,20 +44,21 @@ export default class LikeHeart extends React.PureComponent {
4044
};
4145

4246
render() {
43-
const { isLiked, loggedIn, className } = this.props;
44-
45-
if (!loggedIn) return null;
47+
const { isLiked, colorless, loggedIn, className } = this.props;
4648

4749
return (
48-
<Container className={className}>
49-
<Tooltip title={isLiked ? 'Undo like' : 'Like'}>
50+
<Container loggedIn={loggedIn} className={className}>
51+
<MaybeTooltip
52+
loggedIn={loggedIn}
53+
title={isLiked ? 'Undo like' : 'Like'}
54+
>
5055
{isLiked
5156
? <FullHeartIcon
52-
style={{ color: '#E01F4E' }}
53-
onClick={this.unlikeSandbox}
57+
style={!colorless && { color: '#E01F4E' }}
58+
onClick={loggedIn && this.unlikeSandbox}
5459
/>
55-
: <HeartIcon onClick={this.likeSandbox} />}
56-
</Tooltip>
60+
: <HeartIcon onClick={loggedIn && this.likeSandbox} />}
61+
</MaybeTooltip>
5762
</Container>
5863
);
5964
}

src/app/pages/Profile/Header/UserInfo/Stats.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ type Props = {
2525
forkCount: number,
2626
};
2727

28-
export default ({ viewCount, likeCount, forkCount }: Props) => (
28+
export default ({ viewCount, likeCount, forkCount }: Props) =>
2929
<Container>
3030
<Stat name="Likes" count={likeCount} />
3131
<Stat name="Views" count={viewCount} />
3232
<Stat name="Forked" count={forkCount} />
33-
</Container>
34-
);
33+
</Container>;

src/app/pages/Sandbox/Editor/Workspace/Project/Statistics/StatCount.js

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

src/app/pages/Sandbox/Editor/Workspace/Project/Statistics/index.js

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

0 commit comments

Comments
 (0)