wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
40 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var prop_types_1 = tslib_1.__importDefault(require("prop-types"));
var CodeExample_1 = tslib_1.__importDefault(require("../CodeExample"));
var InteractiveCodeExample = /** @class */ (function (_super) {
tslib_1.__extends(InteractiveCodeExample, _super);
function InteractiveCodeExample(props) {
var _this = _super.call(this, props) || this;
_this.state = {
code: '',
};
_this.onCodeChange = _this.onCodeChange.bind(_this);
return _this;
}
InteractiveCodeExample.prototype.onCodeChange = function (code) {
if (code !== this.state.code) {
this.setState({ code: code });
}
};
InteractiveCodeExample.prototype.render = function () {
var _this = this;
var childrenWithOnChange = react_1.Children.map(this.props.children, function (child) {
return (0, react_1.cloneElement)(child, { onChange: _this.onCodeChange });
});
return (react_1.default.createElement(CodeExample_1.default, { title: this.props.title, code: this.state.code, codeType: "django", autoExpand: this.props.autoExpand }, childrenWithOnChange));
};
InteractiveCodeExample.propTypes = {
children: prop_types_1.default.node,
title: prop_types_1.default.string,
autoExpand: prop_types_1.default.bool,
};
InteractiveCodeExample.defaultProps = {
autoExpand: true,
};
return InteractiveCodeExample;
}(react_1.Component));
exports.default = InteractiveCodeExample;
//# sourceMappingURL=index.js.map