Letter 3d Swap
fancy/letter-3d-swapFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/letter-3d-swap.jsonSource
1"use client"23import React, { ElementType, useCallback, useMemo, useState } from "react"4import {5 AnimationOptions,6 useAnimate,7 ValueAnimationTransition,8} from "motion/react"910import { cn } from "@/lib/utils"1112// handy function to split text into characters with support for unicode and emojis13const splitIntoCharacters = (text: string): string[] => {14 if (typeof Intl !== "undefined" && "Segmenter" in Intl) {15 const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" })16 return Array.from(segmenter.segment(text), ({ segment }) => segment)17 }18 // Fallback for browsers that don't support Intl.Segmenter19 return Array.from(text)20}2122// handy function to extract text from children23const extractTextFromChildren = (children: React.ReactNode): string | undefined => {24 // Handle null/undefined25 if (children == null) return ""2627 // Handle string28 if (typeof children === "string") return children2930 // Handle number31 if (typeof children === "number") return String(children)3233 // Handle arrays (including fragments)34 if (Array.isArray(children)) {35 return children.map(extractTextFromChildren).join("")36 }3738 // Handle React elements39 if (React.isValidElement(children)) {40 const props = (children as React.ReactElement).props41 const childText = (props as any).children as React.ReactNode4243 // Recursively extract text from children44 if (childText != null) {45 return extractTextFromChildren(childText)46 }4748 return ""49 }50}5152/**53 * Internal helper interface for representing a word in the text with its characters and spacing information54 */55interface WordObject {56 /**57 * Array of individual characters in the word58 */59 characters: string[]60 /**61 * Whether this word needs a space after it62 */63 needsSpace: boolean64}6566interface Letter3DSwapProps {67 /**68 * The content to be displayed and animated69 */70 children: React.ReactNode7172 /**73 * HTML Tag to render the component as74 */75 as?: ElementType76 /**77 * Class name for the main container element.78 */79 mainClassName?: string8081 /**82 * Class name for the front face element.83 */84 frontFaceClassName?: string8586 /**87 * Class name for the secondary face element.88 */89 secondFaceClassName?: string9091 /**92 * Duration of stagger delay between elements in seconds.93 * @default 0.0594 */95 staggerDuration?: number9697 /**98 * Direction to stagger animations from.99 * @default "first"100 */101// … 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 | |
| Breathing Textbreathing-text | 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 |
