UNPKG

react-antd-admin-panel

Version:

Easy prototyping admin panel using React and Antd

60 lines 2.11 kB
export default class Access { constructor(main) { this.style = {}; this.access = ({ access: true, hidden: false }); this.disabled = false; this._main = main; } render(v) { this._render = v; return this; } simple(v, args) { var _a; if (v._access === undefined) return false; if (typeof v._disabled === 'function') return (((_a = v._disabled) === null || _a === void 0 ? void 0 : _a.call(v, args)) || !this._main.$access(v._access).access); return (v._disabled || !this._main.$access(v._access).access); } action(v, args) { var _a; if (v._access === undefined) return this; if (this._main) { this.access = this._main.$access(v._access); this.disabled = !this.access.access; if (!this.access.access && !this.access.hidden) { this.style = { opacity: .25 }; } if (!this.access.access && this.access.hidden) { this.style = { opacity: 0 }; } } if ((_a = v._disabled) === null || _a === void 0 ? void 0 : _a.call(v, args)) { this.disabled = true; this.access.access = false; this.style = Object.assign(Object.assign({}, this.style), { opacity: .25 }); } return this; } configs(v) { let keys = Object.keys(v); keys.forEach((r) => { switch (true) { case (r === 'onClick' && !this.access.access): this['onClick'] = (e) => e.stopPropagation(); break; default: this[r] = v[r]; } }); return this._render(this.getObject()); } getObject() { var _a; return ({ style: this.style, disabled: this.disabled, onClick: (_a = this['onClick']) !== null && _a !== void 0 ? _a : (() => { }), }); } } //# sourceMappingURL=Access.js.map