@zohodesk/hooks
Version:
Unified Component Library - Hooks
34 lines (30 loc) • 961 B
JavaScript
export const DEFAULT_POPUP_GROUP = '_DEFAULT_POPUP_GROUP';
let popups = {};
export function addPopupHandler(handler, groupName) {
if (popups[groupName] === undefined) {
popups[groupName] = [];
}
popups[groupName].push(handler);
}
export function removePopupHandler(handler, groupName) {
const selectedGroup = popups[groupName];
if (selectedGroup !== undefined && selectedGroup.length > 0) {
popups[groupName] = selectedGroup.filter(func => func !== handler);
}
}
export function closePopupsByGroup(groupName) {
const selectedGroup = popups[groupName];
if (selectedGroup !== undefined && selectedGroup.length > 0) {
selectedGroup.reverse().map(fn => fn());
}
}
export function closeAllOtherPopupGroups(groupName) {
Object.keys(popups).map(grp => {
if (grp !== groupName) {
const selectedGroup = popups[grp];
if (selectedGroup.length > 0) {
selectedGroup.reverse().map(fn => fn());
}
}
});
}