"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require("react");
var storybook_addons_1 = require("@kadira/storybook-addons");
var assign = require("object-assign");
var style = {
wrapper: {
overflow: "scroll",
position: "fixed",
top: 0,
bottom: 0,
right: 0,
left: 0,
transition: "background 0.25s ease-in-out",
backgroundPosition: "center",
backgroundSize: "cover",
background: "transparent",
},
};
var BackgroundDecorator = (function (_super) {
__extends(BackgroundDecorator, _super);
function BackgroundDecorator(props) {
var _this = this;
_super.call(this, props);
this.state = { background: "transparent" };
this.setBackground = function (background) { return _this.setState({ background: background }); };
Eif (this.props.channel) {
this.channel = this.props.channel;
}
else {
this.channel = storybook_addons_1.default.getChannel();
}
this.story = this.props.story();
}
BackgroundDecorator.prototype.componentWillMount = function () {
this.channel.on("background", this.setBackground);
this.channel.emit("background-set", this.props.backgrounds);
};
BackgroundDecorator.prototype.componentWillReceiveProps = function (nextProps) {
if (nextProps.story !== this.props.story) {
this.story = nextProps.story();
}
};
BackgroundDecorator.prototype.componentWillUnmount = function () {
this.channel.removeListener("background", this.setBackground);
this.channel.emit("background-unset");
};
BackgroundDecorator.prototype.render = function () {
var styles = style.wrapper;
styles.background = this.state.background;
return React.createElement("div", {style: assign({}, styles)}, this.story);
};
return BackgroundDecorator;
}(React.Component));
exports.BackgroundDecorator = BackgroundDecorator;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = function (backgrounds) { return function (story) { return (React.createElement(BackgroundDecorator, {story: story, backgrounds: backgrounds})); }; };
//# sourceMappingURL=index.js.map |