Gradient Text
gradient-textuiApplies a CSS gradient as text color via background-clip: text. Supports preset gradients (sunset, ocean, forest, fire, candy, aurora, rainbow, gold, neon, grape), custom from/to colors with a direction, a fully custom CSS gradient string, and an animated mode that shifts the gradient.
Installation
$pnpm dlx uipkge-ng@latest add gradient-text$npx uipkge-ng@latest add gradient-text$yarn dlx uipkge-ng@latest add gradient-text$bunx uipkge-ng@latest add gradient-textManifest:
https://uipkge.dev/r/angular/gradient-text.jsonInstalls to:src/app/components/ui/gradient-text/Examples
Loading interactive previews…
Loading interactive previews…
Props
| Name | Type / Values | Default | Required |
|---|---|---|---|
preset | GradientPreset | — | optional |
from | string | — | optional |
to | string | — | optional |
direction | GradientDirection | to right | optional |
gradient | string | — | optional |
animated | boolean | false | optional |
animationDuration | number | 4 | optional |
class | string | — | optional |
npm dependencies
Files installed (3)
src/app/components/ui/gradient-text/gradient-text.component.ts2.9 kB
import { Component, Input, booleanAttribute, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core' import { cn } from '@/lib/utils' import { gradientTextPresets, gradientTextVariants, type GradientPreset, type GradientTextVariants, } from './gradient-text.variants' // Copied verbatim from the React gradient-text (injected there as a global <style>). Unscoped // (ViewEncapsulation.None) so it reaches the host and projected content; Angular adds it once. const GRADIENT_TEXT_MOTION_STYLES = ` @media (prefers-reduced-motion: no-preference) { @keyframes gradient-text-shift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } } ` export type GradientDirection = | 'to right' | 'to left' | 'to top' | 'to bottom' | 'to top right' | 'to top left' | 'to bottom right' | 'to bottom left' /** * Applies a CSS gradient as text color via background-clip: text (React `GradientText`). * React's `as` / `asChild` map to the attribute form: `<h1 ui-gradient-text>` renders the * gradient on that element. Consumer `[style]` bindings on the host merge with the gradient * styles, like React's `style` spread. */ @Component({ changeDetection: ChangeDetectionStrategy.Eager, selector: 'ui-gradient-text, [ui-gradient-text]', standalone: true, encapsulation: ViewEncapsulation.None, styles: [GRADIENT_TEXT_MOTION_STYLES], host: { 'data-uipkge': '', 'data-slot': 'gradient-text', '[attr.data-preset]': 'preset ?? null', '[attr.data-animated]': 'animated ? "true" : null', '[style.background-image]': 'gradientValue', '[style.background-clip]': '"text"', '[style.-webkit-background-clip]': '"text"', '[style.color]': '"transparent"', '[style.-webkit-text-fill-color]': '"transparent"', '[style.background-size]': 'animated ? "200% 200%" : null', '[class]': 'hostClass', }, template: `<ng-content />`, }) export class UiGradientTextComponent { @Input() preset?: GradientPreset @Input() from?: string @Input() to?: string @Input() direction: GradientDirection = 'to right' @Input() gradient?: string @Input({ transform: booleanAttribute }) animated = false @Input() animationDuration = 4 @Input('class') className?: string get gradientValue(): string { if (this.gradient) return this.gradient if (this.preset) return gradientTextPresets[this.preset] ?? '' if (this.from && this.to) return `linear-gradient(${this.direction}, ${this.from}, ${this.to})` return 'linear-gradient(to right, var(--primary), var(--primary))' } get hostClass(): string { return cn( gradientTextVariants({} as GradientTextVariants), this.animated ? `motion-safe:animate-[gradient-text-shift_${this.animationDuration}s_ease_infinite]` : '', this.className, ) } } export { gradientTextPresets, gradientTextVariants, type GradientPreset, type GradientTextVariants }src/app/components/ui/gradient-text/gradient-text.variants.ts1.2 kB
import type { VariantProps } from 'class-variance-authority' import { cva } from 'class-variance-authority' /** * Preset gradients keyed by name. Each value is a full CSS gradient string * applied as `background-image` with `background-clip: text`. */ export const gradientTextPresets = { sunset: 'linear-gradient(to right, #ff7e5f, #feb47b)', ocean: 'linear-gradient(to right, #2193b0, #6dd5ed)', forest: 'linear-gradient(to right, #11998e, #38ef7d)', fire: 'linear-gradient(to right, #f12711, #f5af19)', candy: 'linear-gradient(to right, #f857a6, #ff8a5c)', aurora: 'linear-gradient(to right, #00c6ff, #0072ff, #00c6ff)', rainbow: 'linear-gradient(to right, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3)', gold: 'linear-gradient(to right, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c)', neon: 'linear-gradient(to right, #00f260, #0575e6)', grape: 'linear-gradient(to right, #6a11cb, #2575fc)', } as const export type GradientPreset = keyof typeof gradientTextPresets export const gradientTextVariants = cva('inline-block', { variants: {}, defaultVariants: {}, }) export type GradientTextVariants = VariantProps<typeof gradientTextVariants>src/app/components/ui/gradient-text/index.ts0.2 kB
export { UiGradientTextComponent, gradientTextPresets, gradientTextVariants } from './gradient-text.component' export type { GradientDirection, GradientPreset, GradientTextVariants } from './gradient-text.component'
Raw manifest:https://uipkge.dev/r/angular/gradient-text.json