2.1.0 β€’ Published 3 months ago

react-simtip v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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

NameTypeDefaultDescription
contentstring or ReactNodenullThe content of the tooltip.
childrenReactNodenullThe element that will trigger the tooltip.

Optional

Position

NameTypeDefaultDescriptionValues
placementstring"top"The position of the tooltip."top", "bottom", "left", "right"
triggerstring"hover"The event that will trigger the tooltip."hover", "click"
showDelaynumber400The delay before the tooltip appears (in milliseconds).Any number
hideDelaynumber0The delay before the tooltip disappears (in milliseconds).Any number
distanceFromTargetnumber30The distance between the tooltip and the anchor (in pixels).Any number

Appearance

NameTypeDefaultDescriptionValues
fontSizestring"1rem"The font size of the tooltip.Any valid CSS font size
paddingnumber6The padding of the tooltip (in pixels).Any number
borderRadiusnumber4The border radius of the tooltip (in pixels).Any number
backgroundColorstring"#000"The background color of the tooltip.Any valid CSS color
colorstring"#fff"The text color of the tooltip.Any valid CSS color
hasArrowbooleanfalseWhether the tooltip has an arrow or not.true, false
arrowSizenumber6The size of the arrow (in pixels).Any number

Animation

NameTypeDefaultDescriptionValues
animationstring"fade"The animation of the tooltip."fade", "scale", "flip", "slide", "slide-flip", "bounce"
animationDurationnumber300The duration of the animation (in milliseconds).Any number

Classes

NameTypeDefaultDescriptionValues
classNamestringnullThe 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

2.1.0

3 months ago

2.0.3

3 months ago

2.0.5

3 months ago

2.0.4

3 months ago

2.0.6

3 months ago

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago