import React from 'react'; import Actions from '../../../src/flux/actions' import {Flexbox, RetinaImg} from 'nylas-component-kit'; import ThemeOption from './theme-option'; class ThemePicker extends React.Component { static displayName = 'ThemePicker'; constructor(props) { super(props); this._themeManager = NylasEnv.themes; this.state = this._getState(); } componentDidMount() { this.disposable = this._themeManager.onDidChangeActiveThemes(() => { this.setState(this._getState()); }); } componentWillUnmount() { this.disposable.dispose(); } _getState() { return { themes: this._themeManager.getLoadedThemes(), activeTheme: this._themeManager.getActiveTheme().name, } } _setActiveTheme(theme) { const prevActiveTheme = this.state.activeTheme; this.setState({activeTheme: theme}); this._themeManager.setActiveTheme(theme); this._rewriteIFrame(prevActiveTheme, theme); } _rewriteIFrame(prevActiveTheme, activeTheme) { const prevActiveThemeDoc = document.querySelector(`.theme-preview-${prevActiveTheme}`).contentDocument; const prevActiveElement = prevActiveThemeDoc.querySelector(".theme-option.active-true"); prevActiveElement.className = "theme-option active-false"; const activeThemeDoc = document.querySelector(`.theme-preview-${activeTheme}`).contentDocument; const activeElement = activeThemeDoc.querySelector(".theme-option.active-false"); activeElement.className = "theme-option active-true"; } _renderThemeOptions() { const themeOptions = this.state.themes.map((theme) =>
this._setActiveTheme(theme.name)} style={{cursor: "pointer", width: "115px", margin: "2px"}}>
) return themeOptions; } render() { return (
Actions.closeModal()} />

Themes

Click any theme to preview.
{this._renderThemeOptions()}
); } } export default ThemePicker;