storybook-addon-styled-component-theme
Version:
storybook addon with styled-components theme
32 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ThemesProvider = void 0;
var addons_1 = require("@storybook/addons");
var React = require("react");
var recompose_1 = require("recompose");
var BaseComponent = function (_a) {
var theme = _a.theme, ThemeProvider = _a.ThemeProvider, children = _a.children;
return (React.createElement(ThemeProvider, { theme: theme }, children));
};
exports.ThemesProvider = recompose_1.compose(recompose_1.withState("theme", "setTheme", null), recompose_1.withHandlers({
onSelectTheme: function (_a) {
var setTheme = _a.setTheme, themes = _a.themes;
return function (name) {
var theme = themes.find(function (th) { return th.name === name; });
setTheme(theme);
};
},
}), recompose_1.lifecycle({
componentDidMount: function () {
var _a = this.props, onSelectTheme = _a.onSelectTheme, themes = _a.themes;
var channel = addons_1.default.getChannel();
channel.on("selectTheme", onSelectTheme);
channel.emit("setThemes", themes);
},
componentWillUnmount: function () {
var onSelectTheme = this.props.onSelectTheme;
var channel = addons_1.default.getChannel();
channel.removeListener("selectTheme", onSelectTheme);
},
}), recompose_1.branch(function (props) { return !props.theme; }, recompose_1.renderNothing))(BaseComponent);
//# sourceMappingURL=ThemesProvider.js.map