You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
779 B
38 lines
779 B
7 years ago
|
import ThemeContext from './theme-context';
|
||
|
import ThemedButton from './button';
|
||
|
|
||
|
class App extends React.Component {
|
||
|
state = {
|
||
|
theme: {
|
||
|
highlight: 'blue',
|
||
|
accent: 'purple',
|
||
|
},
|
||
|
};
|
||
|
|
||
|
changeHighlightColor = () => {
|
||
|
const colors = ['red', 'blue', 'green'];
|
||
|
const randomColor =
|
||
|
colors[Math.floor(Math.random() * 3)];
|
||
|
this.setState({
|
||
|
theme: {
|
||
|
...this.state.theme,
|
||
|
highlight: randomColor,
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<ThemeContext.Provider value={this.state.theme}>
|
||
|
<div>
|
||
|
<ThemedButton onClick={this.changeHighlightColor}>
|
||
|
Change Theme
|
||
|
</ThemedButton>
|
||
|
</div>
|
||
|
</ThemeContext.Provider>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ReactDOM.render(<App />, document.root);
|