HoverFill
is a versatile React wrapper component that creates an interactive, animated hover fill effect. It uses GSAP (GreenSock Animation Platform) to create smooth, directional sliding animations that respond to mouse interactions.
Prop | Type | Default | Description |
---|---|---|---|
as |
ElementType |
'div' |
The component type to render as |
fillColor |
string |
'white' |
Color of the SVG fill effect |
fillOpacity |
number |
1 |
Opacity of the SVG fill effect |
fillDuration |
number |
0.5 |
Animation duration in seconds |
fillPin |
boolean |
false |
Pins the fill overlay |
fillInvertColors |
boolean |
false |
Invert the colors behind the SVG using blend mode |
fillOnFocus |
boolean |
false |
Animate tab navigation (must be a tabbable element) |
fillFocusEnter |
'up' | 'down' | 'left' | 'right' |
'up' |
Animation direction for focus |
fillFocusLeave |
'up' | 'down' | 'left' | 'right' |
'down' |
Animation direction for blur |
fillInvert |
boolean |
false |
Invert the animation direction for mouse enter/leave |
fillZ |
'auto' | number |
fillInvertColors ? 'auto' : -1 |
The z-index of the SVG overlay |
import HoverFill from '@/components/HoverFill';
function MyComponent() {
return (
<HoverFill
as="button"
fillInvertColors={true}
style={{ position: 'relative' }} // Important for SVG positioning
>
Hover me
</HoverFill>
);
}
HoverFill
must have aposition
value ofrelative
,absolute
, orfixed
for the SVG overlay to correctly fill the element.
The HoverFill
component creates an SVG overlay that animates dynamically based on the mouse enter and leave directions. Key features include:
- Wrapper component that can be applied to any React element
- Highly customizable animation parameters
- Can trigger animations programmatically from the parent
- Performance-optimized with GSAP and React hooks
- Supports both mouse and keyboard interactions
function MyComponent() {
const hoverFillRef = useRef(null);
return (
<HoverFill
ref={hoverFillRef}
onClick={console.log(hoverFillRef.current)}
></HoverFill>
);
}
- slideDownOut
- slideUpIn
- slideUpOut
- slideDownIn
- slideLeftIn
- slideRightIn
- slideLeftOut
- slideRightOut
- React
- GSAP
- @gsap/react
MIT License