• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tooltip React component for Redux.

NPM Package Travis Dependency Status Greenkeeper badge

redux-tooltip

A tooltip React component for Redux.

Features

  • Designed for use with Redux
  • Control by FSA-compliant actions
  • Don't conceal the state
  • Auto-resizing and auto-placement based on the content
  • Support multiple tooltips
  • Fully customizable 'Delay' feature

Why?

react-tooltip is a popular tooltip library and I tried it with Redux. It works nice at first, but I struggled when I wanted to implement delay/keep features. I noticed the root issue is that all tooltip states should be stored in Redux. In addition to this, a tooltip should be controlled by Redux's actions.

Installation

npm install --save redux-tooltip

Demo & Examples

Please check out examples directory.

Online demo is also available.

Getting Started

redux-tooltip provides a Redux reducer and Higher Order components; Tooltip and Origin. The reducer handles actions that are dispatched from the components and changes Redux's state tree. Since both components are already connected to Redux store (this also means they can call store.dispatch()), the Tooltip component receives changes of props from the store and updates itself.

The recommended setup is that a single (shared) Tooltip component and multiple Origin components. If you hover on the origin element, the tooltip will be shown.

1. Put a shared Tooltip component to Container component

import { Tooltip } from 'redux-tooltip';

class App extends React.Component {
  render() {
    return <div>
      <Page />
      <Tooltip>
        Hello Tooltip!
      </Tooltip>
    </div>;
  }
}

2. Wrap your content with an Origin component within a Container or Presentational component

import { Origin } from 'redux-tooltip';

class Page extends React.Component {
  render() {
    return <p>
      Please hover <Origin>here</Origin>.
    </p>;
  }
}

3. Combine redux-tooltip reducer with yours

import { reducer as tooltip } from 'redux-tooltip';

// ...

export default combineReducers(
  { your, awesome, reducers, ..., tooltip }
);

That's it!

[Optional] 4. Insert redux-tooltip middleware with yours

If you want to use 'delay' feature, please insert redux-tooltip middleware to enable the feature.

import { middleware as tooltip } from 'redux-tooltip';

// ...

const store = createStore(
  reducer,
  initialstate,
  applyMiddleware(
    your, awesome, middlewares, ..., tooltip
  )
);

API

<Tooltip />

A tooltip component. Please wrap a content which should be shown in a tooltip.

  • name (string): A name of tooltip. This is used by <Origin /> component.
  • place (string|string[]): A direction of tooltip. This value can be overwritten by <Origin />'s place prop. Default is top.
  • auto (boolean): A switch to enable/disable the auto-placement feature. Default is true.
  • within (DOM): A DOM element which is used to restrict the position where this tooltip is placed within.
  • onHover (Function): A callback function to be called on mouseover at tooltip.
  • onLeave (Function): A callback function to be called on mouseout at tooltip.
  • id (string): An id attribute passed to <div> element of a tooltip.
  • className (string): A class attribute passed to <div> element of a tooltip.
  • darkTheme (boolean): Specify whether dark mode should be used or not

<Origin />

An origin component. Please wrap an element which triggers the action to show a tooltip. In most cases, you may use this component without any options. For advanced usage, you can override the default handlers; onMouseEnter and onMouseLeave.

  • name (string|string[]): A name(s) to specify which tooltip(s) should be used.
  • content (string|DOM|DOM[]): A content for tooltip. If string, it's sanitized by DOMPurify.
  • place (string|string[]): A name of direction to specify a location of tooltip.
  • tagName (string): A tag name of wrapper element. Default is span.
  • delay (boolean|number|string): A number of duration for delay feature.
  • delayOn (string): A name of timing to enable the delay. show, hide, or both. Default is hide.
  • onTimeout (Function): A callback function when timeout by delay feature.
  • onHover (Function): An event handler of mouseenter.
  • onLeave (Function): An event handler of mouseleave.

Origin.wrapBy(tagName)

// Invalid SVG...
// Origin component wraps children with <span> tag in default.
function Shape() {
  return <svg width="80" height="80">
    <Origin>
      <rect x="10" y="10" width="20" height="30" />
    </Origin>
  </svg>;
}

// Perfect!
// Origin.wrapBy() method can be used to create customized Origin component which wraps with your favorite tag.
const SVGOrigin = Origin.wrapBy('g');

function Shape() {
  return <svg width="80" height="80">
    <SVGOrigin>
      <rect x="10" y="10" width="20" height="30" />
    </SVGOrigin>
  </svg>;
}

reducer

A Redux reducer must be combined with yours.

middleware

Please apply this middleware if you want to use 'delay' feature.

actions

delay(action, options = { duration: 1500, callback: null })

A helper function to enable 'delay' feature. Internally, it sets a duration of delay to the meta section of given action. In options argument, duration is used for duration of delay. callback is a callback function which is called after expired delay.

Development

Setup

npm install
npm run build

Start dev server for example

npm start

Open http://localhost:8080/webpack-dev-server/ for auto-reloading. If you want to debug with React Dev Tools, http://localhost:8080/ will be preferred. You can also view the store, and see the actions being fired, if you have Redux DevTools extension installed.

Run test

This executes both unit and integration tests:

npm test

Unit test

npm run test:unit

Integration test

We're currently use PhantomJS 2.1.1 for testing environment. Following command will launch the headless browser and run test suite.

npm run test:feature

If you prefer 'single-run', which means that the browser is closed after testing, try following command:

npm run test:feature:ci

Changelog

See the Releases page on GitHub.

License

MIT

Author

Yuki Kodama / @kuy

More Repositories

1

redux-saga-examples

Yet another example repository for redux-saga.
JavaScript
404
star
2

redux-saga-chat-example

A chat app built with redux-saga and Socket.IO.
JavaScript
288
star
3

redux-tower

Saga powered routing engine for Redux app.
JavaScript
154
star
4

treemap-with-router

An example for react-router-redux with d3's treemap.
JavaScript
63
star
5

reason-of-life

Conway's Lifegame in Reason + reason-react with webpack + bs-loader.
OCaml
27
star
6

slack-loc

Update Slack status based on your location (using Wi-Fi SSID).
Shell
26
star
7

lifegame-redux

Conway's lifegame using Redux + various middlewares.
JavaScript
21
star
8

redux-merge-reducers

A decorator to make your Redux's reducers mergeable.
JavaScript
19
star
9

oberis

Tetris + Obelisk.js with Redux.
JavaScript
15
star
10

popover-profile

A small app to demonstrate shared self-contained components.
JavaScript
13
star
11

react-transport

Transports your React component to the outside of React rendering tree.
JavaScript
11
star
12

decom

Decompose docker-compose logs and organize them.
Rust
8
star
13

babel-plugin-transform-immutablejs

Transform built-in collection operations to Immutable.js ones.
JavaScript
8
star
14

jsonbox-rs

Rust wrapper for jsonbox.io
Rust
8
star
15

testdouble-timers

Fake timers API for testdouble.js.
JavaScript
8
star
16

avn-nodebrew

avn plugin for nodebrew
JavaScript
7
star
17

macro-harness

Test harness for procedural macros
Rust
7
star
18

nada.re

Visualization of Abelian sandpile model written in Reason + Obelisk.js.
OCaml
6
star
19

authist

Automatic 2FA/MFA assistant with OCR your smartphone.
JavaScript
6
star
20

redux-autocomplete

A React component react-autocomplete for Redux.
JavaScript
5
star
21

elevato-rs

An Elevator Simulator written in Rust with Amethyst game engine.
Rust
5
star
22

gmeet-slash-cmd

Slack integration for Google Meet
TypeScript
5
star
23

cizen-chat

Elixir
5
star
24

td4-js

An emulator of TD4 (4-bit tiny CPU) written in JS+Flowtype+Redux.
JavaScript
5
star
25

sc-repeat-playlist

A Chrome Extension providing "Repeat Playlist" feature to SoundCloud.
JavaScript
4
star
26

redux-saga-takex

A powerful take effect accepting RegExp instead of listing action types.
JavaScript
4
star
27

aia

AIA: Illustrator Automated
JavaScript
3
star
28

domain-specific-saga

A helper library to realize Domain Specific Saga for your Redux apps.
JavaScript
3
star
29

electron-connect-webpack-plugin

electron-connect integration for webpack.
JavaScript
3
star
30

gkkj-web

srouce code for Geek House Gokokuji (http://gkkj.org)
JavaScript
3
star
31

warp-example-app

Example web app written in Rust with warp + diesel + tera.
Rust
3
star
32

redux-middleware-logger

Logger for Redux's middleware.
JavaScript
3
star
33

react-cropview

A React component providing a cropped view for large contents and making it draggable.
JavaScript
3
star
34

asdf-pixel-sort

Rust implementation of pixel sorting algorithm "ASDF" by Kim Asendorf
Rust
3
star
35

console.ws

WebSocket powered remote console.log() for Node.js
JavaScript
2
star
36

wistant-fb-toc

TypeScript
2
star
37

docker-nginx-upstream-dynamic

Alpine based nginx container with nginx-upstream-dynamic-servers module.
Dockerfile
2
star
38

dining-philosophers

Dining Philosophers Problem in Rust.
Rust
2
star
39

funl

peco/percol powered interactive placeholders in shell environment.
Shell
2
star
40

sqlx-pool-study

Rust
2
star
41

capistrano-nodebrew

nodebrew support for Capistrano 3.x
Ruby
2
star
42

actix-delay

Simulates a delayed response for actix-web
Rust
2
star
43

monkey-lang

OCaml
2
star
44

blog

HTML
1
star
45

asdf-study

Study of ASDF Pixel Sort
Processing
1
star
46

mockall-study

Rust
1
star
47

menthas-cordova

Menthas for Android/iOS using Apache Cordova.
JavaScript
1
star
48

rustracer

A toy path tracer written in Rust.
Rust
1
star
49

perceptron

OCaml
1
star
50

decent-profile-viewer-seed

Rust
1
star
51

today-anime

I can't keep in mind a day of the week of my favorite animes' broadcast 😇
OCaml
1
star
52

axum-study

Rust
1
star
53

kiyoshi

Zun Doko Kiyoshi!
JavaScript
1
star
54

decent-profile-viewer

Rust
1
star
55

saml-proxy

SAML proxy built with Node.js and run on AWS ECS/Fargate.
JavaScript
1
star
56

acot-reporter-null

A null reporter for @acot/cli.
TypeScript
1
star
57

parseco

Learning parser combinators in OCaml + Core.
OCaml
1
star
58

otel-study

Rust
1
star
59

opendatastructures-study

Rust
1
star
60

relit-lifegame

OCaml
1
star
61

jsonbox-todo-example

Usage example of jsonbox.rs
Rust
1
star
62

conscale

Rust
1
star
63

kuy.github.io

HTML
1
star
64

acot-reporter-github

A GitHub reporter for acot
JavaScript
1
star
65

peddyo

Slack bot written in OCaml
OCaml
1
star
66

rust-hello

Rust
1
star
67

rust-cross-into-study

Rust
1
star
68

lazy-spinner

A small application to demonstrate the lazy loading spinner using React + Redux.
JavaScript
1
star
69

dining-philosophers-aa

Rust's async/await version of Dining Philosophers Problem.
Rust
1
star
70

flix-sandbox

1
star
71

winit-study

Rust
1
star
72

client-dynamodb-study

DynamoDB of AWS JavaScript SDK v3
JavaScript
1
star
73

camera-proc

Rust
1
star
74

cizen-cells

Time-driven two-dimensional asynchronous cellular automaton with Moore neighborhood.
Elixir
1
star
75

acot-reporter-slack

A Slack reporter for acot.
TypeScript
1
star
76

lifegame.rs

Conway's lifegame written in Rust.
Rust
1
star