All files / src/components/drop-down DropDown.ts

39.29% Statements 11/28
0% Branches 0/2
25% Functions 2/8
39.29% Lines 11/28

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 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 971x 1x 1x 1x   1x   1x 1x   1x       1x         1x                                                                                                                                                         1x
import CustomElement from "../../custom-element/CustomElement";
import getClasses from "../../custom-element/helpers/css/class/getClasses";
import defineCustomElement from "../../custom-element/helpers/defineCustomElement";
import popupManager from "../../custom-element/helpers/managers/popupManager";
import { CustomElementStateMetadata } from "../../custom-element/interfaces";
import html  from "../../renderer/html";
import { NodePatchingData } from "../../renderer/NodePatcher";
import { dropChanged } from "../tools/drop/DropTool";
import styles from "./DropDown.css";
 
export default class DropDown extends CustomElement  {
 
    static get styles(): string {
 
        return styles as any;
    }
 
    static get state(): Record<string, CustomElementStateMetadata> {
 
        return {
 
            showing: {
                value: false
            }
        };
    }
 
    constructor() {
 
        super();
 
        this.handleDropChanged = this.handleDropChanged.bind(this);
    }
 
    render(): NodePatchingData {
 
        const {
            showing
        } = this;
 
        const contentClasses = getClasses({
            'dropdown-content': true,
            'show': showing
        });
 
        return html`<div tabindex="0" class="dropdown">
            <gcl-row>
                <slot id="header" name="header"></slot>
                <gcl-drop-tool id="drop-tool"></gcl-drop-tool>
            </gcl-row>
            <div class=${contentClasses}>
                <slot name="content"></slot>
            </div>
        </div>`;
    }
 
    connectedCallback() {
 
        super.connectedCallback?.();
 
        this.addEventListener(dropChanged, this.handleDropChanged);
    }
 
    disconnectedCallback() {
 
        super.disconnectedCallback?.();
 
        this.removeEventListener(dropChanged, this.handleDropChanged);
    }
 
    handleDropChanged(evt: CustomEvent) {
 
        evt.stopPropagation();
 
        const {
            showing
        } = evt.detail;
 
        if (showing === true) { // Hide the contents of other showing dropdowns and set this one as being shown
 
            popupManager.setShown(this as any);
        }
 
        this.showing = showing;
    }
 
    hideContent() {
 
        const dropTool = this.document.getElementById('drop-tool');
 
        dropTool.hideContent();
 
        popupManager.setHidden(this as any);
    }
}
 
defineCustomElement('gcl-drop-down', DropDown);