@up-group-ui/react-controls
Version:
Up shared react controls
30 lines • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withTogglleable = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var hoist_non_react_statics_1 = (0, tslib_1.__importDefault)(require("hoist-non-react-statics"));
var utils_1 = require("utils");
var withTogglleable = function (UnwrappedComponent) {
var WithToggle = (function (_super) {
(0, 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 = (0, tslib_1.__rest)(_a, ["children"]);
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(UnwrappedComponent, (0, tslib_1.__assign)({}, rest, { onClick: this.toggle }), void 0), show ? children : null] }, void 0));
};
WithToggle.displayName = (0, utils_1.getHocComponentName)(WithToggle.name, UnwrappedComponent);
WithToggle.WrappedComponent = UnwrappedComponent;
return WithToggle;
}(react_1.default.Component));
return (0, hoist_non_react_statics_1.default)(WithToggle, UnwrappedComponent);
};
exports.withTogglleable = withTogglleable;
//# sourceMappingURL=withToggeable.js.map