Giter Club home page Giter Club logo

react-aria-tooltip's Introduction

react-aria-tooltip

Simple ReactJS component that adds the appropriate role, identification structure, and aria-hidden attribute for a tooltip.

Installation

npm install react-aria-tooltip

Usage

import ReactARIAToolTip from "react-aria-tooltip";

return (
  <ReactARIAToolTip message="Your custom message">
    <SomeTagOrComponent>Some content</SomeTagOrComponent>
  </ReactARIAToolTip>
);

Options

  1. message string that will display in the tooltip (required)
  2. eventType this can either be 'click' or 'hover' (default 'click')
  3. direction the placement of the tooltip. Can be one of four options 'top', 'bottom', 'right', 'left' (default 'top')
  4. duration this is only applicable to the click eventType. This value defines the amount of time the tooltip is present after the user clicks the target element (default 2000). If the value is 0 or false then the tooltip will persist until the user clicks outside of the bounds of any of the tooltip content and/or button.
  5. bgcolor controls the background color of the tooltip. (default '#000')

Note: Please use a color contrast checker such as http://webaim.org/resources/contrastchecker/ to make sure the font color, defaulted to white/#fff, works with your bgcolor value)

Storybook

React aria tooltip uses Storybook to validate UI behaviors and visual the rendering states. To see and test react-aria-tooltip run yarn run storybook after installing all packages by running yarn. This should start a local service at http://localhost:6006 where you can see the available directions (top, right, bottom, left) and events (click & hover) in UI wrapper.

Examples

Hover

<ReactARIAToolTip
  message="Tooltip text"
  eventType="hover"
  direction="bottom"
  bgcolor="#333"
>
  <span>Some text</span>
</ReactARIAToolTip>

Click (auto remove with duration)

<ReactARIAToolTip
  message="Something fancy"
  eventType="click"
  duration="500"
  bgcolor="red"
>
  <img src="../path/to/some/image" alt="" title="" />
</ReactARIAToolTip>

Click (remove with clicking outside of tooltip)

<ReactARIAToolTip
  message="Something fancy"
  eventType="click"
  duration="{false}"
  bgcolor="red"
>
  <img src="../path/to/some/image" alt="" title="" />
</ReactARIAToolTip>

Styling

All styles are handled inline but each element contains a CSS class so you can override what's necessary to override locally. Below is the basic structure for reference:

<div class="ra-tooltip-wrapper">
  <div class="ra-tooltip">
    <div class="ra-tooltip-message">
      <p>Tooltip text</p>
    </div>
  </div>
</div>

MIT Licensed

react-aria-tooltip's People

Contributors

egoens avatar danielksato avatar oyeanuj avatar asaayers avatar mshick avatar

Watchers

James Cloos 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.