All files DialogOptions.tsx

100% Statements 11/11
66.67% Branches 4/6
100% Functions 2/2
100% Lines 11/11
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                  3x                                     1x 1x 1x                 3x 3x 3x 2x   3x 3x 3x    
 
/** All options for dialog */
export interface DialogOptions {
    theme?: string;
    labelOK?: string,
    labelCancel?: string,
    animate?: boolean,
    notificationAutoClose?: boolean;
    notificationClickClose?: boolean;
    notificationCloseDelay?: number;
    notificationTheme?: string;
    notificationPlacement?: string;
    notificationMaxItems?: number;
    notificationSquare?: boolean;
}
 
/** The default options for dialog */
export let defaultOptions: DialogOptions = {
    labelOK: "OK",
    labelCancel: "Cancel",
    animate: true,
    notificationAutoClose: true,
    notificationClickClose: true,
    notificationCloseDelay: 3000,
    notificationTheme: "default",
    notificationPlacement: "bottom right",
    notificationMaxItems: 3,
    notificationSquare: false,
};
 
/**
 * Sets global options for dialog.
 *
 * @param options  The dialog options
 */
export function setup(options: DialogOptions) {
    defaultOptions = {...defaultOptions, ...options};
    Eif (defaultOptions.theme) {
        setTheme(defaultOptions.theme);
    }
}
 
/**
 * Sets theme for dialog and will remove old theme
 * @param theme The dialog theme
 */
export function setTheme(theme: string) {
    const attrKey = 'dialog-theme';
    const oldTheme = document.body.getAttribute(attrKey);
    if (oldTheme) {
        document.body.classList.remove(oldTheme);
    }
    Eif (theme) {
        document.body.classList.add(theme);
        document.body.setAttribute(attrKey, theme);
    }
}