Skip to content

Commit 49a2445

Browse files
committed
feat(tooltip): allow using custom strategies with arrow
1 parent ce01163 commit 49a2445

File tree

10 files changed

+207
-289
lines changed

10 files changed

+207
-289
lines changed

projects/igniteui-angular/src/lib/directives/tooltip/enums.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

projects/igniteui-angular/src/lib/directives/tooltip/public_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IgxTooltipDirective } from './tooltip.directive';
33

44
export * from './tooltip.directive';
55
export * from './tooltip-target.directive';
6-
export { TooltipPlacement } from './enums';
6+
export { TooltipPositionStrategy } from './tooltip.common';
77

88
/* NOTE: Tooltip directives collection for ease-of-use import in standalone components scenario */
99
export const IGX_TOOLTIP_DIRECTIVES = [

projects/igniteui-angular/src/lib/directives/tooltip/tooltip-target.directive.ts

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAnimation } from '@angular/animations';
21
import {
32
Directive, OnInit, OnDestroy, Output, ElementRef, Optional, ViewContainerRef, HostListener,
43
Input, EventEmitter, booleanAttribute, TemplateRef, ComponentRef, Renderer2, OnChanges, SimpleChanges,
@@ -9,14 +8,12 @@ import { Subject } from 'rxjs';
98
import { takeUntil } from 'rxjs/operators';
109
import { IgxNavigationService } from '../../core/navigation';
1110
import { IBaseEventArgs } from '../../core/utils';
12-
import { PositionSettings } from '../../services/public_api';
11+
import { PositionSettings } from '../../services/public_api';
1312
import { IgxToggleActionDirective } from '../toggle/toggle.directive';
1413
import { IgxTooltipComponent } from './tooltip.component';
1514
import { IgxTooltipDirective } from './tooltip.directive';
1615
import { IgxTooltipCloseButtonComponent } from './tooltip-close-button.component';
17-
import { fadeOut, scaleInCenter } from 'igniteui-angular/animations';
18-
import { TooltipPlacement } from './enums';
19-
import { TooltipPositionStrategy, PositionsMap } from './tooltip.common';
16+
import { TooltipPositionStrategy } from './tooltip.common';
2017

2118
export interface ITooltipShowEventArgs extends IBaseEventArgs {
2219
target: IgxTooltipTargetDirective;
@@ -83,41 +80,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
8380
@Input()
8481
public hideDelay = 300;
8582

86-
87-
/**
88-
* Where to place the tooltip relative to the target element. Default value is `bottom`.
89-
* ```html
90-
* <igx-icon [igxTooltipTarget]="tooltipRef" placement="bottom-start">info</igx-icon>
91-
* <span #tooltipRef="tooltip" igxTooltip>Hello there, I am a tooltip!</span>
92-
* ```
93-
*/
94-
@Input()
95-
public set placement(value: TooltipPlacement) {
96-
this._placement = value;
97-
98-
if (this._overlayDefaults && this.target) {
99-
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionsSettingsByPlacement, this);
100-
}
101-
}
102-
103-
public get placement(): TooltipPlacement {
104-
return this._placement;
105-
}
106-
107-
/** The offset of the tooltip from the target in pixels. Default value is 6. */
108-
@Input()
109-
public set offset(value: number) {
110-
this._offset = value;
111-
112-
if (this._overlayDefaults && this.target) {
113-
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionsSettingsByPlacement, this);
114-
}
115-
}
116-
117-
public get offset(): number {
118-
return this._offset;
119-
}
120-
12183
/**
12284
* Controls whether to display an arrow indicator for the tooltip.
12385
* Set to true to show the arrow. Default value is `false`.
@@ -214,6 +176,42 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
214176
return this._closeTemplate;
215177
}
216178

179+
/**
180+
* Get the position and animation settings used by the tooltip.
181+
* ```typescript
182+
* let positionSettings = this.tooltipTarget.positionSettings;
183+
* ```
184+
*/
185+
@Input()
186+
public get positionSettings(): PositionSettings {
187+
return this._positionSettings;
188+
}
189+
190+
/**
191+
* Set the position and animation settings used by the tooltip.
192+
* ```html
193+
* <igx-icon [igxTooltipTarget]="tooltipRef" [positionSettings]="newPositionSettings">info</igx-icon>
194+
* <span #tooltipRef="tooltip" igxTooltip>Hello there, I am a tooltip!</span>
195+
* ```
196+
* ```typescript
197+
*
198+
* import { PositionSettings, HorizontalAlignment, VerticalAlignment } from 'igniteui-angular';
199+
* ...
200+
* public newPositionSettings: PositionSettings = {
201+
* horizontalDirection: HorizontalAlignment.Right,
202+
* horizontalStartPoint: HorizontalAlignment.Left,
203+
* verticalDirection: VerticalAlignment.Top,
204+
* verticalStartPoint: VerticalAlignment.Top,
205+
* };
206+
* ```
207+
*/
208+
public set positionSettings(settings: PositionSettings) {
209+
this._positionSettings = settings;
210+
if (this._overlayDefaults) {
211+
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionSettings);
212+
}
213+
}
214+
217215
/**
218216
* Specifies if the tooltip should not show when hovering its target with the mouse. (defaults to false)
219217
* While setting this property to 'true' will disable the user interactions that shows/hides the tooltip,
@@ -328,11 +326,10 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
328326
private _autoHideDelay = 180;
329327
private _isForceClosed = false;
330328
private _hasArrow = false;
331-
private _offset = 6;
332-
private _placement: TooltipPlacement = TooltipPlacement.bottom;
333329
private _closeButtonRef?: ComponentRef<IgxTooltipCloseButtonComponent>;
334330
private _closeTemplate: TemplateRef<any>;
335331
private _sticky = false;
332+
private _positionSettings: PositionSettings;
336333

337334
constructor(
338335
private _element: ElementRef,
@@ -413,7 +410,7 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
413410
public override ngOnInit() {
414411
super.ngOnInit();
415412

416-
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionsSettingsByPlacement, this);
413+
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionSettings);
417414
this._overlayDefaults.closeOnOutsideClick = false;
418415
this._overlayDefaults.closeOnEscape = true;
419416

@@ -473,15 +470,6 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
473470
return Object.assign({}, this._overlayDefaults, this.overlaySettings);
474471
}
475472

476-
private get _positionsSettingsByPlacement(): PositionSettings {
477-
const positions = PositionsMap.get(this.placement);
478-
const animations = {
479-
openAnimation: useAnimation(scaleInCenter, { params: { duration: '150ms' } }),
480-
closeAnimation: useAnimation(fadeOut, { params: { duration: '75ms' } })
481-
}
482-
return Object.assign({}, animations, positions);
483-
}
484-
485473
private _checkOutletAndOutsideClick(): void {
486474
if (this.outlet) {
487475
this._overlayDefaults.outlet = this.outlet;

0 commit comments

Comments
 (0)