Morse key
Tap for a dot, hold for a dash.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add morse-tapOr install the package
Don’t want the file? Import from
asta-ui/morse-tapand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { MorseTap } from "asta-ui/morse-tap";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useEffect, useRef, useState } from "react"; const CODE: Record<string, string> = { ".-": "A", "-...": "B", "-.-.": "C", "-..": "D", ".": "E", "..-.": "F", "--.": "G", "....": "H", "..": "I", ".---": "J", "-.-": "K", ".-..": "L", "--": "M", "-.": "N", "---": "O", ".--.": "P", "--.-": "Q", ".-.": "R", "...": "S", "-": "T", "..-": "U", "...-": "V", ".--": "W", "-..-": "X", "-.--": "Y", "--..": "Z", }; const DASH = 220; /** Tap short for a dot, hold for a dash. Pauses commit a letter, longer pauses a space. */ export default function MorseTap() { const [seq, setSeq] = useState(""); const [text, setText] = useState(""); const [down, setDown] = useState(false); const t0 = useRef(0); const seqRef = useRef(""); const letter = useRef<ReturnType<typeof setTimeout>>(undefined); const space = useRef<ReturnType<typeof setTimeout>>(undefined); const press = () => { if (down) return; clearTimeout(letter.current); clearTimeout(space.current); t0.current = performance.now(); setDown(true); }; const release = () => { if (!down) return; setDown(false); const s = seqRef.current + (performance.now() - t0.current < DASH ? "." : "-"); seqRef.current = s.slice(-5); setSeq(seqRef.current); letter.current = setTimeout(() => { const ch = CODE[seqRef.current] ?? "?"; setText((t) => (t + ch).slice(-14)); seqRef.current = ""; setSeq(""); space.current = setTimeout(() => setText((t) => (t.endsWith(" ") || !t ? t : t + " ")), 900); }, 550); }; useEffect( () => () => { clearTimeout(letter.current); clearTimeout(space.current); }, [], ); return ( <div className="flex h-full w-full flex-col items-center justify-center gap-4 p-6"> <div className="flex h-10 w-full max-w-[280px] items-center justify-between border-b border-line"> <span className="truncate font-mono text-xl tracking-[0.15em] text-ink"> {text} <span className="animate-pulse text-signal">_</span> </span> <button type="button" onClick={() => setText("")} className="font-mono text-[11px] uppercase tracking-[0.08em] text-mute hover:text-ink"> Clear </button> </div> <button type="button" onPointerDown={press} onPointerUp={release} onPointerLeave={release} onKeyDown={(e) => { if (e.key === " " && !e.repeat) { e.preventDefault(); press(); } }} onKeyUp={(e) => e.key === " " && release()} onContextMenu={(e) => e.preventDefault()} className={`relative grid h-20 w-20 select-none place-items-center border transition-[scale,background-color,border-color,color] duration-100 [touch-action:none] ${down ? "scale-95 border-signal bg-signal text-paper" : "border-line bg-paper-2 text-ink"}`} > <span className="font-mono text-[11px] uppercase tracking-[0.08em]">Tap</span> </button> <div className="flex h-5 items-center gap-1.5"> {seq.split("").map((c, i) => ( <span key={i} className={`bg-signal ${c === "." ? "h-1.5 w-1.5" : "h-1.5 w-5"}`} /> ))} {!seq && <span className="font-mono text-[11px] uppercase tracking-[0.08em] text-mute">··· −−− ··· = SOS</span>} </div> </div> ); }Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Morse key component to my project. Tap for a dot, hold for a dash. It fills its parent, so give the wrapper a size. It is designed on a dark surface: put it inside an element with the `dark` class. Install it: ```sh pnpm dlx asta-ui@latest add morse-tap --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/morse-tap.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import MorseTap from "@/components/astabyte/morse-tap"; ``` Usage example and props: https://ui.astabyte.com/morse-tap Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]
Usage
It fills its parent. Give the wrapper a size.
import MorseTap from "@/components/astabyte/morse-tap";
export default function Page() {
// Morse key
return (
<div className="relative h-96 w-full">
<MorseTap />
</div>
);
}