Skip to content

Commit 61e3dce

Browse files
donavonCompuIves
authored andcommitted
Package Refresh Icon (codesandbox#24)
* Add @donavon as a contributor * Add a common Icon component * Use Icon for FIles * Use Icon for External Resources * Pass onRefresh to VersionEntry * Add Refrech Icon to VersionEntry * Inject theme in ExternalResource.test * Update ExternalResource.test snaps
1 parent e91691e commit 61e3dce

File tree

9 files changed

+127
-106
lines changed

9 files changed

+127
-106
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
"test",
2626
"tool"
2727
]
28+
},
29+
{
30+
"login": "donavon",
31+
"name": "Donavon West",
32+
"avatar_url": "https://avatars0.githubusercontent.com/u/887639?v=3",
33+
"profile": "http://donavon.com",
34+
"contributions": [
35+
"code"
36+
]
2837
}
2938
]
3039
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [CodeSandbox](https://codesandbox.io)
2-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
2+
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
33
[![Build Status](https://travis-ci.org/CompuIves/codesandbox-client.svg?branch=master)](https://travis-ci.org/CompuIves/codesandbox-client)
44

55
An online code editor with a focus on React.
@@ -36,8 +36,8 @@ yarn start
3636
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
3737

3838
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
39-
| [<img src="https://avatars0.githubusercontent.com/u/587016?v=3" width="100px;"/><br /><sub>Ives van Hoorne</sub>](http://ivesvh.com)<br />[💬](#question-CompuIves "Answering Questions") [📝](#blog-CompuIves "Blogposts") [🐛](https://github.com/CompuIves/CodeSandbox/issues?q=author%3ACompuIves "Bug reports") [💻](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Code") [🎨](#design-CompuIves "Design") [📖](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Documentation") [💡](#example-CompuIves "Examples") [🚇](#infra-CompuIves "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-CompuIves "Reviewed Pull Requests") [⚠️](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Tests") [🔧](#tool-CompuIves "Tools") |
40-
| :---: |
39+
| [<img src="https://avatars0.githubusercontent.com/u/587016?v=3" width="100px;"/><br /><sub>Ives van Hoorne</sub>](http://ivesvh.com)<br />[💬](#question-CompuIves "Answering Questions") [📝](#blog-CompuIves "Blogposts") [🐛](https://github.com/CompuIves/CodeSandbox/issues?q=author%3ACompuIves "Bug reports") [💻](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Code") [🎨](#design-CompuIves "Design") [📖](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Documentation") [💡](#example-CompuIves "Examples") [🚇](#infra-CompuIves "Infrastructure (Hosting, Build-Tools, etc)") [👀](#review-CompuIves "Reviewed Pull Requests") [⚠️](https://github.com/CompuIves/CodeSandbox/commits?author=CompuIves "Tests") [🔧](#tool-CompuIves "Tools") | [<img src="https://avatars0.githubusercontent.com/u/887639?v=3" width="100px;"/><br /><sub>Donavon West</sub>](http://donavon.com)<br />[💻](https://github.com/CompuIves/CodeSandbox/commits?author=donavon "Code") |
40+
| :---: | :---: |
4141
<!-- ALL-CONTRIBUTORS-LIST:END -->
4242

4343
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

src/app/pages/Sandbox/Editor/Workspace/Dependencies/ExternalResource.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
import React from 'react';
2-
import styled from 'styled-components';
3-
import theme from 'common/theme';
42

53
import CrossIcon from 'react-icons/lib/md/clear';
64

75
import EntryContainer from '../EntryContainer';
8-
9-
const Icon = styled.div`
10-
transition: 0.3s ease color;
11-
position: absolute;
12-
right: 1rem;
13-
line-height: 1;
14-
color: ${() => theme.background.lighten(2).clearer(0.5)};
15-
&:hover {
16-
color: ${() => theme.red};
17-
}
18-
`;
6+
import { IconArea, Icon } from '../Icon';
197

208
const getNormalizedUrl = (url: string) => `${url.replace(/\/$/g, '')}/`;
219

@@ -49,7 +37,9 @@ export default class ExternalResource extends React.PureComponent {
4937
<a href={resource} rel="noopener noreferrer" target="_blank">
5038
{getName(resource)}
5139
</a>
52-
<Icon onClick={this.removeResource}><CrossIcon /></Icon>
40+
<IconArea>
41+
<Icon onClick={this.removeResource}><CrossIcon /></Icon>
42+
</IconArea>
5343
</EntryContainer>
5444
);
5545
}

src/app/pages/Sandbox/Editor/Workspace/Dependencies/ExternalResource.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import React from 'react';
22
import renderer from 'react-test-renderer';
3+
import { ThemeProvider } from 'styled-components';
4+
35
import ExternalResource from './ExternalResource';
6+
import theme from '../../../../../../common/theme';
47

58
describe('ExternalResource', () => {
69
it('renders file if there is an extension', () => {
710
const tree = renderer
8-
.create(<ExternalResource resource="https://ivesvh.com/ives.js" />)
11+
.create(<ThemeProvider theme={theme}><ExternalResource resource="https://ivesvh.com/ives.js" /></ThemeProvider>)
912
.toJSON();
1013
expect(tree).toMatchSnapshot();
1114
});
1215

1316
it('renders url if there is no extension', () => {
1417
const tree1 = renderer
15-
.create(<ExternalResource resource="https://ivesvh.com/" />)
18+
.create(<ThemeProvider theme={theme}><ExternalResource resource="https://ivesvh.com/" theme={theme} /></ThemeProvider>)
1619
.toJSON();
1720

1821
const tree2 = renderer
19-
.create(<ExternalResource resource="https://ivesvh.com" />)
22+
.create(<ThemeProvider theme={theme}><ExternalResource resource="https://ivesvh.com" theme={theme} /></ThemeProvider>)
2023
.toJSON();
2124

2225
expect(tree1).toMatchSnapshot();

src/app/pages/Sandbox/Editor/Workspace/Dependencies/VersionEntry.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
11
import React from 'react';
22
import styled from 'styled-components';
33
import CrossIcon from 'react-icons/lib/md/clear';
4-
5-
import fadeIn from 'app/utils/animation/fade-in';
4+
import RefreshIcon from 'react-icons/lib/md/refresh';
65

76
import EntryContainer from '../EntryContainer';
7+
import { IconArea, Icon } from '../Icon';
88

99
const Version = styled.div`
1010
transition: 0.3s ease all;
1111
position: absolute;
12-
right: ${props => (props.hovering ? 2.5 : 1)}rem;
13-
color: ${props => props.theme.background.lighten(2).clearer(0.5)};
14-
`;
15-
16-
const Icon = styled.div`
17-
transition: 0.3s ease color;
18-
position: absolute;
19-
right: 1rem;
20-
opacity: 0;
21-
line-height: 1;
12+
right: ${props => (props.hovering ? 3.5 : 1)}rem;
2213
color: ${props => props.theme.background.lighten(2).clearer(0.5)};
23-
${fadeIn(0)}
24-
&:hover {
25-
color: ${props => props.theme.red};
26-
}
2714
`;
2815

2916
type Props = {
3017
dependencies: { [key: string]: string },
3118
dependency: string,
3219
onRemove: (dep: string) => void,
20+
onRefresh: (dep: string) => void,
3321
};
3422

3523
type State = {
@@ -45,6 +33,7 @@ export default class VersionEntry extends React.PureComponent {
4533
};
4634

4735
handleRemove = () => this.props.onRemove(this.props.dependency);
36+
handleRefresh = () => this.props.onRefresh(this.props.dependency);
4837
onMouseEnter = () => this.setState({ hovering: true });
4938
onMouseLeave = () => this.setState({ hovering: false });
5039

@@ -59,7 +48,10 @@ export default class VersionEntry extends React.PureComponent {
5948
>
6049
<span>{dependency}</span>
6150
<Version hovering={hovering}>{dependencies[dependency]}</Version>
62-
{hovering && <Icon onClick={this.handleRemove}><CrossIcon /></Icon>}
51+
{hovering && <IconArea>
52+
<Icon onClick={this.handleRefresh}><RefreshIcon /></Icon>
53+
<Icon onClick={this.handleRemove}><CrossIcon /></Icon>
54+
</IconArea>}
6355
</EntryContainer>
6456
);
6557
}

src/app/pages/Sandbox/Editor/Workspace/Dependencies/__snapshots__/ExternalResource.test.js.snap

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@ exports[`ExternalResource renders file if there is an extension 1`] = `
1212
ives.js
1313
</a>
1414
<div
15-
className="sc-bwzfXH gaVNMC"
16-
onClick={[Function]}
15+
className="sc-htpNat hFdhGH"
1716
>
18-
<svg
19-
fill="currentColor"
20-
height="1em"
21-
preserveAspectRatio="xMidYMid meet"
22-
style={
23-
Object {
24-
"color": undefined,
25-
"verticalAlign": "middle",
26-
}
27-
}
28-
viewBox="0 0 40 40"
29-
width="1em"
17+
<div
18+
className="sc-bwzfXH gUazxX"
19+
onClick={[Function]}
3020
>
31-
<g>
32-
<path
33-
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
34-
/>
35-
</g>
36-
</svg>
21+
<svg
22+
fill="currentColor"
23+
height="1em"
24+
preserveAspectRatio="xMidYMid meet"
25+
style={
26+
Object {
27+
"color": undefined,
28+
"verticalAlign": "middle",
29+
}
30+
}
31+
viewBox="0 0 40 40"
32+
width="1em"
33+
>
34+
<g>
35+
<path
36+
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
37+
/>
38+
</g>
39+
</svg>
40+
</div>
3741
</div>
3842
</span>
3943
`;
@@ -50,28 +54,32 @@ exports[`ExternalResource renders url if there is no extension 1`] = `
5054
https://ivesvh.com/
5155
</a>
5256
<div
53-
className="sc-bwzfXH gaVNMC"
54-
onClick={[Function]}
57+
className="sc-htpNat hFdhGH"
5558
>
56-
<svg
57-
fill="currentColor"
58-
height="1em"
59-
preserveAspectRatio="xMidYMid meet"
60-
style={
61-
Object {
62-
"color": undefined,
63-
"verticalAlign": "middle",
64-
}
65-
}
66-
viewBox="0 0 40 40"
67-
width="1em"
59+
<div
60+
className="sc-bwzfXH gUazxX"
61+
onClick={[Function]}
6862
>
69-
<g>
70-
<path
71-
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
72-
/>
73-
</g>
74-
</svg>
63+
<svg
64+
fill="currentColor"
65+
height="1em"
66+
preserveAspectRatio="xMidYMid meet"
67+
style={
68+
Object {
69+
"color": undefined,
70+
"verticalAlign": "middle",
71+
}
72+
}
73+
viewBox="0 0 40 40"
74+
width="1em"
75+
>
76+
<g>
77+
<path
78+
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
79+
/>
80+
</g>
81+
</svg>
82+
</div>
7583
</div>
7684
</span>
7785
`;
@@ -88,28 +96,32 @@ exports[`ExternalResource renders url if there is no extension 2`] = `
8896
https://ivesvh.com/
8997
</a>
9098
<div
91-
className="sc-bwzfXH gaVNMC"
92-
onClick={[Function]}
99+
className="sc-htpNat hFdhGH"
93100
>
94-
<svg
95-
fill="currentColor"
96-
height="1em"
97-
preserveAspectRatio="xMidYMid meet"
98-
style={
99-
Object {
100-
"color": undefined,
101-
"verticalAlign": "middle",
102-
}
103-
}
104-
viewBox="0 0 40 40"
105-
width="1em"
101+
<div
102+
className="sc-bwzfXH gUazxX"
103+
onClick={[Function]}
106104
>
107-
<g>
108-
<path
109-
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
110-
/>
111-
</g>
112-
</svg>
105+
<svg
106+
fill="currentColor"
107+
height="1em"
108+
preserveAspectRatio="xMidYMid meet"
109+
style={
110+
Object {
111+
"color": undefined,
112+
"verticalAlign": "middle",
113+
}
114+
}
115+
viewBox="0 0 40 40"
116+
width="1em"
117+
>
118+
<g>
119+
<path
120+
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
121+
/>
122+
</g>
123+
</svg>
124+
</div>
113125
</div>
114126
</span>
115127
`;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export default class Dependencies extends React.PureComponent {
134134
dependencies={npmDependencies}
135135
dependency={dep}
136136
onRemove={this.removeDependency}
137+
onRefresh={this.addDependency}
137138
/>
138139
))}
139140
<AddVersion

src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EditIcons.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import AddDirectoryIcon from 'react-icons/lib/go/file-symlink-directory';
88

99
import fadeIn from 'app/utils/animation/fade-in';
1010

11+
import { Icon } from '../../../Icon';
12+
1113
type Props = {
1214
className: ?string,
1315
hovering: boolean,
@@ -25,15 +27,6 @@ const Container = styled.div`
2527
line-height: 1;
2628
`;
2729

28-
const Icon = styled.div`
29-
transition: 0.3s ease color;
30-
color: ${props => props.theme.background2.lighten(3)};
31-
padding-left: 0.25rem;
32-
&:hover {
33-
color: white;
34-
}
35-
`;
36-
3730
const handleClick = func => (e: Event) => {
3831
e.preventDefault();
3932
e.stopPropagation();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styled from 'styled-components';
2+
import fadeIn from 'app/utils/animation/fade-in';
3+
4+
export const Icon = styled.div`
5+
position: relative;
6+
display: inline-block;
7+
transition: 0.3s ease color;
8+
color: ${props => props.theme.background2.lighten(3)};
9+
padding-left: 0.25rem;
10+
&:hover {
11+
color: white;
12+
}
13+
`;
14+
15+
export const IconArea = styled.div`
16+
position: absolute;
17+
right: 1rem;
18+
opacity: 0;
19+
line-height: 1;
20+
${fadeIn(0)}
21+
`;

0 commit comments

Comments
 (0)