Skip to content

Commit

Permalink
add basic tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
IceMaD committed Feb 19, 2016
1 parent 2e0a4e9 commit 3af1c1d
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 21 deletions.
21 changes: 21 additions & 0 deletions app/sass/component/global/_tooltip.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
+component(tooltip)

position: fixed
background-color: $granny-green
color: $snow-white
padding: .5em 1.5em
border-radius: 3px
transform: translateX(-50%)

&:after

content: ''
position: absolute
left: 50%
top: 100%
transform: translateX(-50%)
width: 0
height: 0
border-style: solid
border-width: 10px 10px 0 10px
border-color: $granny-green transparent transparent transparent
18 changes: 0 additions & 18 deletions app/sass/style.sass

This file was deleted.

19 changes: 19 additions & 0 deletions app/sass/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import 'ext/reset';
@import 'ext/variables';
@import 'ext/mixins';
@import 'ext/fonts';

@import 'component/global/container';
@import 'component/global/button';
@import 'component/global/button-bar';
@import 'component/global/message';
@import 'component/global/tooltip';

@import 'component/tree/tree';
@import 'component/tree/node';

@import 'component/flash/flash-box';
@import 'component/flash/flash-message';

@import 'component/team/team';
@import 'component/team/team-form';
1 change: 1 addition & 0 deletions app/templates/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'--highlighted': node.highlighted,
'--winner': node.last && node.team
}"
tooltip="Hello"
[overlay]="node"
(click)="node.win()">
{{ node.team ? node.team.name : '-' }}</button>
Expand Down
1 change: 0 additions & 1 deletion app/templates/team-management.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@

<ul>
<li>Edit Team name</li>
<li>Winner in gold</li>
<li>Remove all team button</li>
</ul>
3 changes: 2 additions & 1 deletion app/ts/Components/NodeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {Component} from "angular2/core";
import {Input} from "angular2/core";
import {NodeModel} from "../Models/NodeModel";
import {OverlayDirective} from "../Directives/OverlayDirective";
import {TooltipDirective} from "../Directives/TooltipDirective";

@Component({
selector: 'node',
templateUrl: 'app/templates/node.html',
directives: [NodeComponent, OverlayDirective]
directives: [NodeComponent, OverlayDirective, TooltipDirective]
})

export class NodeComponent {
Expand Down
49 changes: 49 additions & 0 deletions app/ts/Directives/TooltipDirective.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Directive} from "angular2/core";
import {Input} from "angular2/core";
import {ElementRef} from "angular2/core";
import {el} from "angular2/testing_internal";

@Directive({
selector: '[tooltip]',
host: {
'(mouseenter)': 'show()',
'(mouseleave)': 'hide()'
}
})
export class TooltipDirective {

@Input('tooltip') text: string;

private _tooltip: HTMLElement;

constructor(
private _element: ElementRef
) {}

show(): void {
var el = this._element.nativeElement;
let position = el.getBoundingClientRect();
let top = position.top - position.height - 10;
let left = position.right - (position.width/2);

this._tooltip = this.getTooltipDom();

el.appendChild(this._tooltip);

this._tooltip.style.left = left + 'px';
this._tooltip.style.top = top + 'px';
}

hide(): void {
this._element.nativeElement.removeChild(this._tooltip);
}

private getTooltipDom(): HTMLElement {
let string: string = '<div class="tooltip">' + this.text + '</div>';
let div: HTMLElement = document.createElement('div');

div.innerHTML = string;

return div.firstChild;
}
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var staticFiles = [
];

gulp.task('sass', function () {
gulp.src(appFolder + 'sass/style.sass')
gulp.src(appFolder + 'sass/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(distFolder + 'css'))
.pipe(connect.reload());
Expand Down

0 comments on commit 3af1c1d

Please sign in to comment.