Breathing Text
fancy/breathing-textFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/breathing-text.jsonSource
1"use client"23import { ElementType } from "react"4import { motion, Transition, Variants } from "motion/react"56import { cn } from "@/lib/utils"78interface TextProps extends React.HTMLAttributes<HTMLElement> {9 /**10 * The content to be displayed and animated11 */12 children: React.ReactNode1314 /**15 * HTML Tag to render the component as16 */17 as?: ElementType1819 /**20 * Initial font variation settings21 */22 fromFontVariationSettings: string2324 /**25 * Target font variation settings to animate to26 */27 toFontVariationSettings: string2829 /**30 * Animation transition configuration31 * @default { duration: 1.5, ease: "easeInOut" }32 */33 transition?: Transition3435 /**36 * Duration of stagger delay between elements in seconds37 * @default 0.138 */39 staggerDuration?: number4041 /**42 * Direction to stagger animations from43 * @default "first"44 */45 staggerFrom?: "first" | "last" | "center" | number4647 /**48 * Delay between animation repeats in seconds49 * @default 0.150 */51 repeatDelay?: number52}5354const BreathingText = ({55 children,56 as = "span",57 fromFontVariationSettings,58 toFontVariationSettings,59 transition = {60 duration: 1.5,61 ease: "easeInOut",62 },63 staggerDuration = 0.1,64 staggerFrom = "first",65 repeatDelay = 0.1,66 className,67 ...props68}: TextProps) => {69 const letterVariants: Variants = {70 initial: { fontVariationSettings: fromFontVariationSettings },71 animate: (i) => ({72 fontVariationSettings: toFontVariationSettings,73 transition: {74 ...transition,75 repeat: Infinity,76 repeatType: "mirror",77 delay: i * staggerDuration,78 repeatDelay: repeatDelay,79 },80 }),81 }8283 const getCustomIndex = (index: number, total: number) => {84 if (typeof staggerFrom === "number") {85 return Math.abs(index - staggerFrom)86 }87 switch (staggerFrom) {88 case "first":89 return index90 case "last":91 return total - 1 - index92 case "center":93 default:94 return Math.abs(index - Math.floor(total / 2))95 }96 }9798 const letters = String(children).split("")99 const ElementTag = as100101 return (102 <ElementTag103 className={cn(104 className,105 // an after pseudo element is used to create a container large enough to hold the text with full weight. Helps avoid layout shifts106// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep | |
| Elastic Lineelastic-line | fancy | Components | Free | 1 dep |
