# Recorder

A voice recorder card with no microphone. The input is a generated voice-like signal, and playback is a silent, timed replay of the same take. The red key records, pauses and resumes; the side key stops and saves the take. On a saved take the red key plays, and the side key becomes hold-to-clear: a red ring fills round it and the waveform collapses. Drag the waveform, scroll over the card or use the arrow keys to scrub. Space and S work while the card has focus.

<demo-recorder>



</demo-recorder>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/recorder.json"
```

## Usage

```vue
<script setup lang="ts">
  import { computed } from 'vue';
  import Recorder from '~/components/ui/recorder/Recorder.vue';

  const colorMode = useColorMode();
  const theme = computed(() => (colorMode.value === 'dark' ? 'dark' : 'light'));

  function onSave(seconds: number) {
    console.log(`saved ${seconds.toFixed(1)}s`);
  }
</script>

<template>
  <Recorder :size="360" :theme="theme" @save="onSave" />
</template>
```

The card is drawn on a 700 × 700 grid and scaled as one piece. It never grows past `size`, and it shrinks further to fit the box it sits in and the window.

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        size
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        360
      </code>
    </td>
    
    <td>
      Width of the card in px. It shrinks further to fit its container and the viewport.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sound
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Tactile clicks on every press and a tick as you scrub, synthesised with Web Audio.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        auto-focus
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Focus the card on mount, so Space and S work straight away.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        theme
      </code>
    </td>
    
    <td>
      <code>
        'light' | 'dark'
      </code>
    </td>
    
    <td>
      <code>
        'dark'
      </code>
    </td>
    
    <td>
      <code>
        dark
      </code>
      
       graphite or <code>
        light
      </code>
      
       porcelain. The red key is the same in both.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element.
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        save
      </code>
    </td>
    
    <td>
      <code>
        (seconds: number)
      </code>
    </td>
    
    <td>
      Fires when a take is saved, with its length in s.
    </td>
  </tr>
</tbody>
</table>

## Keyboard

<table>
<thead>
  <tr>
    <th>
      Key
    </th>
    
    <th>
      Action
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        Space
      </code>
    </td>
    
    <td>
      Record, pause, resume; on a saved take, play and pause.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        S
      </code>
    </td>
    
    <td>
      Stop and save. On a saved take, hold to clear it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ←
      </code>
      
       / <code>
        →
      </code>
    </td>
    
    <td>
      Scrub a saved take by one second.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- Both keys are real buttons. Their `aria-label` follows the state: Record, Pause, Resume recording, Play, Pause playback; Stop, or Hold to clear the recording.
- The status label (READY, REC, PAUSED, SAVED, PLAY) sits in an `aria-live="polite"` region. The timer has `role="timer"` and an `aria-label` with the elapsed time.
- The keyboard listens on the card, not the page, so Space still scrolls the page when the card does not have focus.
- Both keys show a focus ring on keyboard focus. The side key is disabled before the first take.
- With reduced motion the digits, label and glyphs change without rolling or springing, and the clear skips the collapse.

Ported from [Recorder](https://pinui.xyz/components/recorder) by Pin UI, MIT licence.
