2022-07-01 14:44:05 +02:00
|
|
|
import {Component, ElementRef, Input, ViewChild} from "@angular/core";
|
2023-07-26 10:49:50 +02:00
|
|
|
import {MobileDropdownComponent} from "../mobile-dropdown/mobile-dropdown.component";
|
2022-06-30 12:40:37 +02:00
|
|
|
|
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'dropdown-filter',
|
|
|
|
template: `
|
2023-07-26 10:49:50 +02:00
|
|
|
<button #toggle class="uk-button uk-button-default uk-flex uk-flex-middle"
|
2022-07-01 14:44:05 +02:00
|
|
|
[class.uk-disabled]="disabled" [disabled]="disabled">
|
2022-06-30 12:40:37 +02:00
|
|
|
<span>{{name}}<span *ngIf="count > 0">({{count}})</span></span>
|
2022-07-01 14:44:05 +02:00
|
|
|
<icon [flex]="true" class="uk-margin-xsmall-left" [name]="'expand_' + (isOpen?'less':'more')"></icon>
|
2022-06-30 12:40:37 +02:00
|
|
|
</button>
|
2023-07-26 10:49:50 +02:00
|
|
|
<div *ngIf="!isMobile" #dropdownElement class="uk-dropdown"
|
2022-07-18 17:56:59 +02:00
|
|
|
[class.uk-height-max-large]="overflow" [class.uk-overflow-auto]="overflow"
|
|
|
|
[ngStyle]="dropdownMinWidth?{'min-width.px': dropdownMinWidth}:''"
|
|
|
|
[ngClass]="dropdownClass" uk-dropdown="mode: click; delay-hide: 0;">
|
2022-07-13 19:25:19 +02:00
|
|
|
<div>
|
2023-07-26 10:49:50 +02:00
|
|
|
<ng-container *ngTemplateOutlet="content"></ng-container>
|
2022-07-13 19:25:19 +02:00
|
|
|
</div>
|
2022-06-30 12:40:37 +02:00
|
|
|
</div>
|
2023-08-23 15:52:21 +02:00
|
|
|
<mobile-dropdown *ngIf="isMobile" #mobileDropdown [toggle]="toggle">
|
2023-07-26 10:49:50 +02:00
|
|
|
<div [ngClass]="dropdownClass">
|
|
|
|
<ng-container *ngTemplateOutlet="content"></ng-container>
|
|
|
|
</div>
|
|
|
|
</mobile-dropdown>
|
|
|
|
<ng-template #content>
|
|
|
|
<ng-content></ng-content>
|
|
|
|
</ng-template>
|
2022-06-30 12:40:37 +02:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class DropdownFilterComponent {
|
|
|
|
@Input()
|
|
|
|
public name;
|
|
|
|
@Input()
|
|
|
|
public count: number = 0;
|
|
|
|
@Input()
|
|
|
|
public dropdownClass: string;
|
2022-07-01 14:44:05 +02:00
|
|
|
@Input()
|
2022-07-18 17:56:59 +02:00
|
|
|
public dropdownMinWidth: number;
|
|
|
|
@Input()
|
|
|
|
public overflow: boolean = true;
|
|
|
|
@Input()
|
2022-07-01 14:44:05 +02:00
|
|
|
public disabled = false;
|
2023-07-26 10:49:50 +02:00
|
|
|
@Input()
|
|
|
|
public isMobile: boolean = false;
|
2022-07-01 14:44:05 +02:00
|
|
|
@ViewChild("dropdownElement") dropdownElement: ElementRef;
|
2023-07-26 10:49:50 +02:00
|
|
|
@ViewChild("mobileDropdown") mobileDropdown: MobileDropdownComponent;
|
|
|
|
|
2022-07-01 14:44:05 +02:00
|
|
|
get isOpen() {
|
2023-07-26 10:49:50 +02:00
|
|
|
if(this.isMobile) {
|
|
|
|
return this.mobileDropdown?.opened;
|
|
|
|
} else {
|
|
|
|
return (typeof document !== 'undefined') && this.dropdownElement && UIkit.dropdown(this.dropdownElement.nativeElement).isActive();
|
|
|
|
}
|
2022-06-30 12:40:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
closeDropdown() {
|
2023-07-26 10:49:50 +02:00
|
|
|
if(this.isMobile) {
|
|
|
|
this.mobileDropdown.close();
|
|
|
|
} else {
|
|
|
|
UIkit.dropdown(this.dropdownElement.nativeElement).hide();
|
|
|
|
}
|
2022-06-30 12:40:37 +02:00
|
|
|
}
|
|
|
|
}
|