React glow Add a mouse-tracing glow effect to React components. The glow effect will only work using the mouse as the pointer. Touch events…
React glow Add a mouse-tracing glow effect to React components. The glow effect will only work using the mouse as the pointer. Touch events…
Add a mouse-tracing glow effect to React components.
The glow effect will only work using the mouse as the pointer. Touch events will not trigger it.
See it live on codaworks.com.
Install the package with npm:
npm i @codaworks/react-glowWrap any number of components in a which will be used to track the mouse location.
This won't glow
This will glow purple when the mouse is passed over
Children of `` can style themselves how to look when glowing. You might choose to leave some children unchanged, or highlight them with the glow: variant style.
The value of color will be available as a CSS variable --glow-color, as well as the Tailwind glow color.
You can pass any valid CSS color, including hsl() values etc.
Of course, you might choose to use any other color; you can leave out the color prop entirely.
Add the tailwind plugin to unlock the glow: variant and glow color
tailwind.config.js
module.exports = {
...
plugins: [
require('@codaworks/react-glow/tailwind')
]
}As with all colors in Tailwind, you may add opacity by appending a percentage after the color, such as bg-glow/20 for 20% opacity.
You can style the glow effect with vanilla CSS:
This won't glow
This will glow pink when the mouse is passed over
.glowable-text {
color: black;
}
[glow] .glowable-text {
color: var(--glow-color);
}The `` component clones the children tree. The cloned tree is then stacked on top of the original tree.
The overlay tree is transparent, and we only reveal parts using a CSS radial gradient mask. The mask position is updated
by tracking the mouse position.
When you use the glow: variant or [glow] attribute selector, it only targets the overlay.
In order to not block mouse events, the overlay is set to pointer-events: none.
We use the to track the mouse; the itself also keeps track of its position inside the ``.
The fact that we clone the children tree has some implications that is important to keep in mind:
children small. Use a separate for each logical set of children (such as a single card).glow:. Keep the glow styles to just visuals, such as colors, opacity, and a slight scale might also work sometimes.Inspired by this tweet.
No open issues yet, or sync has not completed.