flip-text
vengenceui/flip-textFreeComponent
vengenceui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by vengenceui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.vengenceui.com/r/flip-text.jsonSource
1"use client";23import React, { useMemo } from "react";4import { cn } from "@/lib/utils";56interface FlipTextProps {7 /**8 * Additional CSS classes for the wrapper9 */10 className?: string;1112 /**13 * The text content to animate (will be split by spaces)14 */15 children: string;1617 /**18 * Duration of the flip animation in seconds19 * @default 2.220 */21 duration?: number;2223 /**24 * Initial delay before animation starts in seconds25 * @default 026 */27 delay?: number;2829 /**30 * Whether the animation should loop infinitely31 * @default true32 */33 loop?: boolean;3435 /**36 * Custom separator for splitting text (default is space)37 * @default " "38 */39 separator?: string;4041 /**42 * Whether all characters should animate together (no stagger)43 * @default false44 */45 together?: boolean;46}4748export function FlipText({49 className,50 children,51 duration = 2.2,52 delay = 0,53 loop = true,54 separator = " ",55 together = false,56}: FlipTextProps) {57 const words = useMemo(() => children.split(separator), [children, separator]);58 const totalChars = children.length;5960 // Calculate character index for each position61 const getCharIndex = (wordIndex: number, charIndex: number) => {62 let index = 0;63 for (let i = 0; i < wordIndex; i++) {64 index += words[i].length + (separator === " " ? 1 : separator.length);65 }66 return index + charIndex;67 };6869 return (70 <div71 className={cn(72 "flip-text-wrapper inline-block leading-none",73 className74 )}75 style={{ perspective: "1000px" }}76 >77 {words.map((word, wordIndex) => {78 const chars = word.split("");7980 return (81 <span82 key={wordIndex}83 className="word inline-block whitespace-nowrap"84 style={{ transformStyle: "preserve-3d" }}85 >86 {chars.map((char, charIndex) => {87 const currentGlobalIndex = getCharIndex(wordIndex, charIndex);8889 // Calculate delay - if together, use same delay for all90 let calculatedDelay = delay;91 if (!together) {92 const normalizedIndex = currentGlobalIndex / totalChars;93// … truncated
Files it writes
More from vengenceui
All 128 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | vengenceui | Components | Free | 2 deps | |
| agent-bento-gridagent-bento-grid | vengenceui | Components | Free | 1 dep | |
| alertalert | vengenceui | Components | Free | no deps | |
| animated-buttonanimated-button | vengenceui | Components | Free | 1 dep | |
| animated-footeranimated-footer | vengenceui | Components | Free | 2 deps | |
| animated-numberanimated-number | vengenceui | Components | Free | 1 dep | |
| animated-raysanimated-rays | vengenceui | Components | Free | no deps | |
| animated-tooltipanimated-tooltip | vengenceui | Components | Free | 1 dep |
