Skip to content

Commit 28befcf

Browse files
committed
refactor tooltip to carbon style
1 parent 105976d commit 28befcf

File tree

6 files changed

+72
-41
lines changed

6 files changed

+72
-41
lines changed

src/dialog/dialog.directive.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { DialogConfig } from "./dialog-config.interface";
2626
*/
2727
@Directive({
2828
selector: "[ibmDialog]",
29-
exportAs: "nDialog",
29+
exportAs: "ibmDialog",
3030
providers: [
3131
DialogService
3232
]
@@ -43,7 +43,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
4343
* @type {(string | TemplateRef<any>)}
4444
* @memberof DialogDirective
4545
*/
46-
@Input() nDialog: string | TemplateRef<any>;
46+
@Input() ibmDialog: string | TemplateRef<any>;
4747
/**
4848
* Defines how the Dialog is triggered.(Hover and click behave the same on mobile - both respond to a single tap)
4949
* @type {("click" | "hover" | "mouseenter")}
@@ -66,7 +66,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
6666
* @type {number}
6767
* @memberof DialogDirective
6868
*/
69-
@Input() gap = 10;
69+
@Input() gap = 0;
7070
/**
7171
* Value `true` sets Dialog be appened to the body (to break out of containers)
7272
* @type {boolean}
@@ -122,7 +122,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
122122
// set the config object (this can [and should!] be added to in child classes depending on what they need)
123123
this.dialogConfig = {
124124
title: this.title,
125-
content: this.nDialog,
125+
content: this.ibmDialog,
126126
placement: this.placement,
127127
parentRef: this.elementRef,
128128
gap: this.gap,
@@ -140,7 +140,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
140140
* @memberof DialogDirective
141141
*/
142142
ngOnInit() {
143-
// fix for safari highjacking clicks
143+
// fix for safari hijacking clicks
144144
document.body.firstElementChild.addEventListener("click", () => null, true);
145145

146146
// bind events for hovering or clicking the host

src/dialog/popover/popover-menu.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import { DialogService } from "./../dialog.service";
7373
*/
7474
@Directive({
7575
selector: "[ibmPopoverMenu]",
76-
exportAs: "nPopoverMenu",
76+
exportAs: "ibmPopoverMenu",
7777
providers: [
7878
DialogService
7979
]
@@ -90,7 +90,7 @@ export class PopoverMenuDirective extends DialogDirective {
9090
* @type {(string | TemplateRef<any>)}
9191
* @memberof PopoverMenuDirective
9292
*/
93-
@Input() nPopoverMenu: string | TemplateRef<any>;
93+
@Input() ibmPopoverMenu: string | TemplateRef<any>;
9494

9595
/**
9696
* Creates an instance of PopoverMenuDirective.
@@ -113,6 +113,6 @@ export class PopoverMenuDirective extends DialogDirective {
113113
* @memberof PopoverMenuDirective
114114
*/
115115
onDialogInit() {
116-
this.dialogConfig.content = this.nPopoverMenu;
116+
this.dialogConfig.content = this.ibmPopoverMenu;
117117
}
118118
}

src/dialog/popover/popover.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { DialogService } from "./../dialog.service";
6262
*/
6363
@Directive({
6464
selector: "[ibmPopover]",
65-
exportAs: "nPopover",
65+
exportAs: "ibmPopover",
6666
providers: [
6767
DialogService
6868
]
@@ -81,7 +81,7 @@ export class PopoverDirective extends DialogDirective {
8181
* @type {(string | TemplateRef<any>)}
8282
* @memberof PopoverDirective
8383
*/
84-
@Input() nPopover: string | TemplateRef<any>;
84+
@Input() ibmPopover: string | TemplateRef<any>;
8585

8686
/**
8787
* Creates an instance of PopoverDirective.
@@ -106,7 +106,7 @@ export class PopoverDirective extends DialogDirective {
106106
onDialogInit() {
107107
PopoverDirective.popoverCounter++;
108108
this.dialogConfig.compID = "popover-" + PopoverDirective.popoverCounter;
109-
this.dialogConfig.content = this.nPopover;
109+
this.dialogConfig.content = this.ibmPopover;
110110
this.dialogConfig.footer = this.footer;
111111
}
112112
}

src/dialog/tooltip/tooltip.component.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,39 @@ import { Dialog } from "./../dialog.component";
2424
selector: "ibm-tooltip",
2525
template: `
2626
<div
27-
[class]="getClass()"
28-
role="tooltip"
27+
#dialog
2928
[id]="dialogConfig.compID"
29+
role="tooltip"
3030
tabindex="0"
31-
#dialog>
32-
<div
33-
*ngIf="contentTemplate"
34-
role="tooltip">
35-
<ng-template
31+
class="bx--tooltip bx--tooltip--shown">
32+
<span class="bx--tooltip__caret" aria-hidden="true"></span>
33+
<ng-template
34+
*ngIf="hasContentTemplate"
3635
[ngTemplateOutlet]="dialogConfig.content"
37-
[ngTemplateOutletContext]="{popover: this, filter: dialogConfig.filter}">
38-
</ng-template>
39-
</div>
36+
[ngTemplateOutletContext]="{tooltip: this}">
37+
</ng-template>
4038
<p
41-
*ngIf="!contentTemplate"
42-
class="tooltip_text"
43-
role="tooltip">
39+
*ngIf="!hasContentTemplate">
4440
{{dialogConfig.content}}
4541
</p>
46-
<button
47-
*ngIf="dialogConfig.trigger==='click'"
48-
class="close--xs"
49-
(click)="doClose()"
50-
attr.aria-label="{{'DIALOG.TOOLTIP.CLOSE' | translate}}">
51-
<ibm-static-icon icon="x" size="sm" classList="close_icon"></ibm-static-icon>
52-
</button>
53-
<div class="arrow" aria-hidden="true"></div>
5442
</div>
5543
`
5644
})
5745
export class Tooltip extends Dialog {
58-
/**
59-
* Binds display property to `Tooltop` style attribute.
60-
* @memberof Tooltip
61-
*/
6246
@HostBinding("style.display") style = "inline-block";
6347
/**
6448
* Value is set to `true` if the `Tooltip` is to display a `TemplateRef` instead of a string.
6549
* @type {boolean}
6650
* @memberof Tooltip
6751
*/
68-
public contentTemplate: boolean;
52+
public hasContentTemplate = false;
6953

7054
/**
7155
* Check whether there is a template for the `Tooltip` content.
7256
* @memberof Tooltip
7357
*/
7458
onDialogInit() {
75-
this.contentTemplate = this.dialogConfig.content instanceof TemplateRef;
59+
this.hasContentTemplate = this.dialogConfig.content instanceof TemplateRef;
7660
}
7761

7862
/**

src/dialog/tooltip/tooltip.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { DialogService } from "./../dialog.service";
3232
*/
3333
@Directive({
3434
selector: "[ibmTooltip]",
35-
exportAs: "nTooltip",
35+
exportAs: "ibmTooltip",
3636
providers: [
3737
DialogService
3838
]
@@ -45,7 +45,7 @@ export class TooltipDirective extends DialogDirective {
4545
* @type {(string | TemplateRef<any>)}
4646
* @memberof TooltipDirective
4747
*/
48-
@Input() nTooltip: string | TemplateRef<any>;
48+
@Input() ibmTooltip: string | TemplateRef<any>;
4949
/**
5050
* Set tooltip type to reflect 'warning' or 'error' styles.
5151
*
@@ -87,7 +87,7 @@ export class TooltipDirective extends DialogDirective {
8787
onDialogInit() {
8888
TooltipDirective.tooltipCounter++;
8989
this.dialogConfig.compID = "tooltip-" + TooltipDirective.tooltipCounter;
90-
this.dialogConfig.content = this.nTooltip;
90+
this.dialogConfig.content = this.ibmTooltip;
9191
this.dialogConfig.type = this.tooltipType !== undefined ? this.tooltipType : this.type;
9292
this.elementRef.nativeElement.setAttribute("aria-describedby", this.dialogConfig.compID);
9393
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { storiesOf, moduleMetadata } from "@storybook/angular";
2+
import { withNotes } from "@storybook/addon-notes";
3+
import { action } from "@storybook/addon-actions";
4+
import { withKnobs, boolean, object } from "@storybook/addon-knobs/angular";
5+
6+
import { TranslateModule } from "@ngx-translate/core";
7+
8+
import { DialogModule } from "../../";
9+
10+
storiesOf("Tooltip", module)
11+
.addDecorator(
12+
moduleMetadata({
13+
imports: [
14+
DialogModule,
15+
TranslateModule.forRoot()
16+
],
17+
})
18+
)
19+
.addDecorator(withKnobs)
20+
.add("Basic", () => ({
21+
template: `
22+
<span
23+
ibmTooltip="tooltip text"
24+
trigger="hover"
25+
placement="bottom"
26+
style="cursor: pointer;">
27+
Hover for tooltip
28+
</span>
29+
`
30+
}))
31+
.add("With Template", () => ({
32+
template: `
33+
<ng-template #template let-tooltip="tooltip">
34+
<p>hello</p>
35+
<div>
36+
<button class="bx--btn bx--btn--primary" (click)="tooltip.doClose()">Close</button>
37+
</div>
38+
</ng-template>
39+
<span
40+
[ibmTooltip]="template"
41+
trigger="click"
42+
placement="bottom"
43+
style="cursor: pointer;">
44+
Click for tooltip
45+
</span>
46+
`
47+
}));

0 commit comments

Comments
 (0)