ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
74 lines (64 loc) • 1.87 kB
text/typescript
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
Input,
OnChanges,
OnInit,
Renderer2,
TemplateRef,
ViewEncapsulation,
} from '@angular/core';
import { InputNumber, NumberInput } from '@ohayo/util';
export class QuickMenuComponent implements OnInit, OnChanges {
static ngAcceptInputType_top: NumberInput;
static ngAcceptInputType_width: NumberInput;
constructor(private cdr: ChangeDetectorRef, private el: ElementRef, private render: Renderer2) { }
ctrlStyle: { [key: string]: string } = {};
icon: string | TemplateRef<void> = 'question-circle';
top = 120;
width = 200;
bgColor: string;
borderColor: string;
private show = false;
private initFlag = false;
_click(): void {
this.show = !this.show;
this.setStyle();
}
private setStyle(): void {
this.ctrlStyle = {
'background-color': this.bgColor,
'border-color': this.borderColor,
};
const res: string[] = [`top:${this.top}px`, `width:${this.width}px`, `margin-right:-${this.show ? 0 : this.width}px`];
if (this.bgColor) {
res.push(`background-color:${this.bgColor}`);
}
if (this.borderColor) {
res.push(`border-color:${this.borderColor}`);
}
this.render.setAttribute(this.el.nativeElement, 'style', res.join(';'));
this.cdr.detectChanges();
}
ngOnInit(): void {
this.initFlag = true;
this.setStyle();
}
ngOnChanges(): void {
if (this.initFlag) this.setStyle();
}
}