Skip to content

Commit a96f34a

Browse files
SaraVieiraCompuIves
authored andcommitted
add themes to dependencies modal (codesandbox#1797)
* add themes to depencies modal * Color tweaks
1 parent 469f031 commit a96f34a

File tree

7 files changed

+194
-73
lines changed

7 files changed

+194
-73
lines changed

packages/app/src/app/pages/Sandbox/SearchDependencies/DependencyHit/elements.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
import styled from 'styled-components';
22
import Select from '@codesandbox/common/lib/components/Select';
33
import { UserWithAvatar } from '@codesandbox/common/lib/components/UserWithAvatar';
4+
import Color from 'color';
5+
6+
import GitHubLogo from 'app/components/GitHubLogo';
7+
8+
export const GitHubLogoStyled = styled(GitHubLogo)`
9+
color: ${props =>
10+
!props.theme.light ? 'inherit' : 'rgba(255, 255, 255, 0.8)'};
11+
`;
12+
13+
const getContainerColor = props => {
14+
if (props.highlighted) {
15+
return Color(props.theme['sideBar.background'])
16+
.darken(0.2)
17+
.rgbString();
18+
}
19+
20+
return props.theme['sideBar.background'];
21+
};
422

523
export const Container = styled.div`
624
display: flex;
7-
background: ${props =>
8-
props.highlighted
9-
? props.theme.background2.darken(0.3)
10-
: props.theme.background2};
11-
color: ${props => props.theme.white};
25+
color: ${props =>
26+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
27+
background-color: ${getContainerColor};
1228
cursor: pointer;
29+
1330
&:not(:last-child) {
14-
border-bottom: 1px solid ${props => props.theme.background3};
31+
border-bottom: 1px solid
32+
${props =>
33+
Color(props.theme['sideBar.background'])
34+
.darken(0.4)
35+
.rgbString()};
1536
}
1637
1738
&:hover {
18-
background-color: ${props => props.theme.background2.darken(0.2)};
39+
background-color: ${props =>
40+
Color(props.theme['sideBar.background'])
41+
.darken(0.2)
42+
.rgbString()};
1943
}
2044
`;
2145

@@ -37,20 +61,26 @@ export const Row = styled.div`
3761

3862
export const Description = styled(Row)`
3963
font-size: 0.875rem;
40-
color: rgba(255, 255, 255, 0.6);
64+
65+
color: ${props =>
66+
props.theme.light ? 'rgba(0, 0, 0, 0.6)' : 'rgba(255, 255, 255, 0.6)'};
4167
`;
4268

4369
export const Downloads = styled.span`
44-
color: ${props => props.theme.gray};
70+
color: ${props => props.theme['panelTitle.inactiveForeground']};
4571
font-weight: 500;
4672
font-size: 12px;
4773
`;
4874

4975
export const License = styled.span`
50-
border: 1px solid rgba(255, 255, 255, 0.4);
76+
border: 1px solid
77+
${props =>
78+
!props.theme.light ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.4)'};
5179
border-radius: 3px;
5280
padding: 1px 3px;
53-
color: rgba(255, 255, 255, 0.6);
81+
82+
color: ${props =>
83+
props.theme.light ? 'rgba(0, 0, 0, 0.6)' : 'rgba(255, 255, 255, 0.6)'};
5484
font-size: 12px;
5585
`;
5686

packages/app/src/app/pages/Sandbox/SearchDependencies/DependencyHit/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import compareVersions from 'compare-versions';
66

77
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
88

9-
import GitHubLogo from 'app/components/GitHubLogo';
109
import formatDownloads from '../formatDownloads';
1110

1211
import {
@@ -20,6 +19,7 @@ import {
2019
IconLink,
2120
StyledSelect,
2221
StyledUserWithAvatar,
22+
GitHubLogoStyled,
2323
} from './elements';
2424

2525
const getDefaultSelectedVersion = tags => {
@@ -43,7 +43,7 @@ export default class DependencyHit extends React.PureComponent {
4343
return `https://github.com/${repo.user}/${repo.project}`;
4444
}
4545

46-
makeSearchUrl(hitName: string) {
46+
makeSearchUrl(hitName) {
4747
return `${
4848
process.env.CODESANDBOX_HOST
4949
}/search?refinementList%5Bnpm_dependencies.dependency%5D%5B0%5D=${hitName}&page=1`;
@@ -70,7 +70,7 @@ export default class DependencyHit extends React.PureComponent {
7070
}
7171
}
7272

73-
const versions = Object.keys(hit.versions).sort((a: string, b: string) => {
73+
const versions = Object.keys(hit.versions).sort((a, b) => {
7474
try {
7575
return compareVersions(b, a);
7676
} catch (e) {
@@ -107,7 +107,7 @@ export default class DependencyHit extends React.PureComponent {
107107
rel="noreferrer noopener"
108108
onClick={this.stopPropagation}
109109
>
110-
<GitHubLogo />
110+
<GitHubLogoStyled />
111111
</IconLink>
112112
</Tooltip>
113113
)}

packages/app/src/app/pages/Sandbox/SearchDependencies/RawAutoComplete/elements.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ export const AutoCompleteInput = styled.input`
55
box-sizing: border-box;
66
border: none;
77
outline: none;
8-
background-color: ${props => props.theme.background2};
8+
background-color: ${props => props.theme['sideBar.background']};
99
font-weight: 600;
10-
color: ${props => props.theme.white};
10+
11+
color: ${props =>
12+
props.theme.light ? props.theme.black : props.theme.white};
1113
padding: 0.75em 1em;
1214
z-index: 2;
1315
`;
@@ -16,8 +18,10 @@ export const SuggestionInput = styled(AutoCompleteInput)`
1618
position: absolute;
1719
top: 0;
1820
left: 0;
19-
color: rgba(255, 255, 255, 0.3);
21+
color: ${props =>
22+
props.theme.light ? 'rgba(0, 0, 0, 0.3)' : 'rgba(255, 255, 255, 0.3)'};
2023
background-color: transparent;
2124
z-index: 1;
2225
pointer-events: none;
26+
letter-spacing: 0.45px;
2327
`;

packages/app/src/app/pages/Sandbox/SearchDependencies/dependencies.css

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { createGlobalStyle } from 'styled-components';
2+
3+
export default createGlobalStyle`
4+
.ReactModal__Content div[class^='Modal__ModalBody'] {
5+
/*
6+
* app/src/app/containers/Modal.js sets ModalBody background to white.
7+
* We don't want to risk messing up something else, so we fix that here.
8+
*/
9+
background: transparent;
10+
}
11+
12+
.search-dependencies {
13+
14+
.ais-Pagination {
15+
color: ${props =>
16+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
17+
background-color: ${props => props.theme['sideBar.background']};
18+
border-radius: 0;
19+
display: flex;
20+
justify-content: center;
21+
padding: 0;
22+
}
23+
24+
.ais-Pagination-link {
25+
color: ${props =>
26+
props.theme.light ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)'};
27+
}
28+
29+
.ais-Pagination-item--selected {
30+
color: ${props => props.theme.white};
31+
background: ${props => props.theme['button.hoverBackground']};
32+
}
33+
34+
.ais-Highlight-highlighted {
35+
color: ${props => props.theme['button.hoverBackground']};
36+
}
37+
38+
.ais-PoweredBy-link svg path:nth-child(4) {
39+
fill: ${props =>
40+
props.theme.light
41+
? 'rgba(0, 0, 0, 0.8)'
42+
: 'rgba(255, 255, 255, 0.8)'} !important;
43+
}
44+
45+
footer {
46+
height: 40px;
47+
background-color: ${props => props.theme['sideBar.background']};
48+
49+
.ais-PoweredBy {
50+
color: ${props =>
51+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
52+
53+
}
54+
}
55+
}
56+
`;

packages/app/src/app/pages/Sandbox/SearchDependencies/index.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
22
import { InstantSearch, Configure, PoweredBy } from 'react-instantsearch/dom';
33
import { connectAutoComplete } from 'react-instantsearch/connectors';
4-
import theme from '@codesandbox/common/lib/theme';
54

65
import 'app/pages/Search/search.css';
7-
import './dependencies.css';
6+
import DependenciesCSS from './dependencies';
87

98
import RawAutoComplete from './RawAutoComplete';
109

@@ -48,29 +47,27 @@ export default class SearchDependencies extends React.PureComponent {
4847

4948
render() {
5049
return (
51-
<InstantSearch
52-
appId="OFCNCOG2CU"
53-
apiKey="00383ecd8441ead30b1b0ff981c426f5"
54-
indexName="npm-search"
55-
>
56-
<Configure
57-
analyticsTags={['codesandbox-dependencies']}
58-
hitsPerPage={5}
59-
/>
60-
<ConnectedAutoComplete
61-
onSelect={this.handleSelect}
62-
onManualSelect={this.handleManualSelect}
63-
onHitVersionChange={this.handleHitVersionChange}
64-
/>
65-
<div
66-
style={{
67-
height: 40,
68-
backgroundColor: theme.background2.darken(0.2)(),
69-
}}
50+
<div className="search-dependencies">
51+
<DependenciesCSS />
52+
<InstantSearch
53+
appId="OFCNCOG2CU"
54+
apiKey="00383ecd8441ead30b1b0ff981c426f5"
55+
indexName="npm-search"
7056
>
71-
<PoweredBy />
72-
</div>
73-
</InstantSearch>
57+
<Configure
58+
analyticsTags={['codesandbox-dependencies']}
59+
hitsPerPage={5}
60+
/>
61+
<ConnectedAutoComplete
62+
onSelect={this.handleSelect}
63+
onManualSelect={this.handleManualSelect}
64+
onHitVersionChange={this.handleHitVersionChange}
65+
/>
66+
<footer>
67+
<PoweredBy />
68+
</footer>
69+
</InstantSearch>
70+
</div>
7471
);
7572
}
7673
}

packages/app/src/app/pages/common/Modals/index.js

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22
import { inject, observer } from 'mobx-react';
33
import Modal from 'app/components/Modal';
4-
54
import Loadable from 'app/utils/Loadable';
5+
import { ThemeProvider } from 'styled-components';
6+
import getTemplateDefinition from '@codesandbox/common/lib/templates';
7+
import codesandbox from '@codesandbox/common/lib/themes/codesandbox.json';
8+
import getVSCodeTheme from 'app/src/app/pages/Sandbox/Editor/utils/get-vscode-theme';
69

710
import NewSandbox from './NewSandbox';
811
import PreferencesModal from './PreferencesModal';
@@ -126,22 +129,67 @@ const modals = {
126129
},
127130
};
128131

129-
function Modals({ store, signals }) {
130-
const modal = store.currentModal && modals[store.currentModal];
132+
class Modals extends Component {
133+
state = {
134+
theme: {
135+
colors: {},
136+
vscodeTheme: codesandbox,
137+
},
138+
customVSCodeTheme: this.props.store.preferences.settings.customVSCodeTheme,
139+
};
140+
141+
componentDidMount() {
142+
this.loadTheme();
143+
}
144+
145+
componentDidUpdate() {
146+
if (
147+
this.props.store.preferences.settings.customVSCodeTheme !==
148+
this.state.customVSCodeTheme
149+
) {
150+
this.loadTheme();
151+
}
152+
}
153+
154+
loadTheme = async () => {
155+
const customVSCodeTheme = this.props.store.preferences.settings
156+
.customVSCodeTheme;
157+
158+
try {
159+
const theme = await getVSCodeTheme('', customVSCodeTheme);
160+
this.setState({ theme, customVSCodeTheme });
161+
} catch (e) {
162+
console.error(e);
163+
}
164+
};
165+
render() {
166+
const { signals, store } = this.props;
167+
const sandbox = store.editor.currentSandbox;
168+
const templateDef = sandbox && getTemplateDefinition(sandbox.template);
169+
const modal = store.currentModal && modals[store.currentModal];
131170

132-
return (
133-
<Modal
134-
isOpen={Boolean(modal)}
135-
width={modal && modal.width}
136-
onClose={(isKeyDown: boolean) => signals.modalClosed({ isKeyDown })}
137-
>
138-
{modal
139-
? React.createElement(modal.Component, {
140-
closeModal: () => signals.modalClosed({ isKeyDown: false }),
141-
})
142-
: null}
143-
</Modal>
144-
);
171+
return (
172+
<ThemeProvider
173+
theme={{
174+
templateColor: templateDef && templateDef.color,
175+
templateBackgroundColor: templateDef && templateDef.backgroundColor,
176+
...this.state.theme,
177+
}}
178+
>
179+
<Modal
180+
isOpen={Boolean(modal)}
181+
width={modal && modal.width}
182+
onClose={(isKeyDown: boolean) => signals.modalClosed({ isKeyDown })}
183+
>
184+
{modal
185+
? React.createElement(modal.Component, {
186+
closeModal: () => signals.modalClosed({ isKeyDown: false }),
187+
})
188+
: null}
189+
</Modal>
190+
</ThemeProvider>
191+
);
192+
}
145193
}
146194

147195
export default inject('store', 'signals')(observer(Modals));

0 commit comments

Comments
 (0)