Remove theme context from the react codebase
parent
b695732521
commit
6633d72418
@ -1,16 +0,0 @@
|
||||
import React from 'react';
|
||||
import { ThemeContext } from './theme-context'
|
||||
|
||||
export const withThemeConsumer = (WrappedComponent) => {
|
||||
return class extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<ThemeContext.Consumer>
|
||||
{theme => (
|
||||
<WrappedComponent darkTheme={theme} {...this.props} />
|
||||
)}
|
||||
</ThemeContext.Consumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
export const ThemeContext = React.createContext({
|
||||
dark: false
|
||||
});
|
||||
@ -1,37 +0,0 @@
|
||||
import React from 'react';
|
||||
import { ThemeContext } from './theme-context'
|
||||
|
||||
export const withThemeProvider = (WrappedComponent) => {
|
||||
return class extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
dark: document.querySelector('html').classList.contains('dark') || false
|
||||
};
|
||||
|
||||
this.mutationObserver = new MutationObserver((mutationsList, _observer) => {
|
||||
mutationsList.forEach(mutation => {
|
||||
if (mutation.attributeName === 'class') {
|
||||
this.setState({ dark: mutation.target.classList.contains('dark') });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.mutationObserver.observe(document.querySelector('html'), { attributes: true });
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.mutationObserver.disconnect();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ThemeContext.Provider value={this.state.dark}>
|
||||
<WrappedComponent {...this.props}/>
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue