Skip to content

Commit ea3e563

Browse files
author
Ives van Hoorne
committed
Add template colors to the embed
1 parent a02679c commit ea3e563

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

src/embed/App.js

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @flow
22
import * as React from 'react';
3-
import styled from 'styled-components';
3+
import styled, { ThemeProvider } from 'styled-components';
44
import { camelizeKeys } from 'humps';
55
import 'whatwg-fetch';
66

77
import type { Sandbox, Module } from 'common/types';
8+
import getTemplateDefinition from 'common/templates';
89
import Centered from 'app/components/flex/Centered';
910
import Title from 'app/components/text/Title';
1011
import SubTitle from 'app/components/text/SubTitle';
@@ -15,7 +16,7 @@ import Sidebar from './components/Sidebar';
1516
import { getSandboxOptions } from '../common/url';
1617
import {
1718
findCurrentModule,
18-
findMainModule,
19+
findMainModule
1920
} from 'app/store/entities/sandboxes/modules/selectors';
2021

2122
const Container = styled.div`
@@ -56,7 +57,7 @@ type State = {
5657
sidebarOpen: boolean,
5758
autoResize: boolean,
5859
hideNavigation: boolean,
59-
fontSize: number,
60+
fontSize: number
6061
};
6162

6263
export default class App extends React.PureComponent<{}, State> {
@@ -71,7 +72,7 @@ export default class App extends React.PureComponent<{}, State> {
7172
isEditorScreen,
7273
autoResize,
7374
hideNavigation,
74-
fontSize,
75+
fontSize
7576
} = getSandboxOptions(document.location.href);
7677

7778
this.state = {
@@ -85,7 +86,7 @@ export default class App extends React.PureComponent<{}, State> {
8586
initialPath,
8687
sidebarOpen: false,
8788
autoResize,
88-
hideNavigation,
89+
hideNavigation
8990
};
9091
}
9192

@@ -103,7 +104,7 @@ export default class App extends React.PureComponent<{}, State> {
103104
fetchSandbox = async (id: string) => {
104105
try {
105106
const response = await fetch(
106-
`${this.getAppOrigin()}/api/v1/sandboxes/${id}`,
107+
`${this.getAppOrigin()}/api/v1/sandboxes/${id}`
107108
)
108109
.then(res => res.json())
109110
.then(camelizeKeys);
@@ -148,7 +149,7 @@ export default class App extends React.PureComponent<{}, State> {
148149
sandbox.modules,
149150
sandbox.directories,
150151
currentModulePath,
151-
findMainModule(sandbox.modules),
152+
findMainModule(sandbox.modules)
152153
);
153154
};
154155

@@ -175,30 +176,37 @@ export default class App extends React.PureComponent<{}, State> {
175176
const { showEditor, showPreview, isInProjectView } = this.state;
176177

177178
return (
178-
<Container>
179-
<Header
180-
showEditor={showEditor}
181-
showPreview={showPreview}
182-
setEditorView={this.setEditorView}
183-
setPreviewView={this.setPreviewView}
184-
setMixedView={this.setMixedView}
185-
sandbox={this.state.sandbox}
186-
toggleSidebar={this.toggleSidebar}
187-
/>
188-
<Content
189-
showEditor={showEditor}
190-
showPreview={showPreview}
191-
isInProjectView={isInProjectView}
192-
setProjectView={this.setProjectView}
193-
sandbox={this.state.sandbox}
194-
currentModule={this.getCurrentModuleFromPath().id}
195-
hideNavigation={this.state.hideNavigation}
196-
autoResize={this.state.autoResize}
197-
fontSize={this.state.fontSize}
198-
initialPath={this.state.initialPath}
199-
setCurrentModule={this.setCurrentModule}
200-
/>
201-
</Container>
179+
<ThemeProvider
180+
theme={{
181+
templateColor: getTemplateDefinition(this.state.sandbox.template)
182+
.color
183+
}}
184+
>
185+
<Container>
186+
<Header
187+
showEditor={showEditor}
188+
showPreview={showPreview}
189+
setEditorView={this.setEditorView}
190+
setPreviewView={this.setPreviewView}
191+
setMixedView={this.setMixedView}
192+
sandbox={this.state.sandbox}
193+
toggleSidebar={this.toggleSidebar}
194+
/>
195+
<Content
196+
showEditor={showEditor}
197+
showPreview={showPreview}
198+
isInProjectView={isInProjectView}
199+
setProjectView={this.setProjectView}
200+
sandbox={this.state.sandbox}
201+
currentModule={this.getCurrentModuleFromPath().id}
202+
hideNavigation={this.state.hideNavigation}
203+
autoResize={this.state.autoResize}
204+
fontSize={this.state.fontSize}
205+
initialPath={this.state.initialPath}
206+
setCurrentModule={this.setCurrentModule}
207+
/>
208+
</Container>
209+
</ThemeProvider>
202210
);
203211
};
204212

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5824,6 +5824,10 @@ monaco-editor@CompuIves/codesandbox-monaco-editor:
58245824
dependencies:
58255825
monaco-typescript CompuIves/monaco-typescript
58265826

5827+
monaco-typescript@CompuIves/monaco-typescript:
5828+
version "2.2.0"
5829+
resolved "https://codeload.github.com/CompuIves/monaco-typescript/tar.gz/eff3dd58fe3a6b15944838842aaf734910baa1d4"
5830+
58275831
58285832
version "2.0.0"
58295833
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

0 commit comments

Comments
 (0)