-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module:tooltip): support usage like: <a nz-tooltip="This is a pr…
- Loading branch information
1 parent
4a4e393
commit b4824d9
Showing
7 changed files
with
119 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
import { Directive, ElementRef } from '@angular/core'; | ||
import { | ||
Directive, | ||
ElementRef, | ||
ViewContainerRef, | ||
ComponentFactoryResolver, | ||
Renderer2 | ||
} from '@angular/core'; | ||
import { NzPopconfirmComponent } from './nz-popconfirm.component'; | ||
import { NzTooltipDirective } from '../tooltip/nz-tooltip.directive'; | ||
|
||
@Directive({ | ||
selector: '[nz-popconfirm]', | ||
}) | ||
export class NzPopconfirmDirective { | ||
constructor(public elementRef: ElementRef) { | ||
export class NzPopconfirmDirective extends NzTooltipDirective { | ||
constructor( | ||
elementRef: ElementRef, | ||
hostView: ViewContainerRef, | ||
resolver: ComponentFactoryResolver, | ||
renderer: Renderer2, | ||
tooltip: NzPopconfirmComponent) { | ||
super(elementRef, hostView, resolver, renderer, tooltip); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
import { Directive, ElementRef } from '@angular/core'; | ||
import { | ||
Directive, | ||
ElementRef, | ||
ViewContainerRef, | ||
ComponentFactoryResolver, | ||
Renderer2 | ||
} from '@angular/core'; | ||
import { NzPopoverComponent } from './nz-popover.component'; | ||
import { NzTooltipDirective } from '../tooltip/nz-tooltip.directive'; | ||
|
||
@Directive({ | ||
selector: '[nz-popover]', | ||
}) | ||
export class NzPopoverDirective { | ||
constructor(public elementRef: ElementRef) { | ||
export class NzPopoverDirective extends NzTooltipDirective { | ||
constructor( | ||
elementRef: ElementRef, | ||
hostView: ViewContainerRef, | ||
resolver: ComponentFactoryResolver, | ||
renderer: Renderer2, | ||
tooltip: NzPopoverComponent) { | ||
super(elementRef, hostView, resolver, renderer, tooltip); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,76 @@ | ||
import { Directive, ElementRef, HostBinding } from '@angular/core'; | ||
import { | ||
Directive, | ||
Input, | ||
SimpleChanges, | ||
AfterViewInit, | ||
ViewContainerRef, | ||
ComponentFactoryResolver, | ||
ElementRef, | ||
HostBinding, | ||
Optional, | ||
Renderer2 | ||
} from '@angular/core'; | ||
import { NzToolTipComponent } from './nz-tooltip.component'; | ||
|
||
@Directive({ | ||
selector: '[nz-tooltip]', | ||
}) | ||
export class NzTooltipDirective { | ||
export class NzTooltipDirective implements AfterViewInit { | ||
// [NOTE] Here hard coded, and nzTitle used only under NzTooltipDirective currently. | ||
// The inherited class such as NzPopconfirmDirective should override this property if want using this property. | ||
@Input('nz-tooltip') | ||
get nzTitle() { | ||
return this.tooltip.nzTitle; | ||
} | ||
set nzTitle(title: string) { | ||
if (this.isDynamicTooltip) { | ||
this.tooltip.nzTitle = title; | ||
} | ||
} | ||
|
||
@HostBinding('class.ant-tooltip-open') isTooltipOpen; | ||
|
||
constructor(public elementRef: ElementRef) { | ||
private tooltip: NzToolTipComponent; | ||
private isDynamicTooltip = false; // Indicate whether current tooltip is dynamic created | ||
|
||
constructor( | ||
public elementRef: ElementRef, | ||
private hostView: ViewContainerRef, | ||
private resolver: ComponentFactoryResolver, | ||
private renderer: Renderer2, | ||
@Optional() tooltip: NzToolTipComponent) { | ||
// Support faster tooltip mode: <a nz-tooltip="xxx"></a>. [NOTE] Used only under NzTooltipDirective currently. | ||
if (!tooltip) { | ||
const factory = this.resolver.resolveComponentFactory(NzToolTipComponent); | ||
tooltip = this.hostView.createComponent(factory).instance; | ||
this.isDynamicTooltip = true; | ||
} | ||
tooltip.setOverlayOrigin(this); | ||
this.tooltip = tooltip; | ||
} | ||
|
||
ngAfterViewInit() { | ||
if (this.tooltip.nzTrigger === 'hover') { | ||
this.renderer.listen(this.elementRef.nativeElement, 'mouseenter', () => this.show()); | ||
this.renderer.listen(this.elementRef.nativeElement, 'mouseleave', () => this.hide()); | ||
} else if (this.tooltip.nzTrigger === 'focus') { | ||
this.renderer.listen(this.elementRef.nativeElement, 'focus', () => this.show()); | ||
this.renderer.listen(this.elementRef.nativeElement, 'blur', () => this.hide()); | ||
} else if (this.tooltip.nzTrigger === 'click') { | ||
this.renderer.listen(this.elementRef.nativeElement, 'click', (e) => { | ||
e.preventDefault(); | ||
this.show() | ||
}); | ||
} | ||
} | ||
|
||
private show() { | ||
this.tooltip.show(); | ||
this.isTooltipOpen = true; | ||
} | ||
|
||
private hide() { | ||
this.tooltip.hide(); | ||
this.isTooltipOpen = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters