2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
|
|
|
import addons from '@storybook/addons';
|
|
|
|
import { EVENT_ID_DATA, DEFAULT_THEME_STATE } from './constant';
|
|
|
|
import { Container } from '../../src';
|
|
|
|
|
|
|
|
const channel = addons.getChannel();
|
|
|
|
|
|
|
|
class Theme extends React.Component {
|
|
|
|
state = DEFAULT_THEME_STATE;
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
channel.on(EVENT_ID_DATA, this.onChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
channel.removeListener(EVENT_ID_DATA, this.onChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
onChannel = state => {
|
|
|
|
this.setState(state);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-01-09 02:08:34 +03:00
|
|
|
return <Container themeData={this.state}>{this.props.children}</Container>;
|
2019-01-03 16:00:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const withTheme = story => <Theme>{story()}</Theme>;
|