Skip to content

Commit 699ee88

Browse files
siddharthkpCompuIves
authored andcommitted
Embeds: Add light theme (codesandbox#3015)
* get split pane to work in embed * add a cute little toggle * snap to edges * get default size from props * handle toggle position for different vertical views * get full height back * add transition for resize toggle * breaking things to test on mobile * bring back the toggle * header buttons work again * hide resizer on mobile * only offset height if header is visible * handle 50% and pane container * add transition to snap * add sidebar toggle to header * handle screen resize * vertical panes only * remove header for mobile * refactor and simplify code * Move the heart button to preview * refactor actions + add refresh * add button to open in new window * get the right icons * fade transition * get animation right for navigation actions * add border on all sides for preview * Add types for new props * i dont know what to tell you fam * increase tap width for resizer * increase snap radius for the right side * add threshold for showing navigation icons on smaller screens * (has bugs) add click functionality for resizer * rename width to newSize * add opacity for border * update icons for navigation * move global actions inside splitpane * position open sandbox lower for editor * fold when like overlaps + isDragging transition * first stab at intro animation * animation intensifies * i think thats good * introduce on load for mobile * fix the animation timeline * fix opacity for animation * variables good good * use window.outerWidth because that doesnt lie * dont wait for mouseover on mobile * oh noes, outerWidth is also a lie * solve preview size problems * rename embed theme to dark * start new theme * move theme provider to App * introduce getTheme * add harcoded variant * read theme from url * refactor sidebar elements to system * sidebar info on theme * systemetise file tree * panel + content container * cheeseburget * fix the height of tabs and navigator * remove icons from tabs in embed * theming wip * style preview components * fix embed background * decide top offset for preview based on navigation flag * add theme drop down to share sheet * more night own less custom * punctuations
1 parent 930ab2f commit 699ee88

File tree

17 files changed

+776
-107
lines changed

17 files changed

+776
-107
lines changed

packages/app/src/app/pages/common/Modals/ShareModal/getCode.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import {
88
} from '@codesandbox/common/lib/utils/url-generator';
99
import { escapeHtml } from 'app/utils/escape';
1010

11-
export const BUTTON_URL = `${
12-
process.env.CODESANDBOX_HOST
13-
}/static/img/play-codesandbox.svg`;
11+
export const BUTTON_URL = `${process.env.CODESANDBOX_HOST}/static/img/play-codesandbox.svg`;
1412

1513
export const VIEW_OPTIONS = ['Editor + Preview', 'Preview', 'Editor'];
14+
export const THEME_OPTIONS = ['Dark', 'Light'];
1615

1716
const getOptionsUrl = (sandbox, mainModule, state) => {
1817
const {
1918
defaultModule,
2019
view,
20+
theme,
2121
testsView,
2222
autoResize,
2323
hideNavigation,
@@ -31,6 +31,7 @@ const getOptionsUrl = (sandbox, mainModule, state) => {
3131

3232
const options = {
3333
view: view !== VIEW_OPTIONS[0] ? view.toLowerCase() : null,
34+
theme: theme !== THEME_OPTIONS[0] ? theme.toLowerCase() : null,
3435
previewwindow: testsView ? 'tests' : null,
3536
autoresize: autoResize ? 1 : null,
3637
hidenavigation: hideNavigation ? 1 : null,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import {
2323
BUTTON_URL,
2424
VIEW_OPTIONS,
25+
THEME_OPTIONS,
2526
getIframeScript,
2627
getEditorUrl,
2728
getEmbedUrl,
@@ -32,6 +33,7 @@ import {
3233
class ShareView extends React.Component {
3334
state = {
3435
view: VIEW_OPTIONS[0],
36+
theme: 'dark',
3537
testsView: false,
3638
defaultModule: null,
3739
autoResize: false,
@@ -108,6 +110,10 @@ class ShareView extends React.Component {
108110
this.setState({ view });
109111
};
110112

113+
setTheme = (theme: string) => {
114+
this.setState({ theme });
115+
};
116+
111117
select = function select(event) {
112118
event.target.select();
113119
};
@@ -122,6 +128,7 @@ class ShareView extends React.Component {
122128

123129
const {
124130
view,
131+
theme,
125132
testsView,
126133
autoResize,
127134
hideNavigation,
@@ -156,6 +163,13 @@ class ShareView extends React.Component {
156163
value={view}
157164
setValue={this.setView}
158165
/>
166+
<PaddedPreference
167+
title="Theme"
168+
type="dropdown"
169+
options={THEME_OPTIONS}
170+
value={theme}
171+
setValue={this.setTheme}
172+
/>
159173
<PaddedPreference
160174
title="Auto resize"
161175
type="boolean"

packages/app/src/embed/components/App/elements.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
// @flow
22
import styled from 'styled-components';
3+
import css from '@styled-system/css';
34

4-
export const Container = styled.div`
5-
display: flex;
6-
flex-direction: column;
7-
height: 100%;
8-
width: 100vw;
9-
color: white;
10-
`;
5+
export const Container = styled.div(
6+
css({
7+
display: 'flex',
8+
flexDirection: 'column',
9+
height: '100%',
10+
width: '100vw',
11+
})
12+
);
1113

12-
export const Fullscreen = styled.div`
13-
width: 100vw;
14-
height: 100%;
15-
overflow: hidden;
16-
`;
14+
export const Fullscreen = styled.div(
15+
css({
16+
width: '100vw',
17+
height: '100vh',
18+
overflow: 'hidden',
19+
backgroundColor: 'editor.background',
20+
color: 'editor.foreground',
21+
h1: {
22+
// override common element which has hard coded color
23+
color: 'editor.foreground',
24+
},
25+
})
26+
);
1727

1828
export const Moving = styled.div`
1929
transition: 0.3s ease all;

packages/app/src/embed/components/App/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Content from '../Content';
1717
import Sidebar from '../Sidebar';
1818
import { Container, Fullscreen, Moving } from './elements';
1919
import { SIDEBAR_SHOW_SCREEN_SIZE } from '../../util/constants';
20+
import { getTheme } from '../../theme';
2021

2122
// Okay, this looks veeeery strange, we need this because Webpack has a bug currently
2223
// that makes it think we havecore-js/es6/map available in embed, but we don't.
@@ -46,6 +47,7 @@ type State = {
4647
verticalMode: boolean,
4748
highlightedLines: Array<number>,
4849
tabs?: Array<number>,
50+
theme: string,
4951
};
5052

5153
const isSafari = () => {
@@ -88,6 +90,7 @@ export default class App extends React.PureComponent<
8890
runOnClick,
8991
verticalMode = window.innerWidth < window.innerHeight,
9092
tabs,
93+
theme = 'dark',
9194
} = props.embedOptions || getSandboxOptions(document.location.href);
9295

9396
this.state = {
@@ -109,6 +112,7 @@ export default class App extends React.PureComponent<
109112
forceRefresh,
110113
expandDevTools,
111114
tabs,
115+
theme,
112116
runOnClick:
113117
runOnClick === false
114118
? false
@@ -395,20 +399,23 @@ export default class App extends React.PureComponent<
395399

396400
render() {
397401
const { sandbox } = this.state;
402+
const theme = getTheme(this.state.theme);
398403

399404
return (
400-
<Fullscreen sidebarOpen={this.state.sidebarOpen}>
401-
{sandbox && (
402-
<>
403-
<Sidebar
404-
setCurrentModule={this.setCurrentModule}
405-
currentModule={this.getCurrentModuleFromPath(sandbox).id}
406-
sandbox={sandbox}
407-
/>
408-
</>
409-
)}
410-
<Moving sidebarOpen={this.state.sidebarOpen}>{this.content()}</Moving>
411-
</Fullscreen>
405+
<ThemeProvider theme={theme}>
406+
<Fullscreen sidebarOpen={this.state.sidebarOpen}>
407+
{sandbox && (
408+
<>
409+
<Sidebar
410+
setCurrentModule={this.setCurrentModule}
411+
currentModule={this.getCurrentModuleFromPath(sandbox).id}
412+
sandbox={sandbox}
413+
/>
414+
</>
415+
)}
416+
<Moving sidebarOpen={this.state.sidebarOpen}>{this.content()}</Moving>
417+
</Fullscreen>
418+
</ThemeProvider>
412419
);
413420
}
414421
}
Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
import styled from 'styled-components';
2+
import css from '@styled-system/css';
3+
import { Container as NavigatorContainer } from '@codesandbox/common/lib/components/Preview/Navigator/elements';
24

3-
export const Container = styled.div`
4-
display: flex;
5-
position: relative;
6-
background-color: ${props => props.theme['editor.background']};
7-
height: 100%;
8-
`;
5+
export const Container = styled.div(
6+
css({
7+
display: 'flex',
8+
position: 'relative',
9+
backgroundColor: 'editor.background',
10+
height: '100%',
911

10-
export const Tabs = styled.div`
11-
display: flex;
12-
height: 33px;
13-
min-height: 33px;
14-
background-color: ${props => props.theme['tab.inactiveBackground']};
15-
/* shadow instead of border to align with the border of the child tab */
16-
box-shadow: inset 0px -1px 0 ${props => props.theme['sideBar.border']};
17-
overflow-x: auto;
18-
font-size: 0.875rem;
12+
// overwrite the height of navigation
13+
[NavigatorContainer]: {
14+
height: 31,
15+
minHeight: 31,
16+
},
17+
})
18+
);
1919

20-
-ms-overflow-style: none; // IE 10+
21-
overflow: -moz-scrollbars-none; // Firefox
20+
export const Tabs = styled.div(
21+
css({
22+
display: 'flex',
23+
height: 32,
24+
minHeight: 32,
25+
backgroundColor: 'tab.inactiveBackground',
26+
/* shadow instead of border to align with the border of the child tab */
27+
boxShadow: theme => 'inset 0px -1px 0 ' + theme['sideBar.border'],
28+
overflowX: 'auto',
29+
fontSize: 3,
2230

23-
&::-webkit-scrollbar {
24-
height: 2px; // Safari and Chrome
25-
}
31+
'-ms-overflow-style': 'none', // IE 10+
32+
overflow: '-moz-scrollbars-none', // Firefox
33+
'&::-webkit-scrollbar': {
34+
height: '2px', // Safari and Chrome
35+
},
2636

27-
/* override children, bad but vscode doesnt support
28-
tab.hoverForeground :shrug:
29-
*/
30-
> div:hover > div {
31-
color: white !important;
32-
}
33-
`;
37+
/* override children, bad but vscode doesnt support
38+
tab.hoverForeground so we explicitly set it :shrug:
39+
*/
40+
'> div:hover > div': {
41+
color: 'tab.hoverForeground',
42+
},
43+
})
44+
);
3445

35-
export const MenuInTabs = styled.span`
36-
display: inline-flex;
37-
height: 100%;
38-
align-items: center;
39-
padding-left: 8px;
40-
`;
46+
export const MenuInTabs = styled.span(
47+
css({
48+
display: 'inline-flex',
49+
alignItems: 'center',
50+
height: '100%',
51+
paddingLeft: 2,
52+
})
53+
);

packages/app/src/embed/components/Content/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import { CorrectionClearAction } from 'codesandbox-api/dist/types/actions/correc
1313
import { CodeEditor } from 'app/components/CodeEditor';
1414
import { Editor } from 'app/components/CodeEditor/types'; // eslint-disable-line
1515
import Tab from 'app/pages/Sandbox/Editor/Content/Tabs/Tab';
16-
import EntryIcons from 'app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/EntryIcons';
17-
// eslint-disable-next-line import/extensions
18-
import getType from 'app/utils/get-type.ts';
1916

2017
import getTemplate from '@codesandbox/common/lib/templates';
2118
import { parseSandboxConfigurations } from '@codesandbox/common/lib/templates/configuration/parse-sandbox-configurations';
@@ -534,7 +531,6 @@ export default class Content extends React.PureComponent<Props, State> {
534531
{({ hovering, closeTab }) => (
535532
// TODO deduplicate this
536533
<>
537-
<EntryIcons type={getType(module.title)} />
538534
<TabTitle>{module.title}</TabTitle>
539535
{dirName && (
540536
<TabDir>

packages/app/src/embed/components/Sidebar/FileTree/elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export const FileContainer = styled.div(props =>
88
fontSize: 3,
99
lineHeight: '24px',
1010
paddingLeft: theme.space[3] * (props.depth + 1),
11-
backgroundColor: props.isSelected ? 'grays.500' : 'transparent',
11+
backgroundColor: props.isSelected ? 'sideBar.border' : 'transparent',
1212
':hover': {
1313
cursor: 'pointer',
14-
backgroundColor: 'grays.500',
14+
backgroundColor: 'sideBar.border',
1515
},
1616
}))
1717
);

packages/app/src/embed/components/Sidebar/SandboxInfo/elements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Title = styled.h2(
2121
export const Description = styled.div(
2222
css({
2323
fontSize: 2,
24-
color: 'grays.300',
24+
color: 'sideBar.foreground',
2525
marginBottom: 4,
2626
})
2727
);
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
// @flow
21
import styled from 'styled-components';
2+
import css from '@styled-system/css';
33
import { isIOS } from '@codesandbox/common/lib/utils/platform';
44

5-
export const Container = styled.div`
6-
flex: 250px;
7-
width: 250px;
5+
export const Container = styled.div(
6+
css({
7+
flex: 250,
8+
width: 250,
89

9-
color: white;
10-
z-index: 10;
11-
background-color: ${props => props.theme['sideBar.background']};
12-
overflow: auto;
13-
font-family: Inter, sans-serif;
10+
color: 'sideBar.foreground',
11+
zIndex: 10,
12+
backgroundColor: 'sideBar.background',
13+
overflow: 'auto',
14+
fontFamily: 'Inter, sans-serif',
1415

15-
/* There is a bug with ios that causes the sidebar to be longer than the preview, when you then
16-
* scroll the preview it scrolls the editor down (page is longer). If I set this to 100% scrolling
17-
* is broken in Chrome though. That's why we have this check */
18-
height: ${isIOS ? '100%' : '100vh'};
19-
`;
16+
/* There is a bug with ios that causes the sidebar to be longer than the preview, when you then
17+
* scroll the preview it scrolls the editor down (page is longer). If I set this to 100% scrolling
18+
* is broken in Chrome though. That's why we have this check */
19+
height: isIOS ? '100%' : '100vh',
20+
})
21+
);

packages/app/src/embed/components/legacy/Header/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const Button = styled.button(
111111

112112
export const MenuIcon = styled(MenuIconSVG)(
113113
css({
114-
color: 'grays.400',
114+
color: 'tab.activeForeground',
115115
marginRight: 2,
116116
cursor: 'pointer',
117117
zIndex: 10,

0 commit comments

Comments
 (0)