Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add modern tooltips #23

Closed
KyleMit opened this issue Aug 30, 2019 · 0 comments
Closed

add modern tooltips #23

KyleMit opened this issue Aug 30, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@KyleMit
Copy link
Member

KyleMit commented Aug 30, 2019

Especially for <abbr title="Vermont Department of Health">VDH</abbr> elements with title attribute.

Here are but biggest driver is going to be perf/bundle size. We don't need a lot of features

CSS

microtip - 1.2 KB

<button aria-label="Hey tooltip!" data-microtip-position="up" role="tooltip">

wenk - 0.7 KB

<span data-wenk="I'm to the right!" data-wenk-pos="right">Wenk to the right!</span>

W3 Schools - 0.3 KB

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>

Custom

<abbr data-tooltip="Vermont Department of Health">VDH</abbr> / 
*[data-tooltip] {
  position: relative;
}

*[data-tooltip]::after {
  content: attr(data-tooltip);

  position: absolute;
  bottom: -145%;
  left: -100%;
  display: inline-block;
  white-space: pre;
  z-index: 99;
  padding: 2px 7px;
  font-size: 1rem;
  line-height: 1rem;
  color: white;
  background: black;
  box-shadow: 1px 1px 1px grey;
  border-radius: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  transition-delay: 0.2s;
}

*[data-tooltip]:hover::after {
  opacity: 1;
}

JS

popper.js / tooltip.js - 7.3 KB + 2.2. KB

<button id="myButton">My Button</button>
var el = document.getElementByID("myButton")
new Tooltip(el , {
    placement: 'top', // or bottom, left, right, and variations
    title: "Tooltip text"
});

Tippy.js - 7.3 KB + 7.6 KB

<button id="myButton">My Button</button>
tippy('#myButton', {content: "I'm a Tippy tooltip!"})

Custom

<abbr title="Vermont Department of Health">VDH</abbr> / 
document.querySelectorAll("body [title]").forEach(function(el) {
  var tooltip = document.createElement("div")
  tooltip.classList.add("tooltip-text")
  tooltip.innerText = el.title

  el.title = ""
  el.classList.add("tooltip")
  el.append(tooltip)

  el.onmouseover = function() { 
    tooltip.classList.add("active"); 
    setTimeout(function() {tooltip.classList.remove("active")  }, 5000)
  }
  el.onmouseout = function() {
    tooltip.classList.remove("active")
  }
});
@KyleMit KyleMit added the enhancement New feature or request label Aug 30, 2019
@KyleMit KyleMit self-assigned this Aug 30, 2019
KyleMit added a commit that referenced this issue Sep 12, 2019
@KyleMit KyleMit closed this as completed Sep 12, 2019
@KyleMit KyleMit added this to the v0.4-beta milestone Sep 18, 2019
KyleMit added a commit that referenced this issue Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant