All files / src/custom-element/helpers/css/class applyClasses.ts

100% Statements 6/6
75% Branches 3/4
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23            2x   2x   4x   4x   2x       2x        
/**
 * Apply the classes to an HTML elements if the props keyed by the name of the class
 * has a value that evaluates to true
 * @param element 
 * @param props 
 */
export default function applyClasses(element: HTMLElement, props: Record<string, boolean>): void {
    
    for (const key in props) {
 
        Eif (props.hasOwnProperty(key)) {
 
            if (props[key] === true) {
 
                element.classList.add(key);
            }
            else {
 
                element.classList.remove(key);
            }
        }
    }
}