UNPKG

react-loki

Version:

A React Wizard .... Pun intended

6 lines 5.25 kB
/*! * react-loki v1.2.0 * MIT Licensed */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactLoki=e(require("react")):t.ReactLoki=e(t.React)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var s=n[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(e,n){e.exports=t},function(t,e,n){t.exports=n(2)},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"default",function(){return f});var i=n(0),p=n.n(i),a=n(3),c=n(4);n.d(e,"LokiStepContainer",function(){return c.a}),n.d(e,"LokiStep",function(){return a.a});var u,l,h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},f=(l=u=function(t){function e(){var n,o,i;r(this,e);for(var p=arguments.length,a=Array(p),c=0;c<p;c++)a[c]=arguments[c];return n=o=s(this,t.call.apply(t,[this].concat(a))),o.state={currentStep:1,stepsDone:[],complete:!1},i=n,s(o,i)}return o(e,t),e.prototype._back=function(t){this.props.onBack&&this.props.onBack(t),this.setState({currentStep:this.state.currentStep-1})},e.prototype._next=function(t){if(this.state.currentStep===this.props.steps.length)return this.props.onFinish(t),this.setState({complete:!0});this.props.onNext&&this.props.onNext(t),this.setState({currentStep:this.state.currentStep+1,stepsDone:this.state.stepsDone.concat([this.state.currentStep])})},e.prototype._lokiData=function(){return{currentStep:this.state.currentStep,stepIndex:this.state.currentStep-1,cantBack:1===this.state.currentStep,isInFinalStep:this.state.currentStep===this.props.steps.length,backHandler:this._back.bind(this),nextHandler:this._next.bind(this)}},e.prototype._renderSteps=function(){var t=this;if(this.props.steps){if(this.props.renderSteps)return this.props.renderSteps(this._lokiData());var e=this.props.steps.map(function(e,n){return p.a.createElement(a.a,{key:n,stepsDone:t.state.stepsDone,currentStep:t.state.currentStep,totalSteps:t.props.steps.length,step:h({},e,{index:n+1}),goTo:function(e){return t.setState({currentStep:e})},isLokiComplete:t.state.complete})});return p.a.createElement(c.a,null,e)}},e.prototype._renderComponents=function(){if(this.props.steps){if(this.props.renderComponents)return this.props.renderComponents(this._lokiData());var t=this._lokiData(),e=t.stepIndex,n=t.cantBack,r=t.isInFinalStep,s=t.backHandler,o=t.nextHandler,i=this.props.steps[e].component;return this.props.noActions?p.a.cloneElement(i,{isComplete:this.state.complete,backLabel:this.props.backLabel,nextLabel:r?this.props.finishLabel:this.props.nextLabel,cantBack:n,isInFinalStep:r,onBack:s,onNext:o}):i}},e.prototype._renderActions=function(){if(this.props.steps&&!this.props.noActions){var t=1===this.state.currentStep,e=this.state.currentStep===this.props.steps.length;return this.props.renderActions?this.props.renderActions(this._lokiData()):p.a.createElement("div",{className:"Loki-Actions"},p.a.createElement("button",{type:"button",onClick:this._back.bind(this),disabled:t||this.state.complete},this.props.backLabel),p.a.createElement("button",{type:"button",onClick:this._next.bind(this),disabled:this.state.complete},e?this.props.finishLabel:this.props.nextLabel))}},e.prototype.render=function(){return p.a.createElement("div",{className:"Loki"},this._renderSteps(),this._renderComponents(),this._renderActions())},e}(i.Component),u.defaultProps={backLabel:"Back",nextLabel:"Next",finishLabel:"Finish"},l)},function(t,e,n){"use strict";var r=n(0),s=n.n(r),o=function(t){var e=t.currentStep,n=(t.stepsDone,t.totalSteps,t.step),r=t.isLokiComplete,o=t.goTo,i=e===n.index,p=e>n.index,a=!i&&!p;return s.a.createElement("li",{className:"LokiStep "+(i&&"LokiStep-Active")+" "+((p||r)&&"LokiStep-Complete")},s.a.createElement("a",{href:"#",onClick:function(t){t.preventDefault(),a||o(n.index)},className:"LokiStep-Link "+(a&&"disabled"),disabled:a},s.a.createElement("div",{className:"LokiStep-Icon"},n.icon||n.index)))};e.a=o},function(t,e,n){"use strict";var r=n(0),s=n.n(r),o=function(t){var e=t.children;return s.a.createElement("ol",{className:"LokiSteps"},e)};e.a=o}])}); //# sourceMappingURL=react-loki.min.js.map