npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zkreations/tooltips

v4.2.0

Published

Tiny and powerful tooltips with pure css

Downloads

229

Readme

Tooltips.css

Installation

npm

npm i @zkreations/tooltips

cdn

<link href="https://cdn.jsdelivr.net/npm/@zkreations/tooltips@4/tooltips.min.css" rel="stylesheet"/>

How to use

Add the data-tts and aria-label attributes to an html element:

<span data-tts aria-label="Hello world!">Tooltip</span>

Positioning

If no orientation is specified, the default value (up) will be used:

<span data-tts="up" aria-label="Up">Top</span>
<span data-tts="left" aria-label="Left">Left</span>
<span data-tts="right" aria-label="Right">Right</span>
<span data-tts="down" aria-label="Down">Bottom</span>

The "up" and "down" orientations can be combined with "left" and "right":

<span data-tts="up-left" aria-label="Up Left">Up Left</span>
<span data-tts="up-right" aria-label="Up Right">Up Right</span>
<span data-tts="down-left" aria-label="Down Left">Down Left</span>
<span data-tts="down-right" aria-label="Down Right">Down Right</span>

Animations

Animations can be created using CSS variables that affect the initial state:

| Variable | Default | Description | ----------------------- | -------- | ------------ | --tts-start-scale | 1 | Initial scale | --tts-end-scale | 1 | Final scale | --tts-start-translate | 0px | Initial position | --tts-end-translate | 0px | Final position

With these variables, you can create animations, for example:

.tts-slideIn {
  --tts-start-translate: -1rem;
}
.tts-slideOut {
  --tts-start-translate: 1rem;
}
.tts-zoomIn {
  --tts-start-scale: .9;
}
.tts-zoomOut {
  --tts-start-scale: 1.1;
}

Now just add the classes to your animations:

<span data-tts class="tts-slideIn" aria-label="Slide In">SlideIn</span>
<span data-tts class="tts-slideOut" aria-label="Slide Out">SlideOut</span>
<span data-tts class="tts-zoomIn" aria-label="Zoom In">ZoomIn</span>
<span data-tts class="tts-zoomOut" aria-label="Zoom Out">ZoomOut</span>

You can also define a default animation for all tooltips without using classes:

[data-tts] {
  --tts-start-translate: 1rem;
  --tts-start-scale: .75;
}

Show programmable tooltip

Add the data-tts-visible class to display the tooltip at any time without the need for user interaction with the element. You can easily add this attribute using JavaScript.

<span data-tts data-tts-visible aria-label="Programmatically Visible">Hello world</span>

Customize

Define new values for the tooltip's CSS variables to change its appearance. The available design variables are:

| Variable | Default | Description | --------------------- | -------------------- | ------------- | --tts-background | rgb(0 0 0 / 90%) | Background color | --tts-arrow | 6px | Arrow size | --tts-arrow-offset | 6px | Arrow offset (only for combined orientation) | --tts-duration | 0.3s | Animation duration | --tts-font-size | 14px | Font size | --tts-font-family | Roboto, sans-serif | Font family | --tts-color | #fff | Font color | --tts-padding | 0.5em 0.75em | Padding | --tts-border-radius | 0.25em | Border radius

Variables allow you to create new themes that you can apply with your own classes:

.tts-custom {
  --tts-background: #607D8B;
  --tts-border-radius: 1em;
  --tts-duration: .5s;
}

You can also set global styles for all tooltips:

[data-tts] {
  --tts-background: #607D8B;
  --tts-border-radius: 0px;
}

Notes

Tooltips do not work with self-closing tags, for example, <img/> or <input/>. To fix this, create a container and initiate the tooltip inside it:

<figure data-tts aria-label="I am an image">
  <img src="example.jpg"/>
</figure>

Supporting

If you want to help me keep this and more related projects always up to date, you can buy me a coffee ☕. I will be very grateful 👏.

License

tooltips.css is licensed under the MIT License