react-see-through
Edit page
<SeeThrough><SeeThroughController>PropsImportingMultiple active SeeThroughs at onceWhen should you have multiple active SeeThroughs?How do different SeeThroughs know their "active" prop should be true at the same time?

SeeThroughController

This component is necessary if you want to have multiple active SeeThroughs at once

Props

children
any

Anything. All <SeeThrough> elements under this will be tied to this controller and be able to be active at the same time.

maskColor
string
"rgba(0, 0, 0, 0.4)"

The color of the mask around all nested <SeeThrough>s. Supports all canvas fillStyle formats, e.g. “#AAA333”, “red”, “rgba(10, 12, 8, 0.2)”, …

Importing

To use the SeeThroughController, you want to do:

import { SeeThroughController } from 'react-see-through';

after installing.

Multiple active SeeThroughs at once

Differences:

  • There's a SeeThroughController above all of the related SeeThroughs
  • All of the SeeThroughs' onClick handlers are triggered
  • maskColor is now defined on the controller so that it's the same for all SeeThroughs
My cool content
My cool content somewhere else on the page

When should you have multiple active SeeThroughs?

Suppose that you have a popup that's always in the same position and the popup is associated with some element on the page:

A calendar website with an event and a popup both see-through

In this example there are two active SeeThroughs at the same time: one around the time on the calendar and one around the drawer at the bottom.

This can't be done with one active SeeThrough because both elements are far apart in the DOM and moving a single SeeThrough high up in the tree would result in almost everything being see through.


How do different SeeThroughs know their "active" prop should be true at the same time?

You'll need your own way of passing that information to them. Some common ways are through React contexts or Redux.