insomnia/app/ui/components/modals/index.js
Gregory Schier 8131041701 Nunjucks Template Tag Plugins MVP (#272)
* Refactor extension format and load plugins from directory

* Added some UI around plugins

* Refactor PromptModal usage
2017-05-31 19:04:27 -07:00

39 lines
789 B
JavaScript

import PromptModal from './prompt-modal';
const modals = {};
export function registerModal (instance) {
if (instance === null) {
// Modal was unmounted
return;
}
modals[instance.constructor.name] = instance;
}
export function showPrompt (config) {
showModal(PromptModal, config);
}
export function showModal (modalCls, ...args) {
return _getModal(modalCls).show(...args);
}
export function toggleModal (modalCls, ...args) {
return _getModal(modalCls).toggle(...args);
}
export function hideModal (modalCls) {
return _getModal(modalCls).hide();
}
export function hideAllModals () {
for (const key of Object.keys(modals)) {
const modal = modals[key];
modal.hide && modal.hide();
}
}
function _getModal (modalCls) {
return modals[modalCls.name];
}