UNPKG

react-permissions

Version:
6 lines 2.74 kB
/*! * react-permissions v1.0.3 - https://github.com/IkoroVictor * MIT Licensed */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactPermissions=t(require("react")):e.ReactPermissions=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function s(e,t){return function(n){function a(e,i){r(this,a);var u=o(this,n.call(this,e,i));return u.state={allowedPermissions:t||e.allowedPermissions||[]},u.allPermissions=s.prototype.allPermissions||(s.mapPermissions?s.mapPermissions(e):[]),u.alternateView=e.alternateView||l.a.createClass({displayName:"alternateView",render:function(){return l.a.createElement("div",null)}}),u}return i(a,n),a.prototype.componentWillReceiveProps=function(e){e.allowedPermissions&&this.setState({allowedPermissions:e.allowedPermissions})},a.prototype.componentWillUpdate=function(e,t){this.allPermissions=s.prototype.allPermissions||(s.mapPermissions?s.mapPermissions(e):[])},a.prototype.hasPermission=function(e){var t=this,n=this.allPermissions.filter(function(e){return t.state.allowedPermissions.filter(function(t){return t==e}).length>0});return e?n.length===this.state.allowedPermissions.length:n.length>0},a.prototype.render=function(){var t=this.alternateView;return this.hasPermission(this.props.hasAll)?l.a.createElement(e,this.props):l.a.createElement(t,null)},a}(l.a.Component)}Object.defineProperty(t,"__esModule",{value:!0}),t.Permissioned=s;var a=n(1),l=n.n(a)},function(t,n){t.exports=e},function(e,t,n){e.exports=n(0)}])}); //# sourceMappingURL=react-permissions.min.js.map