Updated
Spill Textarea
Customize
Limit80
Fall, leave a gap
Gravity1.0
Warn at0.80
Count from20
Color
Warn colour
Radius16px
Installation
npx shadcn@latest add https://uibrik.com/r/spill-textarea.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/spill-textarea/spill-textarea.tsx"use client"; import { motion, useReducedMotion } from "motion/react"; import { useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; // Letters falling at once, however much is pasted past the limit. const MAX_PIECES = 24; // Pixels per second squared: reads as a small real object dropping. const G = 2400; // Seconds a letter sits in place, turning red, before it falls. const HOLD = 0.09; const FONT = 15; const LINE = 22; const PAD = 14; const cp = (s: string, utf16: number) => [...s.slice(0, utf16)].length; type Piece = { el: HTMLSpanElement; x: number; y: number; dir: number; vx: number; vy: number; w: number; spin: number; start: number; hold: number }; export type SpillTextareaProps = {
Adds the files to
components/uibrik/spill-textarea and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/spill-textarea.Usage
import { SpillTextarea } from "@/components/uibrik/spill-textarea/spill-textarea";const defaultValue = "Shipping the new editor today. Drafts now save as you type and sync across";<SpillTextarea limit={80} overflow="fall" gravity={1} warnAt={0.8} countFrom={20} color="#ef4444" warnColor="#f59e0b" radius={16} defaultValue={defaultValue} placeholder="What's happening?" label="Message" minRows={3} maxRows={8} onChange={(value, over) => {}} // value="…"/>Where to use Spill Textarea
Post composers
Short-form posts and replies show their limit without a wall of numbers.
Pairs with Prompt Input
Bios and descriptions
Profile and listing fields make going over obvious before the save fails.
Pairs with Settings Page
SMS and push copy
Message writers see exactly which characters won't fit.
Props
SpillTextarea- limit
- Type number
- 80
- Characters allowed before letters fall.
- overflow
- Type "fall" | "copy"
- "fall"
- What happens to a letter typed past the limit.
- gravity
- Type number
- 1
- How hard letters fall.
- warnAt
- Type number
- 0.8
- Share of the limit at which the ring turns amber.
- countFrom
- Type number
- 20
- Remaining characters at which the number appears.
- color
- Type string
- "#ef4444"
- Colour of over-limit letters.
- warnColor
- Type string
- "#f59e0b"
- Ring colour near the limit.
- radius
- Type number
- 16
- Corner radius.
- value
- Type string
- –
- Controlled value.
- defaultValue
- Type string
- ""
- Starting text when uncontrolled.
- onChange
- Type (value: string, over: boolean) => void
- –
- Called with the text and whether it is over the limit.
- placeholder
- Type string
- "What's happening?"
- Placeholder text.
- label
- Type string
- "Message"
- Accessible name for the field.
- minRows
- Type number
- 3
- Rows shown when empty.
- maxRows
- Type number
- 8
- Rows it grows to before scrolling.
- className
- Type string
- –
- Classes for the wrapper.