-
Notifications
You must be signed in to change notification settings - Fork 0
/
xp-tooltip.html
201 lines (169 loc) · 5.65 KB
/
xp-tooltip.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!--
@license
Copyright (c) 2015 The ExpandJS authors. All rights reserved.
This code may only be used under the BSD style license found at https://expandjs.github.io/LICENSE.txt
The complete set of authors may be found at https://expandjs.github.io/AUTHORS.txt
The complete set of contributors may be found at https://expandjs.github.io/CONTRIBUTORS.txt
-->
<!--
An element used to display a generic tooltip, centered underneath the content it contains.
It will reveal itself either on hovering or on tap.
```html
<xp-tooltip tip="Further detail...">
Hover over or tap for more details.
</xp-tooltip>
```
@element xp-tooltip
@description A custom element used to create a tooltip
@keywords web app, html5, expandjs, web-components
@group accessibility
@homepage http://expandjs.com/elements/xp-tooltip
@repository https://github.com/ExpandJS/xp-tooltip
@behavior xp-referral-behavior /bower_components/xp-referral-behavior/xp-referral-behavior.html
@dependency polymer Polymer/polymer#^1.1.0
@dependency expandjs ExpandJS/expandjs#0.9.11
@dependency xp-overlay ExpandJS/xp-overlay#0.9.11
@dependency xp-referral-behavior ExpandJS/xp-referral-behavior#0.9.11
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../expandjs/expandjs.html">
<link rel="import" href="../xp-overlay/xp-overlay.html">
<link rel="import" href="../xp-referral-behavior/xp-referral-behavior.html">
<dom-module id="xp-tooltip">
<template>
<style>
:host {
display: inline-block;
overflow: visible;
}
:host([empty]) #xpTooltipOverlay {
display: none !important;
}
:host #xpTooltipOverlay {
pointer-events: none;
}
:host #xpTooltipOverlay::shadow #xpOverlayWrapper {
overflow: visible;
}
:host #xpTooltipTip {
background-color: hsla(0, 0%, 0%, 0.9);
border-radius: 2px;
color: hsla(0, 0%, 100%, 1);
margin: 4px;
overflow: hidden;
padding: 4px 8px;
text-align: center;
text-overflow: ellipsis;
-moz-user-select: none;
-ms-user-select: none;
-webkit-tap-highlight-color: transparent;
-webkit-user-select: none;
user-select: none;
white-space: nowrap;
}
</style>
<content id="content"></content>
<xp-overlay id="xpTooltipOverlay" auto-center auto-hide-disabled position="baseline" showed="{{showed}}" target="[[self]]">
<div id="xpTooltipTip">{{tip}}</div>
</xp-overlay>
</template>
<script>
Polymer({
// ELEMENT
is: 'xp-tooltip',
// BEHAVIORS
behaviors: [
Polymer.XPReferralBehavior
],
/*********************************************************************/
/**
* Hides the tooltip.
*
* @method hide
* @returns {Element}
*/
hide: function () {
var self = this;
self.$.xpTooltipOverlay.hide();
return self;
},
/**
* Shows the tooltip.
*
* @method show
* @returns {Element}
*/
show: function () {
var self = this;
self.$.xpTooltipOverlay.show();
return self;
},
/**
* Toggles the tooltip.
*
* @method toggle
* @returns {Element}
*/
toggle: function () {
var self = this;
self.$.xpTooltipOverlay.toggle();
return self;
},
/*********************************************************************/
// LISTENERS
listeners: {
'mouseover': 'show',
'mouseout': 'hide'
},
// PROPERTIES
properties: {
/**
* If set to true, the tooltip is hidden.
*
* @attribute empty
* @type boolean
* @default true
* @notifies
* @readonly
*/
empty: {
computed: '_computeEmpty(tip)',
notify: true,
reflectToAttribute: true,
type: Boolean,
value: true
},
/**
* If set to true, the tooltip is showed.
*
* @attribute showed
* @type boolean
* @default false
* @notifies
*/
showed: {
notify: true,
reflectToAttribute: true,
type: Boolean,
value: false
},
/**
* The tooltip's text.
*
* @attribute tip
* @type string
*/
tip: {
reflectToAttribute: true,
type: String,
value: null
}
},
/*********************************************************************/
// COMPUTER
_computeEmpty: function (tip) {
return !tip;
}
});
</script>
</dom-module>