Updated
Draggable Letters
Customize
Falloff0.50
Settle0.45s
Bounce0.15
Text size48px
Installation
npx shadcn@latest add https://uibrik.com/r/draggable-letters.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/draggable-letters/draggable-letters.tsx"use client"; import { cn } from "@/lib/utils"; import { animate, motion, useMotionValue, useTransform, type MotionValue } from "motion/react"; import { useEffect } from "react"; // `play` counts presses of a card's Change button. 0 means the card has not // been pressed yet, so every effect renders its resting state without // animating on page load. export type EffectProps = { play: number }; // Size comes from --text-effect-size (default 1.25rem, i.e. text-xl), so a // preview can enlarge every effect without changing the installed default. const SIZE = "text-[length:var(--text-effect-size,1.25rem)] leading-[1.4]"; const TEXT = `${SIZE} text-zinc-700 font-medium dark:text-zinc-200`; const glyph = (ch: string) => (ch === " " ? " " : ch); // 11 — Any letter can be pulled. Its neighbours follow at half the distance // per step away, and everything settles home on release. Pressing Change // gives the middle letter a small tug. export function DraggableLetters({ play,
Adds the files to
components/uibrik/draggable-letters and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/draggable-letters.Usage
import { DraggableLetters } from "@/components/uibrik/draggable-letters/draggable-letters";<DraggableLetters play={0} text="Pull me apart" falloff={0.5} settleDuration={0.45} bounce={0.15}/>Where to use Draggable Letters
Portfolio heroes
Letters you can pull apart invite visitors to play with a name or title.
404 and empty pages
Something to drag turns a dead end into a moment of delight.
Creative agency sites
Springy, physical type suits studios that want their site to feel hands-on.
Props
DraggableLetters- text
- Type string
- "Pull me apart"
- The copy to animate.
- falloff
- Type number
- 0.5
- Share of the pull each neighbour follows, per step away.
- settleDuration
- Type number
- 0.45
- Time to spring home.
- bounce
- Type number
- 0.15
- Spring bounce on release.
- playrequired
- Type number
- –
- Each change plays the effect again; 0 shows its resting state.