import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; import { MatTooltip, MatTooltipModule } from '@angular/material/tooltip'; import { CircleButtonType, CircleButtonTypes } from '../types/circle-button.type'; import { IqserTooltipPosition, IqserTooltipPositions, randomString } from '../../utils'; import { NgIf } from '@angular/common'; import { MatLegacyButtonModule as MatButtonModule } from '@angular/material/legacy-button'; import { MatIconModule } from '@angular/material/icon'; import { StopPropagationDirective } from '../../directives'; @Component({ selector: 'iqser-circle-button [icon]', templateUrl: './circle-button.component.html', styleUrls: ['./circle-button.component.scss'], standalone: true, imports: [MatTooltipModule, MatIconModule, NgIf, MatButtonModule, StopPropagationDirective], }) export class CircleButtonComponent implements OnInit { readonly circleButtonTypes = CircleButtonTypes; @Input() buttonId = `${randomString()}-circle-button`; @Input() icon!: string; @Input() tooltip?: string; @Input() tooltipClass?: string; @Input() showDot = false; @Input() tooltipPosition: IqserTooltipPosition = IqserTooltipPositions.above; @Input() disabled = false; @Input() type: CircleButtonType = CircleButtonTypes.default; @Input() greySelected = false; @Input() helpModeButton = false; @Input() removeTooltip = false; @Input() isSubmit = false; @Input() size = 34; @Input() iconSize = 14; @Output() readonly action = new EventEmitter(); @ViewChild(MatTooltip) private readonly _matTooltip!: MatTooltip; constructor(private readonly _elementRef: ElementRef) {} ngOnInit(): void { (this._elementRef.nativeElement as HTMLElement).style.setProperty('--size', `${this.size}px`); (this._elementRef.nativeElement as HTMLElement).style.setProperty('--iconSize', `${this.iconSize}px`); } performAction($event: MouseEvent) { if (this.removeTooltip) { this._matTooltip.hide(); // Timeout to allow tooltip to disappear first, // useful when removing an item from the list without a confirmation dialog setTimeout(() => this.action.emit($event)); } else { this.action.emit($event); } } }