UNPKG

@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

45 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var utils_1 = require("utils"); var initialState = { show: false }; var Toggleable = (function (_super) { tslib_1.__extends(Toggleable, _super); function Toggleable() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = initialState; _this.reset = function () { return _this.internalSetState(initialState, function () { }); }; _this.getApi = function () { return { show: _this.state.show, toggle: _this.toggle }; }; _this.internalSetState = function (changes, callback) { _this.setState(function (state) { var changesObject = typeof changes === 'function' ? changes(state) : changes; var reducedChanges = _this.props.stateReducer ? _this.props.stateReducer(state, changesObject) : changesObject; return reducedChanges; }, callback); }; _this.toggle = function (event) { return _this.internalSetState(updateShowState, function () { return _this.props.onToggle ? _this.props.onToggle(_this.state.show) : null; }); }; return _this; } Toggleable.prototype.render = function () { var _a = this.props, InjectedComponent = _a.component, children = _a.children, render = _a.render, props = _a.props; var renderProps = this.getApi(); if (InjectedComponent) { return (React.createElement(InjectedComponent, tslib_1.__assign({}, props, renderProps), children)); } if (render) { return render(renderProps); } if (children != null && utils_1.isFunction(children)) { var childrenAsFunction = children; return childrenAsFunction(renderProps); } return null; }; return Toggleable; }(React.Component)); exports.Toggleable = Toggleable; var updateShowState = function (prevState) { return ({ show: !prevState.show }); }; //# sourceMappingURL=Toggleable.js.map