Record button Free
Free forever. One command, source you own.
Install
npx shadcn@latest add https://cottoncandy.dev/r/record-button.jsonFree. Lands in components/mu/record-button/ with the shared foundation. Needs React 19, Tailwind v4 and motion; reads your shadcn theme, and dark mode follows .dark.
Usage
import { RecordButton } from "@/components/mu/record-button/RecordButton";
<RecordButton
onStream={(stream) => recorder.start(stream)} // the microphone it opened, to record
onStop={(seconds) => recorder.stop()}
/>Use with an agent Beta
npx shadcn@latest add https://cottoncandy.dev/r/uisdk/record-button.jsonOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch / keyboard: the mic key starts recording; the lamp stops it. Both are real buttons with names, and both give under a press (the key's whole body squeezes). The lamp takes presses once it has arrived, so a fast double-tap on the key never stops what it just started. Keyboard focus moves to the lamp as the pill opens and back to the key as it closes; the lamp's name follows the state ("Stop recording", "Saving", "Saved, N seconds"). A polite live region says the same.
- Off-screen: the light stops redrawing while the item is out of view, and whenever nothing about it is changing.
- Reduced motion: the pill opens and closes instantly, digits change without rolling, the light's strength still follows the voice but its bloom keeps one width (the level without the travel), and the results show at once with their mark drawn.
Props
| Prop | Default | What it does |
|---|---|---|
onStart | — | called when recording starts |
recording | — | controlled: true starts a take and false stops it, from your own key, a timer or a route change (a take you start without a person's press makes no sound) |
onRecordingChange | — | called with true when a take starts and false when it stops (a press, or maxSeconds) |
onPhase | — | called with each phase it moves to: recording, saving, saved or failed, and idle when the pill closes |
onStream | — | called with the microphone's MediaStream once it is open, so you can record the same stream; the button stops its tracks when the take ends |
onStop | — | called with the length in seconds; return or resolve false, or throw, to show the failed state |
level | the microphone | your own input level 0..1 (e.g. from an AnalyserNode); the light follows it, rising fast and falling slowly, and the button opens no microphone |
maxSeconds | 600 | stops on its own after this long |
labels | English | { start, stop, recording, saving, saved, failed, min, sec, denied, noMic, busy, insecure, micFailed }. saved is a function of the seconds or a template, so a Server Component can pass it: "Saved, {s} seconds", or "Saved {time}" (m:ss) |
sound | off | key, lamp and result sounds: true, or a volume 0–1 (see Sound) |
size | "md" | "md" (64 tall, 216 open), "lg" (96, 324 open), "xl" (128, 432 open), or a scale (1.25 is 80 tall): every length scales from one unit, --record-button-scale, and the lamp's lens is drawn at that size at the screen's density, never scaled. Show it at "xl" where it is the piece on display |
className | — | added to the root |
Sound
Off by default. With sound (or a volume, sound={0.5}) the key tocks as it goes down, the lamp arms with a soft tone when it is ready to press, pressing it tocks again, and the save answers with a two-note chime, or two low, rounded pulses stepping down if it fails. A stop at maxSeconds is silent. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Free to use in your projects, under the terms on the licence.
A voice-note button that opens into a recorder. Press the mic and a light inside smoky glass follows your voice while the seconds roll. Press the lamp to stop: a pale tick when it’s saved, a warm red cross if saving fails.
For voice notes and quick recordingsMore in Messaging