mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
64 lines
1.3 KiB
JavaScript
64 lines
1.3 KiB
JavaScript
import React, {Component} from 'react';
|
|
|
|
|
|
const modals = {
|
|
// Modals will be registered here as singletons
|
|
};
|
|
|
|
class ModalComponent extends Component {
|
|
componentDidMount () {
|
|
const name = this.constructor.name;
|
|
modals[name] = this;
|
|
}
|
|
|
|
static _callInstanceMethod (method, ...args) {
|
|
const name = this.name;
|
|
const instance = modals[name];
|
|
|
|
if (!instance) {
|
|
console.error(`Modal doesn't exist with NAME: ${name}`, modals);
|
|
return;
|
|
}
|
|
|
|
return instance[method](...args);
|
|
}
|
|
|
|
static show (...args) {
|
|
return this._callInstanceMethod('show', ...args);
|
|
}
|
|
|
|
static hide (...args) {
|
|
return this._callInstanceMethod('hide', ...args);
|
|
}
|
|
|
|
static toggle (...args) {
|
|
return this._callInstanceMethod('toggle', ...args);
|
|
}
|
|
|
|
toggle () {
|
|
if (this.refs.modal) {
|
|
this.refs.modal.toggle();
|
|
} else {
|
|
console.error(`ref "modal" does not exist on ${this.constructor.name}`, this.refs);
|
|
}
|
|
}
|
|
|
|
hide () {
|
|
if (this.refs.modal) {
|
|
this.refs.modal.hide();
|
|
} else {
|
|
console.error(`ref "modal" does not exist on ${this.constructor.name}`, this.refs);
|
|
}
|
|
}
|
|
|
|
show () {
|
|
if (this.refs.modal) {
|
|
this.refs.modal.show();
|
|
} else {
|
|
console.error(`ref "modal" does not exist on ${this.constructor.name}`, this.refs);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default ModalComponent;
|