Docs
Underline To Background

Underline To Background

A text component that animates a text underline into a text background.

Weeklygoodiesdeliveredstraighttoyourinboxsubscribe

Source code


Understanding the component


The component creates a separate div element positioned absolutely below the text (instead of the regular underline elements with CSS pseudo-elements). It animates the height from a thin line (controlled by underlineHeightRatio) to cover the full text height, effectively becoming a background. Simultaneously, it transitions the text color to maintain contrast against the expanding background.

Props


PropTypeDefaultDescription
label*string-The text to be displayed
classNamestringundefinedAdditional CSS classes for styling
transitionValueAnimationTransition{ type: "spring", damping: 30, stiffness: 300 }Animation configuration for the underline-to-background effect. Refer to framer-motion docs for more details
onClick() => voidundefinedCallback function when the text is clicked
targetTextColor*string"#fef"The color of the text when the background animation is complete
underlineHeightRationumber0.1The height of the underline as a ratio of the font size
underlinePaddingRationumber0.01The padding of the underline as a ratio of the font size