All files / components/upp-dropdown upp-dropdown.ts

0% Statements 0/23
100% Branches 0/0
0% Functions 0/3
0% Lines 0/16

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                                                                                                                                                                                 
import { Component } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';
import { ContentChild } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
 
/**
 * Represents the title of the dropdown. This component is used to project content as the dropdown's title.
 */
@Component({
    selector: 'upp-dropdown-title',
    template: `
        <ion-item lines="none">
            <ion-label>
                <ng-content></ng-content>
            </ion-label>
        </ion-item>
    `,
    styleUrls: [ './upp-dropdown.scss' ]
})
export class UppDropdownTitleComponent {
    // nothing to do
}
 
/**
 * Represents a content section in the dropdown. This component is used to project content
 * as part of the dropdown menu options.
 */
@Component({
    selector: 'upp-dropdown-content',
    template: `<ng-content></ng-content>`,
    styleUrls: [ './upp-dropdown.scss' ]
})
export class UppDropdownContentComponent {
    // nothing to do
}
 
/**
 * Represents a visual separator in the dropdown. This component is used to render a styled line
 * separating sections within the dropdown menu.
 */
@Component({
    selector: 'upp-dropdown-separate',
    template: `<div style="clear:both; height: 1px; margin: 8px 0px; border-bottom: 5px solid var(--ion-color-light)"></div>`,
    styleUrls: [],
})
export class UppDropdownSplitComponent {
    // nothing to do
}
 
/**
 * Main dropdown component that handles the projection and rendering of dropdown content, separators, and title.
 * The component preserves the order of the child elements and dynamically renders them.
 */
@Component({
    selector: 'upp-dropdown',
    changeDetection: ChangeDetectionStrategy.OnPush,
    templateUrl: './upp-dropdown.html',
    styleUrls: ['./upp-dropdown.scss']
})
export class UppDropdownComponent {
    /** Indicates whether the dropdown is expanded or collapsed. */
    @Input() expand = false;
    /** Emits an event when the dropdown is closed. */
    @Output() Closed = new EventEmitter<void>();
 
    /**
     * Constructor for the UppDropdownComponent.
     * @param change ChangeDetectorRef for triggering manual change detection.
     * @param renderer Renderer2 for DOM manipulation.
     */    
    constructor(private change: ChangeDetectorRef){
        // nothing to do
    }
 
    @ContentChild(UppDropdownTitleComponent) _title: UppDropdownTitleComponent | null = null;
    get HasTitle(): boolean {
        return !!this._title;
    }
 
    /**
     * Closes the dropdown and triggers the `OnClosed` event.
     */    
    OnCloseDropdown() : void {
        this.expand = false;
        this.change.markForCheck();
        this.Closed.next();
    }
}