Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import { POPOVER_DATA } from '../popover/popover';
template: `
<div class="tooltip-container">
<ng-container *ngIf="this.isComplexContent; else simpleContent">
<ng-container *ngTemplateOutlet="this.content"> </ng-container>
<ng-container *ngTemplateOutlet="this.templateRef; context: this.data.context"></ng-container>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we want this to be used as context directly, or made $implicit?

Copy link
Contributor Author

@adisreyaj adisreyaj Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK Can add$implicit, but current way gives more control to the parent. What do you think is best here?

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's equivalent in terms of functionality, but I think implicit is easier to use if I'm understanding correctly. Take an obj like

{
  "a": "a-value",
  "b": "b-value"
}

With $implicit, you'd write

<ng-template let-data>
   A is {{ data.a }} and B is {{ data.b }}
</ng-template>

In the current form, wouldn't you have to let each value on the context individually and by name?

<ng-template let-a="a" let-b="b">
   A is {{ a }} and B is {{ b }}
</ng-template>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It's easier with $implicit.

But what I meant was:

<div [htTooltip]="tpl" [htTooltipContext]="{$implicit: data, index: i}">Something</div>

Since we have mentioned context as input, it can take an object which may or may not contain $implicit key. We are giving that flexibility to the parent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, I hate to expose using $implicit since I suspect most devs are unfamiliar with it, but since the templatRef is also there, it's not like it's under the hood. Your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah...that's exactly my thought.

</ng-container>

<ng-template #simpleContent>
{{ this.content }}
{{ this.data.content }}
</ng-template>
</div>
`
})
export class TooltipContentContainerComponent {
public readonly isComplexContent: boolean;
public constructor(@Inject(POPOVER_DATA) public readonly content: string | TemplateRef<unknown>) {
this.isComplexContent = content instanceof TemplateRef;
public readonly templateRef: TemplateRef<unknown>;

public constructor(
@Inject(POPOVER_DATA) public readonly data: { content: string | TemplateRef<unknown>; context: unknown }
) {
this.isComplexContent = data.content instanceof TemplateRef;
this.templateRef = data.content as TemplateRef<unknown>;
}
}
5 changes: 4 additions & 1 deletion projects/components/src/tooltip/tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class TooltipDirective implements OnDestroy {
@Input('htTooltip')
public content?: TemplateRef<unknown> | string | number;

@Input('htTooltipContext')
public context?: unknown;

private readonly mouseEnter$: Subject<MouseEvent> = new Subject();
private readonly mouseLeave$: Subject<MouseEvent> = new Subject();

Expand Down Expand Up @@ -55,7 +58,7 @@ export class TooltipDirective implements OnDestroy {

this.popover = this.popoverService.drawPopover({
componentOrTemplate: TooltipContentContainerComponent,
data: this.content,
data: { content: this.content, context: this.context ?? {} },
position: {
type: PopoverPositionType.Relative,
origin: this.host,
Expand Down