Text Gradient
abui/text-gradientFreeComponent
A text gradient effect component.
Live preview
live · rendered by the registry
Rendered by abui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://abui.io/r/text-gradient.jsonSource
1import * as React from "react"2import { cn } from "@/lib/utils"34type CSSVariableStyle = React.CSSProperties & {5 "--spread"?: string6}78interface TextGradientProps extends React.HTMLAttributes<HTMLSpanElement> {9 children: React.ReactNode10 /**11 * The spread distance for the gradient effect in pixels12 * @default 2213 */14 spread?: number15 /**16 * The background color for the gradient highlight17 * Can be a CSS variable or any valid CSS color18 * @default "hsl(var(--background))"19 */20 highlightColor?: string21 /**22 * The base text color (shows through the gradient)23 * Can be a CSS variable or any valid CSS color24 * @default "hsl(var(--muted-foreground))"25 */26 baseColor?: string27 /**28 * Animation duration in seconds29 * @default 330 */31 duration?: number32}3334const TextGradient = React.forwardRef<HTMLSpanElement, TextGradientProps>(35 (36 {37 children,38 className,39 spread = 22,40 highlightColor = "var(--background)",41 baseColor = "var(--muted-foreground)",42 duration = 2,43 style,44 ...props45 },46 ref,47 ) => {48 const inlineStyle: CSSVariableStyle = {49 "--spread": `${spread}px`,50 ...style,51 backgroundImage: `linear-gradient(90deg, transparent calc(50% - var(--spread)), ${highlightColor} 50%, transparent calc(50% + var(--spread))), linear-gradient(${baseColor}, ${baseColor})`,52 backgroundSize: "250% 100%, 100% 100%",53 animation: `text-gradient-shift ${duration}s linear infinite`,54 }5556 return (57 <span58 ref={ref}59 className={cn(60 "relative inline-block bg-clip-text text-transparent",61 "[background-repeat:no-repeat,padding-box]",62 className,63 )}64 style={inlineStyle}65 {...props}66 >67 <style>68 {`69 @keyframes text-gradient-shift {70 from { background-position: 100% center; }71 to { background-position: 0% center; }72 }73 `}74 </style>75 {children}76 </span>77 )78 },79)8081TextGradient.displayName = "TextGradient"8283export { TextGradient }84export default TextGradient
Files it writes
More from abui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordion Multiselectaccordion-multiselect | abui | Components | Free | 3 deps | |
| Breakpoint Displaybreakpoint-display | abui | Components | Free | no deps | |
| Color Swatch Selectorcolor-swatch-selector | abui | Components | Free | no deps | |
| Label Selectorlabel-selector | abui | Components | Free | 2 deps | |
| Radio Rowsradio-rows | abui | Components | Free | no deps | |
| Radio Tabsradio-tabs | abui | Components | Free | no deps | |
| Scroll Progressscroll-progress | abui | Components | Free | 1 dep | |
| Spinnerspinner | abui | Components | Free | 1 dep |
