Skip to content

Commit fcd1cf5

Browse files
authored
feat(tooltip): add context data to tooltip (#1464)
1 parent c256074 commit fcd1cf5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

projects/components/src/tooltip/tooltip-content-container.component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ import { POPOVER_DATA } from '../popover/popover';
88
template: `
99
<div class="tooltip-container">
1010
<ng-container *ngIf="this.isComplexContent; else simpleContent">
11-
<ng-container *ngTemplateOutlet="this.content"> </ng-container>
11+
<ng-container *ngTemplateOutlet="this.templateRef; context: this.data.context"></ng-container>
1212
</ng-container>
1313
1414
<ng-template #simpleContent>
15-
{{ this.content }}
15+
{{ this.data.content }}
1616
</ng-template>
1717
</div>
1818
`
1919
})
2020
export class TooltipContentContainerComponent {
2121
public readonly isComplexContent: boolean;
22-
public constructor(@Inject(POPOVER_DATA) public readonly content: string | TemplateRef<unknown>) {
23-
this.isComplexContent = content instanceof TemplateRef;
22+
public readonly templateRef: TemplateRef<unknown>;
23+
24+
public constructor(
25+
@Inject(POPOVER_DATA) public readonly data: { content: string | TemplateRef<unknown>; context: unknown }
26+
) {
27+
this.isComplexContent = data.content instanceof TemplateRef;
28+
this.templateRef = data.content as TemplateRef<unknown>;
2429
}
2530
}

projects/components/src/tooltip/tooltip.directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export class TooltipDirective implements OnDestroy {
1616
@Input('htTooltip')
1717
public content?: TemplateRef<unknown> | string | number;
1818

19+
@Input('htTooltipContext')
20+
public context?: unknown;
21+
1922
private readonly mouseEnter$: Subject<MouseEvent> = new Subject();
2023
private readonly mouseLeave$: Subject<MouseEvent> = new Subject();
2124

@@ -55,7 +58,7 @@ export class TooltipDirective implements OnDestroy {
5558

5659
this.popover = this.popoverService.drawPopover({
5760
componentOrTemplate: TooltipContentContainerComponent,
58-
data: this.content,
61+
data: { content: this.content, context: this.context ?? {} },
5962
position: {
6063
type: PopoverPositionType.Relative,
6164
origin: this.host,

0 commit comments

Comments
 (0)