Qendrim Beka

some components for react

Role
Design and code
Timeline
November 2026
Status
21 components, open source
Stack
React 19, TypeScript, Tailwind CSS, Motion, shadcn registry
Link
The collection

A collection of React components, each built around one interaction detail. Here are nine. In each, Before is the common version and After is mine.

Each keeps something the user already has: what they meant, where things are, or what they chose.

Intent

Results often arrive twice: instantly from recents, then from the server. If the second answer reorders the list and the highlight is a row number, Enter opens a different document.

It types plan, presses ↓ to Q3 planning and presses Enter once the server answers. Watch which document opens.

Here the highlight is the result’s id, and that result keeps its row while the server’s results fill in around it. If an answer drops it, the highlight clears and a screen reader is told. Even the default highlight holds once it has been on screen for 150ms, long enough to be read; the cost is that a pause on the instant list keeps a row the server ranks lower.

// Remember which result is highlighted, not which row.
const [activeId, setActiveId] = useState<string | null>(null);

// An answer that drops it clears the highlight, rather than
// handing it to whichever result moved into its row.
if (activeId && !results.some((r) => r.id === activeId)) {
  setActiveId(null);
}

const current = results.find((r) => r.id === activeId);
if (key === "Enter" && current) onSelect(current);

On the way to a submenu, the pointer crosses the items below. If each reacts to hover, the first one crossed closes the submenu.

Watch the submenu while the pointer cuts across to a folder.

The fix is old: Ben Kamens wrote up Amazon’s mega-dropdown, and macOS menus work this way. Inside the triangle between the pointer and the submenu’s near edge, crossing a sibling doesn’t close the submenu; resting on one for 300ms does. A tap just opens it.

// apex: where the pointer was when it left the parent item.
const r = submenu.getBoundingClientRect();
const x = r.left >= apex.x ? r.left : r.right; // its near edge
const aiming = inTriangle(pointer, apex,
  { x, y: r.top - 8 }, { x, y: r.bottom + 8 });

// Inside the triangle, a sibling only takes over after 300ms.
if (aiming) schedule(() => activate(item), 300);

Position

Streaming

An AI answer streams in and the panel follows the end. Scroll up to re-read, and the next line pulls you back down.

Watch what the next line does once the reader scrolls up.

Here scrolling up stops following and shows Jump to latest. Pressing it, or scrolling to within 6px of the end, resumes. It watches scrollTop, which new lines don’t change, so only the reader can stop the follow.

function onScroll() {
  const top = el.scrollTop;
  const atBottom = el.scrollHeight - el.clientHeight - top < 6;
  // Moved up, away from the end: the reader has the scroll.
  if (top < lastTop - 1 && !atBottom) following = false;
  // Back at the end by themselves: follow again.
  else if (atBottom) following = true;
  lastTop = top;
}

Editing

Inline editing turns text into a field in place. If the field brings its own padding, border and line height, the words shift when it opens.

Watch the title’s words when it turns into a field.

Here the text stays in the layout with visibility: hidden, so it still sizes the box. A textarea with no border or padding sits over it at inset: 0, with the same font, line height and wrapping.

<div style={{ position: "relative" }}>
  {/* Still in the layout while editing, so it sizes the box. */}
  <span style={{ visibility: editing ? "hidden" : "visible" }}>
    {draft}
  </span>
  {/* No border, no padding: exactly the text's box. */}
  {editing && <textarea style={overlay} value={draft} />}
</div>

Deleting

When a row is deleted, the rows below close the gap. Delete several and the next one has moved under your pointer.

Watch what is under the pointer after the first file is deleted.

Here the row shrinks in place into an Undo capsule as tall as the row, and the delete commits when its ring runs out. The gap closes only once the pointer leaves the list. Each capsule keeps its own clock, and keyboard focus on one pauses it. Only the newest capsule shows the undo shortcut, since that is the one it reaches.

// Pointing never holds the clock; keyboard focus on the capsule does.
const paused = focused || held;

useEffect(() => {
  if (paused) return; // stopped; c.left keeps what remains
  c.since = performance.now();
  c.timer = setTimeout(() => expireRef.current(), Math.max(0, c.left));
  return () => {
    clearTimeout(c.timer);
    c.left -= performance.now() - c.since;
  };
}, [paused]);

Progress

A progress button’s label changes as it goes: Exporting 42%, then Done. If the label sets the width, each change pushes its neighbours.

Watch the Share button.

Here every label sits invisibly in one grid cell (grid-area: 1 / 1), so the button takes the widest, and the current label is laid over it. It needs the labels in advance.

const all = ["Export as CSV", "Exporting 100%", "Done", "Try again"];
const stacked = { gridArea: "1 / 1", visibility: "hidden" } as const;

// Every label in one grid cell: the cell, and so the button,
// takes the widest. The current label is laid on top.
<button style={{ display: "inline-grid", position: "relative" }}>
  {all.map((l) => <span key={l} style={stacked}>{l}</span>)}
  <span style={{ position: "absolute", inset: 0 }}>{current}</span>
</button>

Collapsing

Collapsing a sidebar to an icon rail usually lays it out again: the icons re-centre and the section heading shrinks to a divider, so every icon moves.

Watch the icons under Projects.

Here there is one layout. Rows keep their open width, the sidebar’s moving edge clips the labels (overflow: hidden), and the icons stay put. Only Inbox’s count moves, onto its icon.

const slot = railWidth - 16; // the icon column: the rail's inside
const row = width - 16; // every row keeps its open width

// The edge moves and clips the labels; nothing inside moves.
<motion.aside style={{ overflow: "hidden", width: edgeX }}>
  <span style={{ display: "flex", width: row }}>
    <span style={{ width: slot }}>{icon}</span>
    {label}
  </span>
</motion.aside>

Selects

A list that drops below the trigger puts even the next option a trip away. A macOS pop-up menu opens with the current value on the trigger.

Watch how far the list puts Berlin from the trigger.

Here London opens level with the trigger, so Berlin is one row away.

// The selected row's top, centred on the trigger.
const target = (t.offsetHeight - ROW) / 2;
// The list starts that far above it: the padding plus the rows
// above the selected one (fewer once a long list scrolls by k).
const v = PAD + (i - k) * ROW;
// Near an edge the whole list shifts to stay in bounds.
const top = clamp(target - v, b.top, b.bottom - height);

State

Retrying

A bulk action can succeed for some items and fail for others. Treat that as one failure and Retry sends them all again.

Contract.pdf is open, so the first try can’t archive it. Watch what Retry sends.

Here the two that went through leave, and Contract.pdf stays selected with its reason, File is open. Retry 1 file covers only it.

// The action reports which ids failed, and why.
const r = await action.onAction(target);
const bad = r?.failed ?? [];

// The rest went through and leave the table. Only the failed
// rows stay selected, so Retry covers them and nothing else.
choose(bad);
setFailed(new Map(bad.map((id) => [id, r?.reasons?.[id] ?? r?.reason])));

Smaller things

  • Spinners wait 150ms, then stay at least 400ms. A fast request never shows one, and a slow one doesn’t flash.
  • Things close faster than they open. The tooltip fades in over 180ms and out over 120ms.
  • Only the first tooltip waits. It opens after 500ms; for 300ms after the pointer leaves one, the next opens instantly.

Install

All 21 are in the collection, with their code. Menu, for example:

npx shadcn@latest add \
  https://www.qendrimbeka.com/projects/some-components-for-react/r/menu.json

Thanks for reading. If you’d like to talk, email me.