Lab

Meter

The <audio-ui-meter> custom element of @audio-ui/elements: its attributes, its parts and a live preview.

<audio-ui-meter> displays one or more level channels. Levels come from the value and peak attributes or properties, one per channel, or from a live source property, { getSnapshot, subscribe }, whose frames are written directly to the parts. A click clears clip indicators latched by a live source.

Usage

The styles read the theme's CSS variables, which Styling sets.

<style>
  audio-ui-meter {
    display: flex;
    gap: calc(var(--spacing, 0.25rem) * 1.5 * var(--density, 1));
    height: calc(var(--spacing, 0.25rem) * 44);
  }

  audio-ui-meter-channel {
    position: relative;
    display: block;
    width: calc(var(--spacing, 0.25rem) * 3);
    height: 100%;
    overflow: hidden;
    border-radius: calc(var(--radius, 0.625rem) - 4px);
    background: var(--muted, oklch(0.97 0 0));
  }

  audio-ui-meter-indicator {
    position: absolute;
    bottom: 0;
    display: block;
    background: var(--primary, oklch(0.205 0 0));
  }

  audio-ui-meter-peak {
    position: absolute;
    right: 0;
    left: 0;
    display: block;
    height: calc(var(--spacing, 0.25rem) * 0.5);
    background: var(--foreground, oklch(0.145 0 0));
  }
</style>

<audio-ui-meter min="-60" max="6" value="-18 -10">
  <audio-ui-meter-channel index="0" aria-label="Left">
    <audio-ui-meter-indicator></audio-ui-meter-indicator>
    <audio-ui-meter-peak></audio-ui-meter-peak>
  </audio-ui-meter-channel>
  <audio-ui-meter-channel index="1" aria-label="Right">
    <audio-ui-meter-indicator></audio-ui-meter-indicator>
    <audio-ui-meter-peak></audio-ui-meter-peak>
  </audio-ui-meter-channel>
</audio-ui-meter>

<script type="module">
  import "@audio-ui/elements/meter";

  const meter = document.querySelector("audio-ui-meter");
  meter.value = "-12 -6";
</script>

API reference

pnpm add @audio-ui/elements
import "@audio-ui/elements/meter";
ExportKindWhat it is
METER_TAGSconstThe names the meter's elements are registered under, frozen: a page cannot rename them by accident.
MeterChannelElementclassA channel with role="meter", for its index, labelled by aria-label or an <audio-ui-meter-label>.
MeterChannelsElementclassGenerates an <audio-ui-meter-channel> per level from its <template>, regenerated when the channel count changes.
MeterElementclassThe root of a level meter, with role="group".
MeterIndicatorElementclassThe lit range of a channel, scaled to the level along the meter's length.
MeterLabelElementclassThe accessible label of its channel.
MeterMarkElementclassA scale graduation at value, such as -18 dB, placed along the meter's length from its minimum.
MeterPeakElementclassThe peak-hold marker at the channel's peak level.
MeterSnapshotinterfaceWhat the meter's parts draw from.
MeterSourceinterfaceA live signal, in the shape of an external store: subscribe calls back on each new frame, getSnapshot returns the latest.
MeterTrackElementclassThe full range of a channel, behind the indicator.
MeterValueElementclassRenders the channel's level, formatted with the meter's format and locale.

Props · 11

PartDescription
<audio-ui-meter-channels>Generates an <audio-ui-meter-channel> per level from its <template>. label names each channel, {n} being its number (Output {n}). Renders with display: contents
<audio-ui-meter-channel>A channel with role="meter", for its index. Carries data-warning, data-clipping, and data-clipped until cleared
<audio-ui-meter-track>The full range of a channel
<audio-ui-meter-indicator>The lit range, scaled to the level
<audio-ui-meter-peak>The peak-hold marker, hidden when the channel has none
<audio-ui-meter-value>The formatted level
<audio-ui-meter-label>Labels its channel
<audio-ui-meter-mark>A scale graduation at its value, such as -18

The same control in React, and its parts' props: Meter.

Built by Ouest Labs, the source code is available on GitHub.
RSS