Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor Theme Selection #670

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export function updateFontSize(fontSize){
return{ type: types.UPDATE_FONT_SIZE, fontSize };
}

export function updateTheme(theme) {
return { type: types.UPDATE_THEME, theme };
}

export function updateUserSettings(id,settings){
return ()=>{
if(id){
Expand Down Expand Up @@ -43,5 +47,6 @@ export default {
updateFontSize,
asyncUserSettings,
syncUserSettings,
updateUserSettings
updateUserSettings,
updateTheme
};
19 changes: 16 additions & 3 deletions src/components/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React, { Component } from "react";
import AceEditor from "react-ace";
import "brace/mode/javascript";
import "brace/theme/github";
import "brace/theme/monokai";
import "brace/theme/eclipse";
import "brace/theme/xcode";
import "brace/theme/dracula";
import "brace/theme/gruvbox";

import "brace/ext/searchbox";
import "brace/ext/language_tools";

Expand All @@ -10,6 +16,7 @@ import KeyboardShortcut from "./KeyboardShortcut.js";
import { browserType } from "../../utils/browserType";
import FontSize from "./FontSize.js";
import copy from "copy-to-clipboard";
import ThemeSelector from "./Theme.js";

/**
* Editor is a React Component that create the Ace Editor in the DOM.
Expand Down Expand Up @@ -101,7 +108,8 @@ class Editor extends Component {
name="ace-editor"
// eslint-disable-next-line
ref="aceEditor"
theme="github"
theme={this.props.settings.theme}
background="black"
commands={[{
name: "copyLine",
bindKey: {win: "Ctrl-L", mac: "Command-L"},
Expand All @@ -121,8 +129,13 @@ class Editor extends Component {
enableLiveAutocompletion={true}
onLoad={this.onLoad}
/>
{ browserType() === "desktop" ? <div><KeyboardShortcut/>
<FontSize userActions={this.props.userActions} settings={this.props.settings} refreshText={this.refreshText}/></div> : null }
{ browserType() === "desktop" ? <div>
<KeyboardShortcut/>
<FontSize userActions={this.props.userActions} settings={this.props.settings} refreshText={this.refreshText}/>
<ThemeSelector userActions={this.props.userActions} settings={this.props.settings}/>
</div> : null }


</div>
);
}
Expand Down
41 changes: 41 additions & 0 deletions src/components/editor/Theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import {
Button,
Icon,
Select,
Tooltip,
} from "@material-ui/core";
import "../../css/KeyboardShortcut.css";
export default function ThemeSelector(props) {
const handleThemeEditorUpdate = (e) => {
props.userActions.updateTheme(e.target.value);
};

const themes = [
"github", "eclipse", "xcode", "dracula", "gruvbox", "monokai"
];

return (
<div className="theme-div">
<Tooltip title="Select Editor Theme">
<Button className="font-button"
id="font-size"
variant="contained"
size="small"
color="white"
>
<Icon className="material-icons">format_color_fill</Icon>
<Select
className="theme-select"
labelId="input-label"
defaultValue="github"
value={props.settings.themeColor}
onChange={handleThemeEditorUpdate}>
{themes.map(theme=>(<option value={theme}>{theme}</option>))}
</Select>
</Button>
</Tooltip>
</div>
);
}

1 change: 1 addition & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ export const DELETE_COLLECTION = "DELETE_COLLECTION";

export const SYNC_USER_SETTINGS = "SYNC_USER_SETTINGS";
export const UPDATE_FONT_SIZE = "UPDATE_FONT_SIZE";
export const UPDATE_THEME= "UPDATE_THEME";

export const LOAD_REF_EX = "LOAD_REF_EX";
21 changes: 20 additions & 1 deletion src/css/KeyboardShortcut.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@

.font {
display: inline-block;
margin-left: 4px;
margin-left: 5px;
}

#form-control {
margin-top: 0;
}

.theme-div {
display: inline-block;
margin-left: 5px;
margin-top: 0;
}

.theme-div > button {
width: 140px;
}

.whole-keyboard {
Expand All @@ -43,4 +57,9 @@
.select {
color: white !important;
margin-left: 5px;
}

.theme-select {
color: black !important;
margin-left: 5px;
}
11 changes: 10 additions & 1 deletion src/reducers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as types from "../constants/ActionTypes";
const initial_state = {
user: null,
settings: {
fontSize: 12
fontSize: 12,
theme: "github",
}
};

Expand Down Expand Up @@ -43,6 +44,14 @@ export default function user(state = initial_state, action) {
fontSize: action.fontSize
}
};
case types.UPDATE_THEME:
return{
...state,
settings: {
...state.settings,
theme: action.theme
}
};
default:
return state;
}
Expand Down
12 changes: 8 additions & 4 deletions src/tests/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const generateMockProps = () => {
},
user: null,
settings: {
fontSize: 12
fontSize: 12,
theme: "github",
},
scene: {
name: "",
Expand Down Expand Up @@ -281,7 +282,8 @@ describe("User Reducer", () => {
{
user: null,
settings : {
fontSize: 12
fontSize: 12,
theme: "github"
}
}
);
Expand All @@ -298,7 +300,8 @@ describe("User Reducer", () => {
{
user: testUser,
settings:{
fontSize: 12
fontSize: 12,
theme: "github"
}
}
);
Expand All @@ -312,7 +315,8 @@ describe("User Reducer", () => {
).toEqual({
user: null,
settings:{
fontSize: 12
fontSize: 12,
theme: "github"
}
}
);
Expand Down