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

react-simtip

v2.1.0

Published

A simple tooltip component for React

Downloads

52

Readme

typescript npm npm bundle size install size npm downloads

react-simtip

A simple tooltip component for React.

Features

  • ⚡️ Lightweight (less than 2.3kb gzipped).
  • 📦 No dependencies.
  • 📝 Written in TypeScript.
  • 📖 Easy to use.
  • 🎨 Highly customizable.
  • 📚 Storybook.

Storybook

You can see the component in action in the Storybook.

Installation

npm install react-simtip

or

yarn add react-simtip

Usage

import React from "react";
import { Tooltip } from "react-simtip";

const App = () => {
	return (
		<Tooltip content="Hello World!">
			<button>Hover me!</button>
		</Tooltip>
	);
};

export default App;

Props

Required

| Name | Type | Default | Description | | ---------- | ----------------------- | ------- | ------------------------------------------ | | content | string or ReactNode | null | The content of the tooltip. | | children | ReactNode | null | The element that will trigger the tooltip. |

Optional

Position

| Name | Type | Default | Description | Values | | -------------------- | -------- | ------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | | placement | string | "top" | The position of the tooltip. | "top", "bottom", "left", "right" | | trigger | string | "hover" | The event that will trigger the tooltip. | "hover", "click" | | showDelay | number | 400 | The delay before the tooltip appears (in milliseconds). | Any number | | hideDelay | number | 0 | The delay before the tooltip disappears (in milliseconds). | Any number | | distanceFromTarget | number | 30 | The distance between the tooltip and the anchor (in pixels). | Any number |

Appearance

| Name | Type | Default | Description | Values | | ----------------- | --------- | ------- | --------------------------------------------- | ----------------------- | | fontSize | string | "1rem" | The font size of the tooltip. | Any valid CSS font size | | padding | number | 6 | The padding of the tooltip (in pixels). | Any number | | borderRadius | number | 4 | The border radius of the tooltip (in pixels). | Any number | | backgroundColor | string | "#000" | The background color of the tooltip. | Any valid CSS color | | color | string | "#fff" | The text color of the tooltip. | Any valid CSS color | | hasArrow | boolean | false | Whether the tooltip has an arrow or not. | true, false | | arrowSize | number | 6 | The size of the arrow (in pixels). | Any number |

Animation

| Name | Type | Default | Description | Values | | ------------------- | -------- | ------- | ------------------------------------------------ | -------------------------------------------------------- | | animation | string | "fade" | The animation of the tooltip. | "fade", "scale", "flip", "slide", "slide-flip", "bounce" | | animationDuration | number | 300 | The duration of the animation (in milliseconds). | Any number |

Classes

| Name | Type | Default | Description | Values | | ----------- | -------- | ------- | ------------------------------ | ------------------------ | | className | string | null | The class name of the tooltip. | Any valid CSS class name |

Styling

There are three ways to style the tooltip:

1. Using the className prop

import React from "react";
import { Tooltip } from "react-simtip";

const App = () => {
	return (
		<Tooltip content="Hello World!" className="my-tooltip">
			<button>Hover me!</button>
		</Tooltip>
	);
};

export default App;
.my-tooltip {
	background-color: #000;
	color: #fff;
	font-size: 1rem;
	padding: 6px;
	border-radius: 4px;
}

2. Using the provided CSS variables

You can override the default CSS variables by adding the following code to your CSS file (This is the easiest way to apply same styles to all the tooltips):

:root {
	--simtip-padding: 6px;
	--simtip-animation-duration: 300ms;
	--simtip-border-radius: 4px;
	--simtip-font-size: 11px;
}

3. Using provided props

This way styles will be applied only to the tooltip that has the prop.

import React from "react";
import { Tooltip } from "react-simtip";

const App = () => {
	return (
		<Tooltip
			content="Hello World!"
			backgroundColor="#000"
			color="#fff"
			fontSize="1rem"
			padding={6}
			borderRadius={4}
		>
			<button>Hover me!</button>
		</Tooltip>
	);
};

export default App;

License

The MIT License. See LICENSE for more information.

Author