Styled textarea
Five multi-line field treatments: an underline, a floating label, a focus glow, a filled surface and a character counter. Each is sized, token-driven and wraps a real textarea.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/textarea-styledDependencies, the @ai2/tokens theme and the component file are installed together.
Copy the source
components/ui/textarea-styled.tsx"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
/* Textarea family: 5 decorative multi-line text fields. Color comes ONLY from
tokens. Size = min-height. The focus effects are CSS (focus-within / peer) +
token transitions; the transform-based ones are protected with motion-reduce.
Each one wraps a real <textarea> and passes through all the native props. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const height: Record<StyledSize, string> = {
sm: "min-h-16 text-sm",
md: "min-h-20 text-sm",
lg: "min-h-24 text-base",
xl: "min-h-28 text-base",
}
const fieldBase =
"w-full resize-y bg-transparent text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
type Props = React.ComponentProps<"textarea"> & { size?: StyledSize }
/* Underline: no frame, with a token line growing from the center along the bottom
on focus. */
export function UnderlineTextarea({ className, size = "md", ...props }: Props) {
return (
<span data-slot="styled-textarea" className={cn("relative flex w-72 max-w-full flex-col border-b border-border", height[size], className)}>
<textarea {...props} className={cn(fieldBase, "peer flex-1 px-1 py-1.5", height[size])} />
<span className="pointer-events-none absolute inset-x-0 bottom-[-1px] h-0.5 origin-center scale-x-0 bg-primary transition-transform duration-(--motion-base) ease-(--motion-ease) peer-focus:scale-x-100 motion-reduce:transition-none" />
</span>
)
}
/* Float: odakta / dolu iken yukari suzulen etiket (placeholder=" " + peer). */
export function FloatTextarea({ className, size = "md", id, ...props }: Props) {
const autoId = React.useId()
const areaId = id ?? autoId
return (
<span data-slot="styled-textarea" className={cn("relative flex w-72 max-w-full flex-col rounded-lg border border-border px-3 pt-5 pb-2", height[size], className)}>
<textarea id={areaId} placeholder=" " {...props} className={cn(fieldBase, "peer flex-1", height[size])} />
<label
htmlFor={areaId}
className="pointer-events-none absolute left-3 top-4 bg-background px-1 text-muted-foreground transition-all duration-(--motion-base) peer-focus:top-0 peer-focus:-translate-y-1/2 peer-focus:text-xs peer-focus:text-primary peer-[:not(:placeholder-shown)]:top-0 peer-[:not(:placeholder-shown)]:-translate-y-1/2 peer-[:not(:placeholder-shown)]:text-xs motion-reduce:transition-none"
>
Label
</label>
</span>
)
}
/* Glow: odakta token isima halkasi (focus-within box-shadow). */
export function GlowTextarea({ className, size = "md", ...props }: Props) {
return (
<span
data-slot="styled-textarea"
className={cn(
"relative flex w-72 max-w-full flex-col rounded-lg border border-border px-3 py-2 transition-shadow duration-(--motion-base) focus-within:border-info focus-within:shadow-[0_0_0_3px_color-mix(in_oklab,var(--color-info)_25%,transparent)]",
height[size],
className
)}
>
<textarea {...props} className={cn(fieldBase, "flex-1", height[size])} />
</span>
)
}
/* Filled: dolu yuzey + odakta alttan token vurgu cizgisi. */
export function FilledTextarea({ className, size = "md", ...props }: Props) {
return (
<span data-slot="styled-textarea" className={cn("relative flex w-72 max-w-full flex-col overflow-hidden rounded-t-lg border-b border-border bg-surface-2 px-3 py-2", height[size], className)}>
<textarea {...props} className={cn(fieldBase, "peer flex-1", height[size])} />
<span className="pointer-events-none absolute inset-x-0 bottom-[-1px] h-0.5 origin-center scale-x-0 bg-primary transition-transform duration-(--motion-base) ease-(--motion-ease) peer-focus:scale-x-100 motion-reduce:transition-none" />
</span>
)
}
/* Count: kosede canli karakter sayaci; value uzunlugunu okur, maxLength alir. */
export function CountTextarea({ className, size = "md", value, defaultValue, maxLength, onChange, ...props }: Props) {
const initial = String(value ?? defaultValue ?? "").length
const [count, setCount] = React.useState(initial)
React.useEffect(() => {
if (value !== undefined) setCount(String(value).length)
}, [value])
function handleChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
setCount(event.target.value.length)
onChange?.(event)
}
return (
<span data-slot="styled-textarea" className={cn("relative flex w-72 max-w-full flex-col rounded-lg border border-border px-3 pt-2 pb-6 transition-colors focus-within:border-primary", height[size], className)}>
<textarea
value={value}
defaultValue={defaultValue}
maxLength={maxLength}
onChange={handleChange}
{...props}
className={cn(fieldBase, "flex-1", height[size])}
/>
<span className="pointer-events-none absolute bottom-1.5 right-3 text-xs tabular-nums text-muted-foreground">
{maxLength ? `${count}/${maxLength}` : count}
</span>
</span>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Underline
Borderless, with a token underline that grows from the center on focus.
import { UnderlineTextarea } from "@/components/ui/textarea-styled"
<UnderlineTextarea placeholder="Message" />Float
A label that floats up on focus or when filled.
import { FloatTextarea } from "@/components/ui/textarea-styled"
<FloatTextarea />Glow
A token glow ring blooms on focus.
import { GlowTextarea } from "@/components/ui/textarea-styled"
<GlowTextarea placeholder="Message" />Filled
A filled surface with a token accent bar on focus.
import { FilledTextarea } from "@/components/ui/textarea-styled"
<FilledTextarea placeholder="Message" />Count
A live character counter in the corner.
import { CountTextarea } from "@/components/ui/textarea-styled"
<CountTextarea placeholder="Bio" maxLength={120} />ai2 Styled textarea: 5 styled variations on the token system
The ai2 Styled textarea are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around multi-line field treatments. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: focus effects run on token CSS transitions; transform-based ones respect reduced motion. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the underline and label transitions are disabled and the fields still focus.
What is in the ai2 Styled textarea?
5 exports in one file: Underline, Float, Glow, Filled and Count. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: focus effects run on token CSS transitions; transform-based ones respect reduced motion.
- Reduced-motion aware: Under prefers-reduced-motion, the underline and label transitions are disabled and the fields still focus.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Styled textarea sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.