|
6 | 6 |
|
7 | 7 | let showSettings = false |
8 | 8 |
|
9 | | - let tooltipTextContent = null |
10 | | - let useCustomTooltipClass = false |
11 | | - let tooltipPosition = 'top' |
12 | | - let isTooltipDisabled = false |
13 | | - let animateTooltip = false |
| 9 | + let textContent = null |
| 10 | + let useCustomClass = false |
| 11 | + let position = 'top' |
| 12 | + let isDisabled = false |
| 13 | + let animate = false |
14 | 14 | let useCustomAnimationEnterClass = false |
15 | 15 | let useCustomAnimationLeaveClass = false |
16 | | - let tooltipEnterDelay = 200 |
17 | | - let tooltipLeaveDelay = 200 |
18 | | - let tooltipOffset = 10 |
| 16 | + let enterDelay = 200 |
| 17 | + let leaveDelay = 200 |
| 18 | + let triggerOnEnter = false |
| 19 | + let triggerOnLeave = false |
| 20 | + let offset = 10 |
| 21 | +
|
| 22 | + const _onTooltipEnter = () => { |
| 23 | + if(triggerOnEnter) { |
| 24 | + alert('You\'ve entered the target') |
| 25 | + } |
| 26 | + } |
| 27 | +
|
| 28 | + const _onTooltipLeave = () => { |
| 29 | + if(triggerOnLeave) { |
| 30 | + alert('You\'ve left the target') |
| 31 | + } |
| 32 | + } |
19 | 33 |
|
20 | 34 | const _onTooltipClick = (arg, e) => { |
21 | 35 | e.preventDefault() |
|
204 | 218 | <form class="settings__form"> |
205 | 219 | <fieldset> |
206 | 220 | <label> |
207 | | - Tooltip Text Content: |
208 | | - <input type="text" bind:value={tooltipTextContent}/> |
| 221 | + Text Content: |
| 222 | + <input type="text" bind:value={textContent}/> |
209 | 223 | </label> |
210 | 224 | </fieldset> |
211 | 225 | <fieldset> |
212 | 226 | <label> |
213 | | - Use Custom Tooltip Class: |
214 | | - <input type="checkbox" bind:checked={useCustomTooltipClass}/> |
| 227 | + Use Custom Class: |
| 228 | + <input type="checkbox" bind:checked={useCustomClass}/> |
215 | 229 | </label> |
216 | 230 | </fieldset> |
217 | 231 | <fieldset> |
218 | 232 | <label> |
219 | | - Tooltip Position: |
220 | | - <select bind:value={tooltipPosition}> |
| 233 | + Position: |
| 234 | + <select bind:value={position}> |
221 | 235 | <option value="left">Left</option> |
222 | 236 | <option value="right">Right</option> |
223 | 237 | <option value="top">Top</option> |
|
227 | 241 | </fieldset> |
228 | 242 | <fieldset> |
229 | 243 | <label> |
230 | | - Animate tooltip: |
231 | | - <input type="checkbox" bind:checked={animateTooltip}/> |
| 244 | + Animate: |
| 245 | + <input type="checkbox" bind:checked={animate}/> |
232 | 246 | </label> |
233 | 247 | </fieldset> |
234 | 248 | <fieldset> |
235 | 249 | <label> |
236 | | - Use Custom Tooltip Animation Enter Class: |
| 250 | + Use Custom Animation Enter Class: |
237 | 251 | <input type="checkbox" bind:checked={useCustomAnimationEnterClass}/> |
238 | 252 | </label> |
239 | 253 | </fieldset> |
240 | 254 | <fieldset> |
241 | 255 | <label> |
242 | | - Use Custom Tooltip Animation Leave Class: |
| 256 | + Use Custom Animation Leave Class: |
243 | 257 | <input type="checkbox" bind:checked={useCustomAnimationLeaveClass}/> |
244 | 258 | </label> |
245 | 259 | </fieldset> |
246 | 260 | <fieldset> |
247 | 261 | <label> |
248 | | - Tooltip Enter Delay (ms): |
249 | | - <input type="number" step={100} min={0} bind:value={tooltipEnterDelay}/> |
| 262 | + Enter Delay (ms): |
| 263 | + <input type="number" step={100} min={0} bind:value={enterDelay}/> |
| 264 | + </label> |
| 265 | + </fieldset> |
| 266 | + <fieldset> |
| 267 | + <label> |
| 268 | + Leave Delay (ms): |
| 269 | + <input type="number" step={100} min={0} bind:value={leaveDelay}/> |
| 270 | + </label> |
| 271 | + </fieldset> |
| 272 | + <fieldset> |
| 273 | + <label> |
| 274 | + Trigger callback on enter: |
| 275 | + <input type="checkbox" bind:checked={triggerOnEnter}/> |
250 | 276 | </label> |
251 | 277 | </fieldset> |
252 | 278 | <fieldset> |
253 | 279 | <label> |
254 | | - Tooltip Leave Delay (ms): |
255 | | - <input type="number" step={100} min={0} bind:value={tooltipLeaveDelay}/> |
| 280 | + Trigger callback on leave: |
| 281 | + <input type="checkbox" bind:checked={triggerOnLeave}/> |
256 | 282 | </label> |
257 | 283 | </fieldset> |
258 | 284 | <fieldset> |
259 | 285 | <label> |
260 | | - Tooltip Offset (px): |
261 | | - <input type="number" step={1} min={5} bind:value={tooltipOffset}/> |
| 286 | + Offset (px): |
| 287 | + <input type="number" step={1} min={5} bind:value={offset}/> |
262 | 288 | </label> |
263 | 289 | </fieldset> |
264 | 290 | <fieldset> |
265 | 291 | <label> |
266 | | - Disable Tooltip: |
267 | | - <input type="checkbox" bind:checked={isTooltipDisabled}/> |
| 292 | + Disable: |
| 293 | + <input type="checkbox" bind:checked={isDisabled}/> |
268 | 294 | </label> |
269 | 295 | </fieldset> |
270 | 296 | </form> |
|
276 | 302 | </button> |
277 | 303 | <div |
278 | 304 | use:useTooltip={{ |
279 | | - position: tooltipPosition, |
280 | | - content: tooltipTextContent, |
281 | | - contentSelector: !tooltipTextContent?.length ? '#tooltip__template' : null, |
| 305 | + position: position, |
| 306 | + content: textContent, |
| 307 | + contentSelector: !textContent?.length ? '#tooltip__template' : null, |
282 | 308 | contentActions: { |
283 | 309 | '*': { |
284 | 310 | eventType: 'click', |
|
287 | 313 | closeOnCallback: true, |
288 | 314 | }, |
289 | 315 | }, |
290 | | - containerClassName: useCustomTooltipClass ? `tooltip tooltip-${tooltipPosition}` : null, |
291 | | - animated: animateTooltip, |
| 316 | + containerClassName: useCustomClass ? `tooltip tooltip-${position}` : null, |
| 317 | + animated: animate, |
292 | 318 | animationEnterClassName: useCustomAnimationEnterClass ? 'tooltip-enter' : null, |
293 | 319 | animationLeaveClassName: useCustomAnimationLeaveClass ? 'tooltip-leave' : null, |
294 | | - enterDelay: tooltipEnterDelay, |
295 | | - leaveDelay: tooltipLeaveDelay, |
296 | | - offset: tooltipOffset, |
297 | | - disabled: isTooltipDisabled, |
| 320 | + enterDelay: enterDelay, |
| 321 | + leaveDelay: leaveDelay, |
| 322 | + onEnter: _onTooltipEnter, |
| 323 | + onLeave: _onTooltipLeave, |
| 324 | + offset: offset, |
| 325 | + disabled: isDisabled, |
298 | 326 | }} |
299 | 327 | class="target" |
300 | 328 | > |
|
0 commit comments