Coder Social home page Coder Social logo

react-tooltip-lite's Introduction

React tooltip-lite

A lightweight and responsive tooltip. Feel free to Post an issue if you're looking to support more use cases.

Getting started

1. Install with NPM

$ npm install react-tooltip-lite

2. Import into your react Component

import Tooltip from 'react-tooltip-lite';

3. Wrap any element with the Tooltip component to make it a target

<Tooltip content="Go to google">
    <a href="http://google.com"> edge</a>
</Tooltip>

CodePen demo: http://codepen.io/bsidelinger912/pen/WOdPNK


styling

By default you need to style react-tooltip-lite with CSS, this allows for psuedo elements and some cool border tricks, as well as using sass variables and such to keep your colors consistant. But as of version 1.2.0 you can also pass the "useDefaultStyles" prop which will allow you to use react-tooltip-lite without a stylesheet. Here's an example stylesheet:

/* default tooltip styles */
.react-tooltip-lite {
  background: #333;
  color: white;
}

.react-tooltip-lite-up-arrow {
  border-top: 10px solid #333;
}

.react-tooltip-lite-down-arrow {
  border-bottom: 10px solid #333;
}

.react-tooltip-lite-right-arrow {
  border-right: 10px solid #333;
}

.react-tooltip-lite-left-arrow {
  border-left: 10px solid #333;
}

Props

You can pass in props to define tip direction, styling, etc. Content is the only required prop.

Name Type Description
content node (text or html) the contents of your hover target
tagName string html tag used for className
direction string the tip direction, defaults to up
className string css class added to the rendered wrapper
background string background color for the tooltip contents and arrow
color string text color for the tooltip contents
padding string padding amount for the tooltip contents (defaults to '10px')
styles object style overrides for the target wrapper
eventOn string full name of supported react event to show the tooltip, e.g.: 'onClick'
eventOff string full name of supported react event to hide the tooltip, e.g.: 'onClick'
eventToggle string full name of supported react event to toggle the tooltip, e.g.: 'onClick', default hover toggling is disabled when using this option
useHover boolean whether to use hover to show/hide the tip, defaults to true
useDefaultStyles boolean uses default colors for the tooltip, so you don't need to write any CSS for it

Here's an example using more of the props:

<Tooltip
  content={(
      <div>
          <h4 className="tip-heading">An unordered list to demo some html content</h4>
          <ul className="tip-list">
              <li>One</li>
              <li>Two</li>
              <li>Three</li>
              <li>Four</li>
              <li>Five</li>
          </ul>
      </div>
  )}
  direction="right"
  tagName="span"
  className="target"
>
    Target content for big html tip
</Tooltip>

To see more usage examples, take look at the /example folder in the source.

react-tooltip-lite's People

Contributors

bsidelinger912 avatar artemjackson avatar

Watchers

Sam Doughty avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.