npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-floater

v0.9.3

Published

Floaters everywhere!

Downloads

1,139,333

Readme

React Floater

NPM version CI Quality Gate Status 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 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 a custom component to render the Floater with the component prop.
Check WithStyledComponents.ts in the demo for an example.

Props

autoOpen boolean ▶︎ false
Open the Floater automatically.

callback (action: 'open' | 'close', props: Props) => void
It will be called when the Floater changes state.

children ReactNode
An element to trigger the Floater.

component ComponentType | ReactElement
A React element or function to use as a custom UI for the Floater.
The prop closeFn will be available in your component.

content ReactNode
The Floater content. It can be anything that can be rendered.
This is required unless you pass a component.

debug boolean ▶︎ false
Log some basic actions.
You can also set a global variable ReactFloaterDebug = true;

disableFlip boolean ▶︎ false
Disable changes in the Floater position on scroll/resize.

disableHoverToClick boolean ▶︎ false
Don't convert the hover event to click on mobile.

event 'hover' | 'click' ▶︎ click
The event that will trigger the Floater.

This won't work in a controlled mode.

eventDelay number ▶︎ 0.4
The amount of time (in seconds) the floater should wait after a mouseLeave event before hiding.

Only valid for event type hover.

footer ReactNode
It can be anything that can be rendered.

getPopper (popper: PopperInstance, origin: 'floater' | 'wrapper') => void
Get the popper.js instance.

hideArrow boolean ▶︎ 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 boolean
The switch between normal and controlled modes.

Setting this prop will disable normal behavior.

modifiers PopperModifiers
Customize popper.js modifiers.

interface PopperModifiers {
  applyStyles?: Partial<ApplyStylesModifier>;
  arrow?: Partial<ArrowModifier>;
  computeStyles?: Partial<ComputeStylesModifier>;
  eventListeners?: Partial<EventListenersModifier>;
  flip?: Partial<FlipModifier>;
  hide?: Partial<HideModifier>;
  offset?: Partial<OffsetModifier>;
  popperOffsets?: Partial<PopperOffsetsModifier>;
  preventOverflow?: Partial<PreventOverflowModifier>;
}

Don't use it unless you know what you're doing

placement Placement ▶︎ bottom
The placement of the Floater. It will update the position if there's no space available.

type Placement = 
| "auto" | "auto-start" | "auto-end"
| "top" | "top-start" | "top-end"
| "bottom" | "bottom-start" | "bottom-end"
| "right"| "right-start" | "right-end"
| "left" | "left-start" | "left-end"
| "center"

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

showCloseButton boolean ▶︎ false
It will show a ⨉ button to close the Floater.
This will be true when you change the wrapperOptions position.

styles Styles
Customize the UI.

interface Styles {
  arrow: CSSProperties & {
    length: number;
    spread: number;
  };
  close: CSSProperties;
  container: CSSProperties;
  content: CSSProperties;
  floater: CSSProperties;
  floaterCentered: CSSProperties;
  floaterClosing: CSSProperties;
  floaterOpening: CSSProperties;
  floaterWithAnimation: CSSProperties;
  floaterWithComponent: CSSProperties;
  footer: CSSProperties;
  options: {
    zIndex: number;
  };
  title: CSSProperties;
  wrapper: CSSProperties;
  wrapperPosition: CSSProperties;
}

target string | HTMLElement
The target element to calculate the Floater position. It will use the children as the target if it's not set.

title ReactNode
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 a negative value.
  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
It is 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
Setting a boolean to the open prop will enter the controlled mode and 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>