Skip to content

Commit

Permalink
Merge pull request #2854 from Licen-it/tooltip-data
Browse files Browse the repository at this point in the history
feat(Tooltip, TooltipDefinition): expose data input to be passed as template outlet context when rendering the tooltip
  • Loading branch information
zvonimirfras authored Apr 11, 2024
2 parents fa59676 + b9c5fc7 commit cb12fd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/button/icon-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default {
"danger--ghost"
],
control: { type: "select" },
name: "cdsButton"
name: "kind"
},
size: {
options: ["sm", "md", "lg", "xl", "2xl"],
Expand Down
6 changes: 5 additions & 1 deletion src/tooltip/definition-tooptip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
role="tooltip">
<span class="cds--popover-content cds--definition-tooltip">
<ng-container *ngIf="!isTemplate(description)">{{description}}</ng-container>
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description"></ng-template>
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description" [ngTemplateOutletContext]="{ $implicit: templateContext }"></ng-template>
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span>
</span>
<span *ngIf="!autoAlign" class="cds--popover-caret"></span>
Expand All @@ -57,6 +57,10 @@ export class TooltipDefinition extends PopoverContainer {
* The string or template content to be exposed by the tooltip.
*/
@Input() description: string | TemplateRef<any>;
/**
* Optional data for templates passed as implicit context
*/
@Input() templateContext: any;

constructor(
protected elementRef: ElementRef,
Expand Down
6 changes: 5 additions & 1 deletion src/tooltip/tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { PopoverContainer } from "carbon-components-angular/popover";
<ng-container *ngIf="!disabled">
<span class="cds--popover-content cds--tooltip-content">
<ng-container *ngIf="!isTemplate(description)">{{description}}</ng-container>
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description"></ng-template>
<ng-template *ngIf="isTemplate(description)" [ngTemplateOutlet]="description" [ngTemplateOutletContext]="{ $implicit: templateContext }"></ng-template>
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span>
</span>
<span *ngIf="!autoAlign" class="cds--popover-caret"></span>
Expand Down Expand Up @@ -69,6 +69,10 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked {
* The string or template content to be exposed by the tooltip.
*/
@Input() description: string | TemplateRef<any>;
/**
* Optional data for templates passed as implicit context
*/
@Input() templateContext: any

@ViewChild("contentWrapper") wrapper: ElementRef<HTMLSpanElement>;

Expand Down

0 comments on commit cb12fd9

Please sign in to comment.