All files / src/utils index.js

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                1x       13x       5x 3x         8x 5x   3x         8x       3x       6x      
// @flow
 
import type {ModalProps} from '../types/ModalProps';
 
type Modal = {
    props: ModalProps
}
 
export const activeModals = {
    modals: [],
 
    isActive(modal: Modal) {
        return modal.props.isOpen;
    },
 
    pushIfActive(modal: Modal) {
        if (this.isActive(modal)) {
            this.modals.push(modal);
        }
    },
 
    toggle(modal: Modal) {
        if (this.isActive(modal)) {
            this.pop(modal);
        } else {
            this.modals.push(modal);
        }
    },
 
    pop(modal: Modal) {
        this.modals = this.modals.filter(el => modal !== el);
    },
 
    isOnTop(modal: Modal) {
        return this.modals.slice(-1)[0] === modal;
    },
 
    isEmpty() {
        return this.modals.length === 0;
    }
};