@duoduo-oba/ng-devui
Version:
DevUI components based on Angular
418 lines (410 loc) • 14.6 kB
JavaScript
import { Component, ElementRef, Renderer2, Input, HostBinding, HostListener, Directive, ComponentFactoryResolver, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PositionService, PositioningModule } from '@duoduo-oba/ng-devui/position';
import { fromEvent } from 'rxjs';
import { directionFadeInOut } from '@duoduo-oba/ng-devui/utils';
import { PortalModule } from '@duoduo-oba/ng-devui/portal';
import { OverlayContainerRef } from '@duoduo-oba/ng-devui/overlay-container';
import { WindowRef, DocumentRef } from '@duoduo-oba/ng-devui/window-ref';
/**
* @fileoverview added by tsickle
* Generated from: tooltip.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TooltipComponent = /** @class */ (function () {
function TooltipComponent(positionService, tooltip, renderer2) {
this.positionService = positionService;
this.tooltip = tooltip;
this.renderer2 = renderer2;
this.position = 'bottom';
this.showAnimate = false;
this.animateState = this.showAnimate ? 'void' : 'visible';
this.display = 'block';
}
Object.defineProperty(TooltipComponent.prototype, "class", {
get: /**
* @return {?}
*/
function () {
return 'devui-tooltip ' + this.position;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TooltipComponent.prototype, "state", {
get: /**
* @return {?}
*/
function () {
return this.animateState;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
TooltipComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
var _this = this;
this.updatePosition();
this.scrollElement = this.positionService.getScrollParent(this.triggerElementRef.nativeElement);
this._onScroll = fromEvent((this.scrollElement || window), 'scroll')
.subscribe((/**
* @return {?}
*/
function () {
_this.updatePosition();
}));
};
/**
* @return {?}
*/
TooltipComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this._onScroll) {
this._onScroll.unsubscribe();
}
};
/**
* @return {?}
*/
TooltipComponent.prototype.onShow = /**
* @return {?}
*/
function () {
this.animateState = this.position;
};
/**
* @return {?}
*/
TooltipComponent.prototype.onHide = /**
* @return {?}
*/
function () {
this.animateState = 'void';
};
// will be overwrite by tooltip directive
// will be overwrite by tooltip directive
/**
* @return {?}
*/
TooltipComponent.prototype.onHidden =
// will be overwrite by tooltip directive
/**
* @return {?}
*/
function () {
};
/**
* @param {?} event
* @return {?}
*/
TooltipComponent.prototype.onAnimationEnd = /**
* @param {?} event
* @return {?}
*/
function (event) {
if (event.toState === 'void') {
this.onHidden();
}
};
/**
* @return {?}
*/
TooltipComponent.prototype.updatePosition = /**
* @return {?}
*/
function () {
// 解决tooltip自身大小导致出现滚动条,影响位置计算
this.renderer2.setStyle(this.tooltip.nativeElement, 'visibility', 'hidden');
this.renderer2.setStyle(this.tooltip.nativeElement, 'transform', 'translate(0, -99999px)');
/** @type {?} */
var rect = this.positionService.positionElements(this.triggerElementRef.nativeElement, this.tooltip.nativeElement, this.position, true);
this.renderer2.setStyle(this.tooltip.nativeElement, 'left', rect.left + "px");
this.renderer2.setStyle(this.tooltip.nativeElement, 'top', rect.top + "px");
// 移除样式
this.renderer2.setStyle(this.tooltip.nativeElement, 'visibility', null);
this.renderer2.setStyle(this.tooltip.nativeElement, 'transform', null);
};
TooltipComponent.decorators = [
{ type: Component, args: [{
selector: 'd-tooltip',
template: "<div class=\"devui-tooltip-arrow\"></div>\r\n<div class=\"devui-tooltip-inner\" [innerHTML]=\"content\"></div>\r\n",
animations: [
directionFadeInOut
],
styles: [":host-context(.devui-tooltip){position:absolute;z-index:1070;display:block;font-style:normal;font-weight:400;line-height:1.42857143;line-break:auto;text-align:left;text-align:start;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-break:normal;word-spacing:normal;word-wrap:normal;white-space:normal;font-size:12px;opacity:1}:host-context(.devui-tooltip).top{margin-top:-5px;padding:0;box-shadow:-5px 5px 20px 0 rgba(37,43,58,.2)}:host-context(.devui-tooltip).top .devui-tooltip-arrow{bottom:-5px;left:50%;margin-left:-5px;border-width:5px 5px 0;border-top-color:#464d6e}:host-context(.devui-tooltip).bottom{margin-top:5px;padding:0;box-shadow:5px -5px 20px 0 rgba(37,43,58,.2)}:host-context(.devui-tooltip).bottom .devui-tooltip-arrow{top:-5px;left:50%;margin-left:-5px;border-width:0 5px 5px;border-bottom-color:#464d6e}:host-context(.devui-tooltip).left{margin-left:-5px;padding:0;box-shadow:5px -5px 20px 0 rgba(37,43,58,.2)}:host-context(.devui-tooltip).left .devui-tooltip-arrow{top:50%;right:-5px;margin-top:-5px;border-width:5px 0 5px 5px;border-left-color:#464d6e}:host-context(.devui-tooltip).right{margin-left:5px;padding:0;box-shadow:-5px 5px 20px 0 rgba(37,43,58,.2)}:host-context(.devui-tooltip).right .devui-tooltip-arrow{top:50%;left:-5px;margin-top:-5px;border-width:5px 5px 5px 0;border-right-color:#464d6e}:host-context(.devui-tooltip) .devui-tooltip-inner{max-width:200px;padding:5px 10px;font-size:14px;color:#dfe1e6;letter-spacing:0;line-height:20px;background:#464d6e;box-shadow:none;overflow-wrap:break-word;text-align:start}:host-context(.devui-tooltip) .devui-tooltip-arrow{display:block;position:absolute;width:0;height:0;border-color:transparent;border-style:solid}"]
}] }
];
/** @nocollapse */
TooltipComponent.ctorParameters = function () { return [
{ type: PositionService },
{ type: ElementRef },
{ type: Renderer2 }
]; };
TooltipComponent.propDecorators = {
content: [{ type: Input }],
position: [{ type: Input }],
triggerElementRef: [{ type: Input }],
showAnimate: [{ type: Input }],
display: [{ type: HostBinding, args: ['style.display',] }],
class: [{ type: HostBinding, args: ['class',] }],
state: [{ type: HostBinding, args: ['@directionFadeInOut',] }],
onAnimationEnd: [{ type: HostListener, args: ['@directionFadeInOut.done', ['$event'],] }]
};
return TooltipComponent;
}());
if (false) {
/** @type {?} */
TooltipComponent.prototype.content;
/** @type {?} */
TooltipComponent.prototype.position;
/** @type {?} */
TooltipComponent.prototype.triggerElementRef;
/** @type {?} */
TooltipComponent.prototype.showAnimate;
/** @type {?} */
TooltipComponent.prototype.scrollElement;
/** @type {?} */
TooltipComponent.prototype.animateState;
/** @type {?} */
TooltipComponent.prototype.display;
/** @type {?} */
TooltipComponent.prototype._onScroll;
/**
* @type {?}
* @private
*/
TooltipComponent.prototype.positionService;
/**
* @type {?}
* @private
*/
TooltipComponent.prototype.tooltip;
/**
* @type {?}
* @private
*/
TooltipComponent.prototype.renderer2;
}
/**
* @fileoverview added by tsickle
* Generated from: tooltip.directive.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TooltipDirective = /** @class */ (function () {
function TooltipDirective(triggerElementRef, overlayContainerRef, componentFactoryResolver) {
this.triggerElementRef = triggerElementRef;
this.overlayContainerRef = overlayContainerRef;
this.componentFactoryResolver = componentFactoryResolver;
this.position = 'bottom';
}
/**
* @return {?}
*/
TooltipDirective.prototype.onMouseEnter = /**
* @return {?}
*/
function () {
this.show();
};
/**
* @return {?}
*/
TooltipDirective.prototype.onMouseLeave = /**
* @return {?}
*/
function () {
this.hide();
};
/**
* @return {?}
*/
TooltipDirective.prototype.onFocus = /**
* @return {?}
*/
function () {
this.show();
};
/**
* @return {?}
*/
TooltipDirective.prototype.onBlur = /**
* @return {?}
*/
function () {
this.hide();
};
/**
* @return {?}
*/
TooltipDirective.prototype.createTooltip = /**
* @return {?}
*/
function () {
this.tooltipComponentRef = this.overlayContainerRef.createComponent(this.componentFactoryResolver.resolveComponentFactory(TooltipComponent));
Object.assign(this.tooltipComponentRef.instance, {
content: this.content,
position: this.position,
showAnimate: this.showAnimate,
triggerElementRef: this.triggerElementRef,
});
};
/**
* @return {?}
*/
TooltipDirective.prototype.show = /**
* @return {?}
*/
function () {
if (!this.content) {
return;
}
if (this.tooltipComponentRef) {
this.destroy();
}
this.createTooltip();
if (this.showAnimate) {
this.tooltipComponentRef.instance.onShow();
}
};
/**
* @return {?}
*/
TooltipDirective.prototype.destroy = /**
* @return {?}
*/
function () {
if (this.tooltipComponentRef) {
this.tooltipComponentRef.destroy();
this.tooltipComponentRef = null;
}
};
/**
* @return {?}
*/
TooltipDirective.prototype.hide = /**
* @return {?}
*/
function () {
var _this = this;
if (this.tooltipComponentRef) {
this.tooltipComponentRef.instance.onHide();
if (!this.showAnimate) {
this.destroy();
return;
}
this.tooltipComponentRef.instance.onHidden = (/**
* @return {?}
*/
function () {
_this.destroy();
});
}
};
/**
* @return {?}
*/
TooltipDirective.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroy();
};
TooltipDirective.decorators = [
{ type: Directive, args: [{
selector: '[dTooltip]',
exportAs: 'dTooltip',
},] }
];
/** @nocollapse */
TooltipDirective.ctorParameters = function () { return [
{ type: ElementRef },
{ type: OverlayContainerRef },
{ type: ComponentFactoryResolver }
]; };
TooltipDirective.propDecorators = {
content: [{ type: Input }],
position: [{ type: Input }],
showAnimate: [{ type: Input }],
onMouseEnter: [{ type: HostListener, args: ['mouseenter',] }],
onMouseLeave: [{ type: HostListener, args: ['mouseleave',] }],
onFocus: [{ type: HostListener, args: ['focus',] }],
onBlur: [{ type: HostListener, args: ['blur',] }]
};
return TooltipDirective;
}());
if (false) {
/** @type {?} */
TooltipDirective.prototype.content;
/** @type {?} */
TooltipDirective.prototype.position;
/** @type {?} */
TooltipDirective.prototype.showAnimate;
/** @type {?} */
TooltipDirective.prototype.tooltipComponentRef;
/**
* @type {?}
* @private
*/
TooltipDirective.prototype.triggerElementRef;
/**
* @type {?}
* @private
*/
TooltipDirective.prototype.overlayContainerRef;
/**
* @type {?}
* @private
*/
TooltipDirective.prototype.componentFactoryResolver;
}
/**
* @fileoverview added by tsickle
* Generated from: tooltip.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TooltipModule = /** @class */ (function () {
function TooltipModule() {
}
TooltipModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule,
PortalModule,
PositioningModule
],
exports: [TooltipComponent, TooltipDirective],
declarations: [TooltipComponent, TooltipDirective],
providers: [
WindowRef,
DocumentRef,
OverlayContainerRef,
],
entryComponents: [TooltipComponent]
},] }
];
return TooltipModule;
}());
/**
* @fileoverview added by tsickle
* Generated from: tooltip.types.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-devui-tooltip.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { TooltipComponent, TooltipDirective, TooltipModule };
//# sourceMappingURL=ng-devui-tooltip.js.map