@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
31 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var hoist_non_react_statics_1 = require("hoist-non-react-statics");
var utils_1 = require("utils");
exports.withTogglleable = function (UnwrappedComponent) {
var WithToggle = (function (_super) {
tslib_1.__extends(WithToggle, _super);
function WithToggle() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { show: false };
_this.toggle = function (event) {
return _this.setState(function (prevState) { return ({ show: !prevState.show }); });
};
return _this;
}
WithToggle.prototype.render = function () {
var show = this.state.show;
var _a = this.props, children = _a.children, rest = tslib_1.__rest(_a, ["children"]);
return (React.createElement(React.Fragment, null,
React.createElement(UnwrappedComponent, tslib_1.__assign({}, rest, { onClick: this.toggle })),
show ? children : null));
};
WithToggle.displayName = utils_1.getHocComponentName(WithToggle.name, UnwrappedComponent);
WithToggle.WrappedComponent = UnwrappedComponent;
return WithToggle;
}(React.Component));
return hoist_non_react_statics_1.default(WithToggle, UnwrappedComponent);
};
//# sourceMappingURL=withToggeable.js.map