A box that grows by whole lines, and shades the exact characters that are over the limit.
The prompt12,754 characters
Add the "Textarea" component from notboring to my project.
It is licensed for use in my projects — notboring.dev/license. Please:
1. Create the component at a sensible path for this
project, named Textarea, from the source below.
2. It needs nothing beyond React.
3. Add the CSS to the project's stylesheet.
4. THE PART THAT NEEDS YOUR JUDGMENT. The CSS reads
these custom properties and does not define them:
--card
--danger
--danger-rgb
--font-ui
--ink
--ink-2
--ink-4
--ink-5
--ink-rgb
They are notboring's design tokens. Map each one to
whatever this project already uses for the same
job — its own ink, ground, surface and UI font —
rather than defining them as new globals. If the
project has no equivalent, define it locally on
the component's own root so nothing leaks out.
Anything ending -rgb wants three bare numbers,
because the CSS builds rgba() from it.
5. IF YOU CHANGE IT, GO ALL THE WAY. This block is
built for every state its object can really be
in — empty, one, full, refused, undone, pressed
twice, interrupted halfway — and not only the one
the demo opens on. Adapt it and the same standard
holds: work out that list before you write, and
build the whole of it. Never settle for the
minimum that makes the screenshot right. A
component somebody has to come back and finish is
the thing this was written to replace.
Keep the comments. They say why the numbers are what
they are, and they are most of what makes this worth
copying rather than rewriting.
--- Textarea.tsx ---
import { useEffect, useLayoutEffect, useRef, useState } from "react";
/* ══ Textarea ═════════════════════════════════════════════
A box that grows by whole lines, and shows you exactly
which characters are over.
THE COUNT IS NOT THE MESSAGE — THE INK IS. A number going
red tells you that something is wrong somewhere in what you
wrote; a wash under the last eleven characters tells you
which eleven, and you delete them without counting. The
text is not clipped and the keystroke is not refused: over
the limit is a legitimate state to be in on the way to a
shorter sentence, and the field's job is to make the excess
visible, not to fight the hand.
THE WASH IS A MIRROR, NOT A HIGHLIGHT. A textarea cannot
paint one of its own characters, so the same text is laid
out a second time behind it in the same face, the same
width and the same wrapping, with the tail wrapped in a
span — invisible, except for what is behind it. Every
number that affects wrapping is shared by the two, which is
why the padding and the line height are constants here
rather than values in the stylesheet.
The rest — the source and its comments — is what the plan opens.