• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 1 year ago

Reviews

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

Repository Details

Advanced tooltips for React

React Floater

NPM version CI Maintainability Test Coverage

Advanced tooltips for React!

View the demo

Highlights

  • πŸ– Easy to use: Just set the content
  • πŸ›  Flexible: Personalize the options to fit your needs
  • 🟦 Typescript: Nicely typed

Usage

npm install --save react-floater

Import it in your app:

import Floater from 'react-floater';

<Floater content="This is the Floater content">
  <span>click me</span>
</Floater>;

And voΓ­la!

Customization

You can use your own components to render the Floater with the prop component.
Check WithStyledComponents.js in the demo for an example.

If you use your own components as children it will receive an innerRef prop that you must set in your HTMLElement:

const Button = ({ innerRef, ...rest }) => <button ref={innerRef} {...rest} />;

<Floater content="This is the Floater content">
  <Button>click me</Button>
</Floater>;

This works with styled-components (and other css-in-js libraries):

const Wrapper = styled.div`
  margin: 0 auto;
  max-width: 500px;
  line-height: 1.5;
`;

<Floater content="This is the Floater content">
  <Wrapper>click me</Wrapper>
</Floater>;

Props

autoOpen?: boolean = false
Open the Floater automatically.

callback?: (action: 'open' | 'close', props: Props)
It will be called when the Floater change state.

children: React.ReactNode
An element to trigger the Floater.

component {element|function}
A React component or function to as a custom UI for the Floater.
The prop closeFloater will be available in your component.

content {node}
The Floater content. It can be anything that can be rendered.
This is the only required props, unless you pass a component.

debug {bool} β–ΆοΈŽ false
Log some basic actions.
You can also set a global variable ReactFloaterDebug = true;

disableFlip {bool} β–ΆοΈŽ false
Disable changes in the Floater position on scroll/resize.

disableHoverToClick {bool} β–ΆοΈŽ false
Don't convert hover event to click on mobile.

event {string} β–ΆοΈŽ click
The event that will trigger the Floater. It can be hover | click.
These won't work in controlled mode.

eventDelay {number} β–ΆοΈŽ 0.4
The amount of time (in seconds) that the floater should wait after a mouseLeave event before hiding.
Only valid for event type hover.

footer {node}
It can be anything that can be rendered.

getPopper {function} Get the popper.js instance. It receives with 2 parameters:

  • popper {object} the popper object
  • origin {object} floater or wrapper

hideArrow {bool} β–ΆοΈŽ false
Don't show the arrow. Useful for centered or modal layout.

offset {number} β–ΆοΈŽ 15
The distance between the Floater and its target in pixels.

open {bool} The switch between normal and controlled modes.
Setting this prop will disabled the normal behavior.

options {object}
Customize popper.js modifiers.
Don't use it unless you know what you're doing

placement {string} β–ΆοΈŽ bottom
The placement of the Floater. It will update the position if there's no space available.

It can be:

  • top (top-start, top-end)
  • bottom (bottom-start, bottom-end)
  • left (left-start, left-end)
  • right (right-start, right-end)
  • auto
  • center

portalElement {string|null|HTMLElement}
A css selector or element to render the tooltips

showCloseButton {bool} β–ΆοΈŽ false
It will show a ⨉ button to close the Floater.
This will be true when you change wrapperOptions position.

styles {object} β–ΆοΈŽ defaultStyles
Customize the default UI.

target {object|string}
The target used to calculate the Floater position. If it's not set, it will use the children as the target.

title {node}
It can be anything that can be rendered.

wrapperOptions {WrapperOptions}
Position the wrapper relative to the target.
You need to set a target for this to work.

interface WrapperOptions {
  offset: number; // The distance between the wrapper and the target. It can be negative.
  placement: string; // the same options as above, except center
  position: bool; // Set to true to position the wrapper
}

Styling

You can customize everything with the styles prop.
Only set the properties you want to change and the default styles will be merged.

Check the styles.ts for the syntax.

Modes

Default
The wrapper will trigger the events and use itself as the Floater's target.

<Floater content="This is the Floater content">
  <span>click me</span>
</Floater>

Proxy
The wrapper will trigger the events but the Floater will use the target prop to position itself.

<div className="App">
  <img src="some-path" />

  <Floater content="This is the Floater content" target=".App img">
    <span>click me</span>
  </Floater>
</div>

Beacon
The same as the proxy mode but the wrapper will be positioned relative to the target.

<div className="App">
  <img
    src="https://upload.wikimedia.org/wikipedia/commons/2/2d/Google-favicon-2015.png"
    width="100"
    className="my-super-image"
  />

  <Floater
    content="This is the Floater content"
    target=".my-super-image"
    wrapperOptions={{
      offset: -22,
      placement: 'top',
      position: true,
    }}
  >
    <span style={{ color: '#f04', fontSize: 34 }}>β—‰</span>
  </Floater>
</div>

Controlled
When you set a boolean to the open prop it will enter the controlled mode and it will not respond to events.
In this mode you don't even need to have children

<div className="App">
  <img src="some-path" />
  <Floater content="This is the Floater content" open={true} target=".App img" />
</div>

More Repositories

1

logos

A huge collection of SVG logos
SVG
6,086
star
2

react-joyride

Create guided tours in your apps
TypeScript
6,046
star
3

react-inlinesvg

An SVG loader component for ReactJS
TypeScript
1,249
star
4

react-redux-saga-boilerplate

Starter kit with react-router, react-helmet, redux, redux-saga and styled-components
TypeScript
607
star
5

react-spotify-web-playback

A simple player for Spotify's web playback
TypeScript
291
star
6

disable-scroll

Prevent page scrolling
TypeScript
143
star
7

react-redux-observables-boilerplate

Starter kit for React with Router, Redux, Observable + RxJS
JavaScript
89
star
8

react-redux-starter

React starter kit with redux and react-router
JavaScript
68
star
9

alfred-workflows

Collection of Alfred workflows
PHP
33
star
10

react-from-dom

Convert HTML/XML source code or DOM nodes to React elements
TypeScript
25
star
11

codeclimate-stylelint

A Code Climate engine for the mighty, modern CSS linter
Less
24
star
12

tree-changes

Compare changes between two datasets
TypeScript
21
star
13

styled-minimal

Minimal UI theme with styled-components
JavaScript
18
star
14

is-lite

Type check tool
TypeScript
17
star
15

Turntable.fm-Playlists

Add playlists to turntable.fm
JavaScript
16
star
16

react-joyride-demo

Demo for React-Joyride
TypeScript
15
star
17

components

A collection of imperfect React components
TypeScript
15
star
18

react-web-session

Keep user data between visits
TypeScript
12
star
19

mdn-search

Search MDN with Alfred 2
PHP
11
star
20

generator-web

Generate a front-end website
JavaScript
11
star
21

colormeup

a tool to inspect a color and play with its many variations
JavaScript
10
star
22

helpers

Collection of useful functions
TypeScript
9
star
23

colorizr

Color conversion, manipulation, comparison and analysis
TypeScript
8
star
24

cpf-cnpj-generator

Generate fake brazilian CPF and CNPJ
PHP
8
star
25

hooks

Collection of useful React hooks
TypeScript
7
star
26

object-to-dot-notation

Convert simple objects to dot notation
TypeScript
6
star
27

links

Useful links for development
5
star
28

cloudinary

A tiny alternative to cloudinary-npm
JavaScript
5
star
29

react-starter

React starter kit with flux, router and bootstrap with a Hacker News reader
JavaScript
4
star
30

resume-v1

Developer Resume
ApacheConf
4
star
31

react-range-slider

A range slider component for React
TypeScript
4
star
32

genpass-alfred

Generate passwords from strings
JavaScript
3
star
33

dotfiles

sensible hacker default for macOS
Vim Script
3
star
34

git-rev-webpack-plugin

Webpack plugin to use git branch, hash and tag as substitutions for file names
Shell
3
star
35

s3-api

JavaScript
3
star
36

react-bot

A guided chat for interviewing users
3
star
37

deep-equal

Lightweight deep equal comparator
TypeScript
3
star
38

web-session

Keep user sessions between visits
TypeScript
3
star
39

idea-settings

IDEA Settings
2
star
40

tsconfig

Shared Typescript config
2
star
41

crashplan-control

Control CrashPlan with Alfred
Shell
2
star
42

types

Reusable typescript typings
TypeScript
2
star
43

git-hooks

A collection of useful git hooks
Shell
2
star
44

js-codemod

Codemod scripts to transform code
JavaScript
2
star
45

hadio

Airtime custom player
JavaScript
1
star
46

react-celebration

1
star
47

big-list

Technologies that you should learn (or at least now what it is about)
1
star
48

cookies

Lightweight cookie client
TypeScript
1
star
49

react-money

1
star
50

prettier-config

Shared Prettier config
1
star
51

learning

Books, courses and presentations that I've engaged.
1
star
52

react-party

It's a party
1
star
53

github-labels

1
star
54

eslint-config

Shared ESLint config
JavaScript
1
star
55

ttRoomie

A lightweight Users List for turntable.fm
JavaScript
1
star
56

gilbarbara.github.io

My Resume
ApacheConf
1
star
57

react-dropdown

Flexible dropdown component for React
TypeScript
1
star
58

wabi-sabi

1
star
59

fluxy

Flux Playground
JavaScript
1
star
60

react-floater-demo

Demo for react-floater
TypeScript
1
star
61

simple-react-router-redux

Tiny redux bindings for react-router
JavaScript
1
star
62

raycast-extensions

Raycast Extensions
TypeScript
1
star
63

TT-Bot

room bot and dj queue manager for turntable.fm
JavaScript
1
star
64

repo-tools

Useful CLI commands for working with remote repositories.
TypeScript
1
star
65

bitbar-plugins

BitBar plugins
JavaScript
1
star
66

kollectiv-syntax

Another dark theme with cool colors
CSS
1
star
67

intera-demo

Demo for Intera
TypeScript
1
star
68

wc14

World Cup 2014
JavaScript
1
star
69

requird

Wordpress plugin to require users to fill selected fields before posting.
PHP
1
star
70

generator-marionette-2

A Marionette 2 generator for Yeoman
JavaScript
1
star
71

little-alchemy-helper

Little Alchemy Helper - Interactive app with a bookmarklet to help while you play the game Little Alchemy.
JavaScript
1
star