Media Editor — Capture

Camera photo and video capture feature for the Media Editor, providing getUserMedia lifecycle, camera permission flows, a photo/video shutter control, and a dev-only multi-instance guard. It plugs into the base editor through the `capture` prop as `mediaCapture`.

Media Editor — Capture
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @ilinxa/media-editor-capture

Requires @ilinxa in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ShutterButton } from "@/components/media-editor/features/capture";export function Shutter() {  return (    <ShutterButton      mode="photo"      ariaLabel="Take photo"      onPress={() => {}}    />  );}
  • Adding in-app photo or short video capture to a Media Editor composer, story, or chat embed.
  • Needing a shutter button with Instagram-style tap for photo and tap or long-press for video behavior.
  • Handling camera permission states (idle, pending, denied, no-camera, error) with built-in or custom UI.
  • Building a custom camera UI from the hook (useMediaCapture) or permission watcher (useCameraPermissions) without the full composer.

Examples

Photo shutter

A tap-only photo shutter that calls onPress.

photo-shutter.tsx
import { ShutterButton } from "@/components/media-editor/features/capture";export function PhotoShutter({ onCapture }: { onCapture: () => void }) {  return <ShutterButton mode="photo" ariaLabel="Take photo" onPress={onCapture} />;}

Video shutter with recording state

Video mode: hold to record or tap to toggle, with recording progress driving the ring fill.

video-shutter-with-recording-state.tsx
import { useState } from "react";import { ShutterButton } from "@/components/media-editor/features/capture";export function VideoShutter() {  const [recording, setRecording] = useState(false);  return (    <ShutterButton      mode="video"      ariaLabel={recording ? "Stop recording" : "Start recording"}      isRecording={recording}      recordProgress={0}      onStart={() => setRecording(true)}      onStop={() => setRecording(false)}    />  );}

Headless camera with the hook

Uses useMediaCapture with autoAcquire false so the camera only starts after a user gesture.

headless-camera-with-the-hook.tsx
import { useMediaCapture } from "@/components/media-editor/features/capture";export function CameraPreview() {  const cap = useMediaCapture({ enabled: true, autoAcquire: false });  return (    <div>      <video ref={cap.videoRef} autoPlay playsInline muted className="w-full bg-black" />      <button type="button" onClick={() => void cap.acquire()}>Enable camera</button>    </div>  );}

API reference

PropTypeDefaultDescription
enabledboolean (EditorCameraProps, required)—Composer is open and a live camera stream should be held.
modeComposerMode (EditorCameraProps, required)—Drives mirroring, default facing, shutter aria-label, and whether recording is available.
defaultFacing"user" | "environment"—Initial camera facing; auto-detected from touch capability when omitted.
recordAudiobooleantrueRequests a mic track only in video mode.
maxFileSizeMbnumber50Max size for gallery-picked files.
maxVideoDurationSecnumber30Hard cap on a single recording; auto-stops.
captureAspectRationumber | null—Width/height of the visible preview; photos are center-cropped to match. null captures the full frame.
autoAcquireOverrideboolean—Forces auto-acquire on mount even without a pre-granted permission.
labelsRequired<StoryComposerLabels> (EditorCameraProps, required)—All UI strings used by the camera surface.
onPhoto(photo: CapturedPhoto) => void (required)—Called with the captured JPEG blob and dimensions.
onVideo(video: CapturedVideo) => void (required)—Called with the recorded blob and duration.
onGalleryFile(file: File) => void (required)—Called with a validated file picked from the gallery.
onValidationError(error: ValidationError) => void—Reports file validation and recording/capture failures.
onPermissionDenied() => void—Fires once when permission is denied.
renderPermissionDenied(ctx: { retry: () => void; usePicker: () => void }) => React.ReactNode—Replaces only the denied-state UI.
mode (ShutterButton)"photo" | "video"—Shutter behavior: tap for photo, tap or long-press for video.
onPress() => void—Photo-mode tap handler; ignored in video mode.
onStart() => void—Video-mode start, on long-press down or tap-to-start.
onStop() => void—Video-mode stop, on long-press release or tap-to-stop.
isRecordingbooleanfalseDrives the recording ring and stop-square visuals.
recordProgressnumber (0..1)0Fraction of max duration elapsed; drives the conic ring.
disabledbooleanfalseDisables the shutter button.
ariaLabelstring—Accessible name for the shutter button (required).
classNamestring—Extra classes merged onto the button.
variant (CameraPermissionPrompt)"idle" | "pending" | "denied" | "no-camera" | "error"—Which permission state body to render.
labels (CameraPermissionPrompt)Required<StoryComposerLabels>—Strings for the prompt body and buttons.
onRetry() => void—Re-requests the camera.
onUsePicker() => void—Opens the gallery file picker.
className (CameraPermissionPrompt)string—Extra classes merged onto the root element.
enabled (useMediaCapture)boolean—Enables the camera; releasing flips status back to idle.
defaultFacing (useMediaCapture)"user" | "environment"—Initial facing; auto-detected when omitted.
requestAudio (useMediaCapture)booleanfalseRequests audio for video recording; keep false for photo-only capture.
maxVideoDurationSec (useMediaCapture)number30Auto-stop cap for a recording.
autoAcquire (useMediaCapture)booleantrueAcquire automatically when enabled; set false to require a user gesture.

Accessibility

  • The shutter button has aria-label from ariaLabel plus a sr-only label, and aria-pressed reflects isRecording in video mode.
  • The recording indicator is role="status" with aria-live="polite" and an sr-only recordingLabel.
  • The permission prompt for denied, no-camera, and error states uses role="alert" with aria-live="polite".
  • Icon-only gallery and switch-camera buttons receive aria-label from the labels prop.
  • The shutter has a visible focus-visible ring (white, offset) for keyboard users.
  • Consider keeping autoAcquire false until a user gesture so browser permission prompts are triggered by intent.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Media Editor — Capture" component (ilinxa/media-editor-capture) from its shadcn registry.1. Install it with: npx shadcn@latest add @ilinxa/media-editor-capture2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: enabled, mode, defaultFacing, recordAudio, maxFileSizeMb, maxVideoDurationSec, captureAspectRatio, autoAcquireOverride, labels, onPhoto, onVideo, onGalleryFile, onValidationError, onPermissionDenied, renderPermissionDenied, mode (ShutterButton), onPress, onStart, onStop, isRecording, recordProgress, disabled, ariaLabel, className, variant (CameraPermissionPrompt), labels (CameraPermissionPrompt), onRetry, onUsePicker, className (CameraPermissionPrompt), enabled (useMediaCapture), defaultFacing (useMediaCapture), requestAudio (useMediaCapture), maxVideoDurationSec (useMediaCapture), autoAcquire (useMediaCapture).Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ShutterButton } from "@/components/media-editor/features/capture";export function Shutter() {  return (    <ShutterButton      mode="photo"      ariaLabel="Take photo"      onPress={() => {}}    />  );}```

Files & dependencies

  • src/registry/components/media/media-editor/features/capture/index.ts→ components/media-editor/features/capture/index.ts
  • src/registry/components/media/media-editor/features/capture/provider.tsx→ components/media-editor/features/capture/provider.tsx
  • src/registry/components/media/media-editor/features/capture/hooks/use-media-capture.ts→ components/media-editor/features/capture/hooks/use-media-capture.ts
  • src/registry/components/media/media-editor/features/capture/hooks/use-camera-permissions.ts→ components/media-editor/features/capture/hooks/use-camera-permissions.ts
  • src/registry/components/media/media-editor/features/capture/hooks/use-multi-instance-guard.ts→ components/media-editor/features/capture/hooks/use-multi-instance-guard.ts
  • src/registry/components/media/media-editor/features/capture/parts/editor-camera.tsx→ components/media-editor/features/capture/parts/editor-camera.tsx
  • src/registry/components/media/media-editor/features/capture/parts/camera-permission-prompt.tsx→ components/media-editor/features/capture/parts/camera-permission-prompt.tsx
  • src/registry/components/media/media-editor/features/capture/parts/shutter-button.tsx→ components/media-editor/features/capture/parts/shutter-button.tsx
dependencieslucide-react@^1.11.0
registryDependencies@ilinxa/media-editorbutton

Looks similar, elsewhere