An open API service indexing awesome lists of open source software.

https://github.com/paulrosset/rehover

👐 React hovering on two elements made simpler!
https://github.com/paulrosset/rehover

animation hover react react-hovering

Last synced: 6 months ago
JSON representation

👐 React hovering on two elements made simpler!

Awesome Lists containing this project

README

          

# Rehover 👐

#### React hovering on two elements made simpler!

[![Travis CI Build Status](https://travis-ci.org/PaulRosset/rehover.svg?branch=master)](https://travis-ci.org/PaulRosset/rehover)
[![npm version](https://badge.fury.io/js/rehover.svg)](https://badge.fury.io/js/rehover)

![](demo.gif)

## Install

```sh
yarn add rehover
```

## Usage

> React v16.0 required, [rendering arrays in render method.](https://reactjs.org/blog/2017/09/26/react-v16.0.html)

### To build something quickly...

If you don't need to build something very complex, `Rehover` component is what you need, like the example below:

* **Pros**:
* Easy to get started
* Very light to write (not verbose)
* **Cons**:
* Not very customizable
* Restricted to 2 children only

```js
import React from "react";
import { Rehover } from "rehover";
```

```jsx

Hover me!


A
B
C

```

### To go further...

However, if you want to write something more customizable and complex, you should try the example below, which is using the [**new Context API from React**](https://reactjs.org/docs/context.html).

* **Pros**:
* You are free to customize, you are not anymore restricted to two childrens.
* You are using the new context API 🔥
* **Cons**:

* Much more verbose.
* Longer to write.

```js
import React from "react";
import { RehoverProvider, RehoverConsumer } from "rehover";
```

```jsx


{({ states, actions }) => (



Hover me !

{states.isOnSource || states.isOnTarget ? (

List of items:



Item1

Item2

Item3



) : null}

)}

```

> The new React context Api is available since the 16.3.0 version.

## API

* Delay: Number `delay`

* To let you the time to go to the target.

* States: Function `states`
* Function with `isOpen`, `isOntarget` and `isOnSource` as parameter `Boolean`, to let you construct animation for example.

> If you want to pass a **_React Component_** as a source or destination, make sure that they got a onMouseEnter props and a onMouseLeave props at their root.

## Live demo/Sandbox

[![Edit j2rjln010w](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/0o78oxx3w0)

## License

MIT Paul Rosset