Giter Club home page Giter Club logo

react-popper-spring-tooltip's Introduction

React Popper Spring Tooltip

npm version npm downloads code style: prettier

Tooltips powered by react-popper and react-spring.

Install

Via package managers:

npm install react-popper-spring-tooltip --save
# or
yarn add react-popper-spring-tooltip

Usage

Examples

Let's start with a simple example:

Wrap your Tooltip component around an on / off Toggle.

<Tooltip trigger="click" placement="bottom" content={<h1>Hi!</h1>}>
  {({ ...bind }) => <button {...bind}>Toggle</button>}
</Tooltip>

Spreading bind will pass you the reference provided by react-popper and EventListeners to open / close the tooltip content.

react-popper-spring-tooltip makes use of a React pattern called "render prop", if you are not familiar with it, please read more on the official React documentation.

In more advanced use cases you may pass your Components via the content prop. You can also pass your own react-spring config to make awesome custom animations. Also note that you can destructure the isOpen prop to add conditions to your Toggle.

<Tooltip
  trigger="click"
  placement="bottom"
  content={<TooltipContent />}
  springConfig={{
    from: {
      scale: 0.8,
      config: { duration: 100 }
    },
    to: {
      scale: 1,
      config: { duration: 50 }
    }
  }}
>
  {({ isOpen, ...bind }) => (
    <button
      {...bind}
      className={`${isOpen ? "opened-button" : "closed-button"}`}
    >
      Toggle
    </button>
  )}
</Tooltip>

Props

children

(props) => ReactNode | required

The Tooltip component must be wrapped around a function that renders your Toggle.

content

string | React.Element | required

The content of the Tooltip.

placement

string | required

The Tooltip placement. Valid placements are:

  • auto
  • top
  • bottom
  • left
  • right

Each placement can have a variation from this list:

  • -start
  • -end

trigger

string | required

The Tooltip trigger action. Valid actions are:

  • click
  • hover
  • context

closeOnClickOutside

boolean | defaults to true

Will determine whether or not to close the Tooltip by clicking outside the Trigger.

init

boolean | defaults to false

Will set the initial open (true) and closed (false) state.

springConfig

object | defaults to:

{ from: { opacity: 0 }, to: { opacity: 1 }}

Define the CSS using from and to keys.

If you are new to react-spring check out their docs.

TypeScript

This library is built with TypeScript and will automatically generate typing during the Rollup build process in: dist/Tooltip.d.ts

Local Development

clone repo

git clone https://github.com/impulse/react-popper-spring-tooltip.git

cd into folder

cd react-popper-spring-tooltip

install dependencies

npm install or yarn

run dev mode

npm run watch or yarn watch

react-popper-spring-tooltip's People

Contributors

ecklf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.