2016-03-05 07:21:06 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Actions from '../../../src/flux/actions'
|
|
|
|
|
2016-03-31 06:52:51 +08:00
|
|
|
import {Flexbox, RetinaImg, ScrollRegion} from 'nylas-component-kit';
|
2016-03-05 07:21:06 +08:00
|
|
|
import ThemeOption from './theme-option';
|
|
|
|
|
|
|
|
|
|
|
|
class ThemePicker extends React.Component {
|
|
|
|
static displayName = 'ThemePicker';
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-03-09 09:08:09 +08:00
|
|
|
this.themes = NylasEnv.themes;
|
2016-03-05 07:21:06 +08:00
|
|
|
this.state = this._getState();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-03-09 09:08:09 +08:00
|
|
|
this.disposable = this.themes.onDidChangeActiveThemes(() => {
|
2016-03-05 07:21:06 +08:00
|
|
|
this.setState(this._getState());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.disposable.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
_getState() {
|
|
|
|
return {
|
2016-03-09 09:08:09 +08:00
|
|
|
themes: this.themes.getLoadedThemes(),
|
|
|
|
activeTheme: this.themes.getActiveTheme().name,
|
2016-03-05 07:21:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setActiveTheme(theme) {
|
|
|
|
const prevActiveTheme = this.state.activeTheme;
|
2016-03-09 09:08:09 +08:00
|
|
|
this.themes.setActiveTheme(theme);
|
2016-03-05 07:21:06 +08:00
|
|
|
this._rewriteIFrame(prevActiveTheme, theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
_rewriteIFrame(prevActiveTheme, activeTheme) {
|
2016-04-06 04:43:36 +08:00
|
|
|
const prevActiveThemeDoc = document.querySelector(`.theme-preview-${prevActiveTheme.replace(/\./g, '-')}`).contentDocument;
|
2016-03-05 07:21:06 +08:00
|
|
|
const prevActiveElement = prevActiveThemeDoc.querySelector(".theme-option.active-true");
|
2016-04-06 04:43:36 +08:00
|
|
|
if (prevActiveElement) prevActiveElement.className = "theme-option active-false";
|
|
|
|
const activeThemeDoc = document.querySelector(`.theme-preview-${activeTheme.replace(/\./g, '-')}`).contentDocument;
|
2016-03-05 07:21:06 +08:00
|
|
|
const activeElement = activeThemeDoc.querySelector(".theme-option.active-false");
|
2016-04-06 04:43:36 +08:00
|
|
|
if (activeElement) activeElement.className = "theme-option active-true";
|
2016-03-05 07:21:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_renderThemeOptions() {
|
2016-03-12 03:01:33 +08:00
|
|
|
const internalThemes = ['ui-ubuntu', 'ui-taiga', 'ui-darkside', 'ui-dark', 'ui-light'];
|
2016-03-11 08:37:01 +08:00
|
|
|
const sortedThemes = [].concat(this.state.themes);
|
|
|
|
sortedThemes.sort((a, b) => {
|
|
|
|
return (internalThemes.indexOf(a.name) - internalThemes.indexOf(b.name)) * -1;
|
|
|
|
});
|
|
|
|
return sortedThemes.map((theme) =>
|
2016-03-09 09:08:09 +08:00
|
|
|
<ThemeOption
|
|
|
|
key={theme.name}
|
|
|
|
theme={theme}
|
|
|
|
active={this.state.activeTheme === theme.name}
|
2016-03-11 06:10:48 +08:00
|
|
|
onSelect={() => this._setActiveTheme(theme.name)} />
|
2016-03-09 09:08:09 +08:00
|
|
|
);
|
2016-03-05 07:21:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2016-03-19 09:12:55 +08:00
|
|
|
<div className="theme-picker" tabIndex="1">
|
2016-03-05 07:21:06 +08:00
|
|
|
<Flexbox direction="column">
|
|
|
|
<RetinaImg
|
2016-03-22 10:35:47 +08:00
|
|
|
className="theme-picker-x"
|
2016-04-01 03:04:41 +08:00
|
|
|
style={{width: "14", WebkitFilter: "none"}}
|
2016-03-05 07:21:06 +08:00
|
|
|
name="picker-close.png"
|
|
|
|
mode={RetinaImg.Mode.ContentDark}
|
|
|
|
onMouseDown={() => Actions.closeModal()} />
|
2016-03-11 07:18:52 +08:00
|
|
|
<h4 style={{color: "#434648"}}>Themes</h4>
|
|
|
|
<div style={{color: "rgba(35, 31, 32, 0.5)", fontSize: "12px"}}>Click any theme to apply:</div>
|
2016-03-31 06:52:51 +08:00
|
|
|
<ScrollRegion style={{margin: "10px 5px 0 5px", height: "290px"}}>
|
2016-03-05 07:21:06 +08:00
|
|
|
<Flexbox
|
|
|
|
direction="row"
|
|
|
|
height="auto"
|
|
|
|
style={{alignItems: "flex-start", flexWrap: "wrap"}}>
|
|
|
|
{this._renderThemeOptions()}
|
|
|
|
</Flexbox>
|
2016-03-31 06:52:51 +08:00
|
|
|
</ScrollRegion>
|
2016-03-11 07:18:52 +08:00
|
|
|
<div className="create-theme">
|
2016-03-22 10:35:47 +08:00
|
|
|
<a
|
|
|
|
href="https://github.com/nylas/N1-theme-starter"
|
|
|
|
style={{color: "#3187e1"}}>
|
|
|
|
Create a Theme
|
|
|
|
</a>
|
2016-03-11 07:18:52 +08:00
|
|
|
</div>
|
2016-03-05 07:21:06 +08:00
|
|
|
</Flexbox>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ThemePicker;
|