# Lens Voice Message

A recorded reply with a waveform, playback speed and time left.

Build a Voice Message in this project that looks and behaves like Lens's. Measured from the running Lens app (developer.lens.xyz). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.

Fidelity: Concept, not a real feature. Designed from the dashboard black round button and the count pill. The dark theme is derived.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--lens-blackberry-black` | `#2c2d30` | `#ececed` |
| `--lens-blackberry-black-a2` | `#2c2d3033` | `#ececed38` |
| `--lens-blackberry-black-a3` | `#2c2d304d` | `#ececed54` |
| `--lens-white` | `#fff` | `#1c1d1f` |
| `--lens-text-primary` | `#2c2d30` | `#ececed` |
| `--lens-text-secondary` | `#2c2d3099` | `#ececed9e` |
| `--lens-text-tertiary` | `#2c2d304d` | `#ececed54` |
| `--lens-background-quinary` | `#f2f2f2` | `#2e2f32` |
| `--lens-stroke` | `#2c2d300d` | `#ececed14` |
| `--lens-black-hover` | `color(display-p3 0.2658 0.2719 0.29)` | `#d4d4d6` |
| `--lens-count-bg` | `#f5f5f5` | `#2a2b2e` |
| `--lens-focus-element` | `0 0 0 1px var(--lens-white), 0 0 0 3px var(--lens-blackberry-black), 0 1px 1px 0 #00000008` | `0 0 0 1px var(--lens-white), 0 0 0 3px var(--lens-blackberry-black), 0 1px 1px 0 #00000026` |
| `--duration-short` | `0.2s` | `0.2s` |
| `--font-regular` | `"Lens Inter", "Lens Inter Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif` | `"Lens Inter", "Lens Inter Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif` |

## CSS

Scoped under `[data-style="lens"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="lens"] {
  .ui-voice-message {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 14px 0 6px;
    border: 1px solid var(--lens-stroke);
    border-radius: 22px;
    background: var(--lens-white);
    color: var(--lens-text-primary);
    font-family: var(--font-regular);
  }

  .ui-voice-message-play {
    box-sizing: border-box;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    outline: 3px solid transparent;
    outline-offset: 0;
    background: var(--lens-blackberry-black);
    color: var(--lens-white);
    cursor: pointer;
    transition: all var(--duration-short);

    & svg {
      width: 14px;
      height: 14px;
    }

    @media (hover: hover) {
      &:hover {
        background: var(--lens-black-hover);
      }
    }

    &:active {
      transform: scale(0.96);
    }

    &:focus-visible {
      outline-color: var(--lens-blackberry-black-a3);
      outline-offset: 2px;
    }
  }

  .ui-voice-message-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    width: 140px;
    height: 24px;
  }

  .ui-voice-message-bar {
    flex: 1;
    min-width: 2px;
    height: calc(var(--bar-height) * 100%);
    min-height: 3px;
    border-radius: 1px;
    background: var(--lens-blackberry-black-a2);
    transition: background-color var(--duration-short);

    &[data-played] {
      background: var(--lens-blackberry-black);
    }
  }

  .ui-voice-message-speed {
    box-sizing: border-box;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 20px;
    margin: 0;
    padding: 0 6px;
    border: 0;
    border-radius: 10px;
    outline: none;
    background: var(--lens-count-bg);
    color: var(--lens-text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition:
      background-color var(--duration-short),
      color var(--duration-short);

    @media (hover: hover) {
      &:hover {
        background: var(--lens-background-quinary);
        color: var(--lens-text-primary);
      }
    }

    &:focus-visible {
      box-shadow: var(--lens-focus-element);
    }
  }

  .ui-voice-message-duration {
    min-width: 28px;
    color: var(--lens-text-tertiary);
    font-size: 12px;
    line-height: 18px;
    font-variant-numeric: tabular-nums;
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-voice-message-play,
    .ui-voice-message-bar,
    .ui-voice-message-speed {
      transition: none;
    }

    .ui-voice-message-play:active {
      transform: none;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Button as BaseButton } from "@base-ui/react/button";
import type { ComponentProps, CSSProperties } from "react";
import { join } from "./utils";

function Root({ className, ...props }: ComponentProps<"div">) {
  return <div className={join("ui-voice-message", className)} {...props} />;
}

type PlayProps = Omit<BaseButton.Props, "className"> & { className?: string; playing?: boolean };

function Play({ className, playing = false, ...props }: PlayProps) {
  return (
    <BaseButton
      className={join("ui-voice-message-play", className)}
      aria-label={playing ? "Pause" : "Play"}
      data-playing={playing || undefined}
      {...props}
    >
      {playing ? (
        <svg viewBox="0 0 16 16" fill="currentColor" aria-hidden>
          <rect x="4" y="3" width="3" height="10" rx="1" />
          <rect x="9" y="3" width="3" height="10" rx="1" />
        </svg>
      ) : (
        <svg viewBox="0 0 16 16" fill="currentColor" aria-hidden>
          <path d="M5 3.4v9.2a.6.6 0 0 0 .9.52l7.6-4.6a.6.6 0 0 0 0-1.04l-7.6-4.6A.6.6 0 0 0 5 3.4z" />
        </svg>
      )}
    </BaseButton>
  );
}

type WaveformProps = Omit<ComponentProps<"div">, "children"> & { bars: number[]; progress?: number };

function Waveform({ className, bars, progress = 0, ...props }: WaveformProps) {
  const played = Math.round(bars.length * Math.min(Math.max(progress, 0), 1));
  return (
    <div className={join("ui-voice-message-waveform", className)} aria-hidden {...props}>
      {bars.map((height, index) => (
        <span
          key={`bar-${index}`}
          className="ui-voice-message-bar"
          data-played={index < played || undefined}
          style={{ "--bar-height": height } as CSSProperties}
        />
      ))}
    </div>
  );
}

function Speed({ className, ...props }: Omit<BaseButton.Props, "className"> & { className?: string }) {
  return <BaseButton className={join("ui-voice-message-speed", className)} {...props} />;
}

function Duration({ className, ...props }: ComponentProps<"span">) {
  return <span className={join("ui-voice-message-duration", className)} {...props} />;
}

export const VoiceMessage = {
  Root,
  Play,
  Waveform,
  Speed,
  Duration,
};
```

## Example

```tsx
import { VoiceMessage } from "@replicas/ui";
import { useEffect, useState } from "react";

const bars = [0.3, 0.5, 0.4, 0.7, 0.9, 0.6, 0.4, 0.8, 1, 0.7, 0.5, 0.3, 0.6, 0.9, 0.8, 0.5, 0.4, 0.7, 0.6, 0.3, 0.5, 0.8, 0.6, 0.4, 0.3, 0.5, 0.7, 0.4];
const speeds = ["1×", "1.5×", "2×"];
const length = 8;

export default function VoiceMessageDemo() {
  const [playing, setPlaying] = useState(false);
  const [elapsed, setElapsed] = useState(0);
  const [speed, setSpeed] = useState(0);

  useEffect(() => {
    if (!playing) return;
    const timer = setInterval(() => {
      setElapsed((value) => {
        const next = value + 0.1 * Number.parseFloat(speeds[speed]);
        if (next < length) return next;
        setPlaying(false);
        return 0;
      });
    }, 100);
    return () => clearInterval(timer);
  }, [playing, speed]);

  const shown = Math.ceil(playing || elapsed ? length - elapsed : length);

  return (
    <VoiceMessage.Root>
      <VoiceMessage.Play playing={playing} onClick={() => setPlaying(!playing)} />
      <VoiceMessage.Waveform bars={bars} progress={elapsed / length} />
      <VoiceMessage.Speed aria-label={`Playback speed ${speeds[speed]}`} onClick={() => setSpeed((speed + 1) % speeds.length)}>
        {speeds[speed]}
      </VoiceMessage.Speed>
      <VoiceMessage.Duration>0:{String(shown).padStart(2, "0")}</VoiceMessage.Duration>
    </VoiceMessage.Root>
  );
}
```

## Foundations

The rest of the Lens style, as a skill: https://replicas.raphaelsalaja.com/skills/lens/SKILL.md