@molecule/app-feature-transport-bar-angular

Feature · feature-transport-bar · App (browser) · v1.1.2 · Apache-2.0

Transport-control bar (play / pause / stop / record / skip / loop) used by music-daw + video-editor for editor playback control

npm install @molecule/app-feature-transport-bar-angular

npm · Source on GitHub

How it works

@molecule/app-feature-transport-bar-angular is a ready-made feature-transport-bar feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { Component } from '@angular/core'
import { TransportBar } from '@molecule/app-feature-transport-bar-angular'

@Component({
  selector: 'app-editor-transport',
  standalone: true,
  imports: [TransportBar],
  template: `
    <div
      mol-transport-bar
      [isPlaying]="playing"
      [isRecording]="recording"
      [loop]="loop"
      [onPlayToggle]="togglePlay"
      [onStop]="stop"
      [onRecordToggle]="toggleRecord"
      [onLoopToggle]="toggleLoop"
      timeDisplay="0:42 / 3:10"
    ></div>
  `,
})
export class EditorTransport {
  playing = false
  recording = false
  loop = false
  togglePlay(): void {
    this.playing = !this.playing
  }
  stop(): void {
    this.playing = false
  }
  toggleRecord(): void {
    this.recording = !this.recording
  }
  toggleLoop(): void {
    this.loop = !this.loop
  }
}

Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular

Reference

Angular transport bar — play / pause / stop / record / skip / loop controls for editor playback (music DAW, video editor, animation tool).

Exports <div mol-transport-bar> (TransportBar). All styling routes through getClassMap() and all button labels translate via the companion @molecule/app-locales-feature-transport-bar locale bond. It is the Angular counterpart of @molecule/app-feature-transport-bar-react: the same props, the same DOM for the same input, and the same callbacks.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { Component } from '@angular/core'
import { TransportBar } from '@molecule/app-feature-transport-bar-angular'

@Component({
  selector: 'app-editor-transport',
  standalone: true,
  imports: [TransportBar],
  template: `
    <div
      mol-transport-bar
      [isPlaying]="playing"
      [isRecording]="recording"
      [loop]="loop"
      [onPlayToggle]="togglePlay"
      [onStop]="stop"
      [onRecordToggle]="toggleRecord"
      [onLoopToggle]="toggleLoop"
      timeDisplay="0:42 / 3:10"
    ></div>
  `,
})
export class EditorTransport {
  playing = false
  recording = false
  loop = false
  togglePlay(): void {
    this.playing = !this.playing
  }
  stop(): void {
    this.playing = false
  }
  toggleRecord(): void {
    this.recording = !this.recording
  }
  toggleLoop(): void {
    this.loop = !this.loop
  }
}

Type

feature

Installation

npm install @molecule/app-feature-transport-bar-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular

API

Interfaces

TransportBarProps

Props accepted by TransportBar — the same props @molecule/app-feature-transport-bar-react accepts. Node props (timeDisplay, children) are projected content in Angular (an input cannot carry a node), so they are typed unknown: pass them in the host template, not as values.

interface TransportBarProps {
  /**
   * Whether playback is currently running. Drives the play / pause toggle
   * button's icon, label, and `aria-pressed` state.
   */
  isPlaying: boolean
  /**
   * Whether recording is currently armed / running. Drives the record
   * button's icon, label, and `aria-pressed` state. The record button
   * itself renders only when `onRecordToggle` is provided.
   */
  isRecording?: boolean
  /**
   * Whether the stop button is enabled. When `false`, the button still
   * renders but is `disabled`. Defaults to `true` when omitted.
   */
  canStop?: boolean
  /**
   * Whether the skip-back / skip-forward buttons are enabled. When `false`,
   * the buttons still render but are `disabled`. Defaults to `true` when
   * omitted. Skip buttons only render when their respective `onSkipBack` /
   * `onSkipForward` handlers are provided.
   */
  canSkip?: boolean
  /**
   * Whether loop playback is currently engaged. Drives the loop button's
   * `aria-pressed` state. The loop button itself renders only when
   * `onLoopToggle` is provided.
   */
  loop?: boolean
  /** Toggle play / pause. Required. */
  onPlayToggle: (event: Event) => void
  /** Stop playback (resets to start). Required. */
  onStop: (event: Event) => void
  /** Skip to the previous marker / start of clip. Optional. */
  onSkipBack?: (event: Event) => void
  /** Skip to the next marker / end of clip. Optional. */
  onSkipForward?: (event: Event) => void
  /** Toggle record mode. Optional — when omitted no record button is rendered. */
  onRecordToggle?: (event: Event) => void
  /** Toggle loop mode. Optional — when omitted no loop button is rendered. */
  onLoopToggle?: (event: Event) => void
  /**
   * Optional time-display slot, projected as `[slot=timeDisplay]` content (or
   * passed as a `TemplateRef` / text input). Takes precedence over
   * `children`.
   */
  timeDisplay?: unknown
  /** Optional time-display slot, projected as the element's default content. */
  children?: unknown
  /** Extra classes merged onto the root element. */
  className?: string
}

Classes

TransportBar

Transport-control bar (play / pause / stop / record / skip / loop) used by music-daw + video-editor surfaces for editor playback control. Renders a horizontal bar of buttons with semantic icons and fully translated aria-labels; an optional time-display slot lets callers render the current playhead position / total duration without coupling the bar to any specific time-format library.

The host IS the outer <div> (div[mol-transport-bar]), matching React's root exactly. Every button renders only while React would render it (a missing handler renders no button, canStop / canSkip only disable one), and the time-display wrapper renders only while React's {slot && …} would render it — the Angular projection capture points must stay mounted, so the placement function decides the wrapper's presence and withholds it with setElementPresent instead.

@Component({
  selector: 'div[mol-transport-bar]',
  standalone: true,
  hostDirectives: [MolPlacement],
  imports: [NgTemplateOutlet],
  inputs: [
    'isPlaying',
    'isRecording',
    'canStop',
    'canSkip',
    'loop',
    'onPlayToggle',
    'onStop',
    'onSkipBack',
    'onSkipForward',
    'onRecordToggle',
    'onLoopToggle',
    'timeDisplay',
    'className',
  ],
  host: {
    role: 'toolbar',
    'data-mol-id': 'transport-bar',
    '[attr.aria-label]': 'regionLabel()',
    '[class]': 'classes()',
  },
  template: `@if (onSkipBack) {<button type="button" (click)="callSkipBack($event)" [disabled]="!canSkipValue()" [attr.aria-label]="skipBackLabel()" data-mol-id="transport-bar-skip-back" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">⏮</span></button>}<button type="button" (click)="callPlayToggle($event)" [attr.aria-label]="isPlaying ? pauseLabel() : playLabel()" [attr.aria-pressed]="isPlaying" [attr.data-state]="isPlaying ? 'playing' : 'paused'" data-mol-id="transport-bar-play-toggle" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">{{ isPlaying ? '⏸' : '▶' }}</span></button><button type="button" (click)="callStop($event)" [disabled]="!canStopValue()" [attr.aria-label]="stopLabel()" data-mol-id="transport-bar-stop" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">⏹</span></button>@if (onSkipForward) {<button type="button" (click)="callSkipForward($event)" [disabled]="!canSkipValue()" [attr.aria-label]="skipForwardLabel()" data-mol-id="transport-bar-skip-forward" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">⏭</span></button>}@if (onRecordToggle) {<button type="button" (click)="callRecordToggle($event)" [attr.aria-label]="isRecording ? stopRecordingLabel() : recordLabel()" [attr.aria-pressed]="!!isRecording" [attr.data-state]="isRecording ? 'recording' : 'idle'" data-mol-id="transport-bar-record-toggle" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">●</span></button>}@if (onLoopToggle) {<button type="button" (click)="callLoopToggle($event)" [attr.aria-label]="loop ? loopOnLabel() : loopOffLabel()" [attr.aria-pressed]="!!loop" [attr.data-state]="loop ? 'on' : 'off'" data-mol-id="transport-bar-loop-toggle" [class]="controlClasses()" [style.background]="'transparent'" [style.border]="'none'" [style.cursor]="'pointer'" [style.padding]="0"><span aria-hidden="true">↻</span></button>}<div #timeSlot data-mol-id="transport-bar-time-display" [class]="timeClasses()"><span #childSlot><ng-content></ng-content></span><span #namedSlot><ng-content select="[slot=timeDisplay]"></ng-content></span>@if (isTemplate(timeDisplay)) {<ng-container [ngTemplateOutlet]="asTemplate(timeDisplay)" />}@if (timeDisplayText()) {{{ timeDisplayText() }}}</div>@if (falsySlotText()) {{{ falsySlotText() }}}`,
})
export class TransportBar {
  isPlaying?: boolean
  isRecording?: boolean
  canStop?: boolean
  canSkip?: boolean
  loop?: boolean
  onPlayToggle?: (event: Event) => void
  onStop?: (event: Event) => void
  onSkipBack?: (event: Event) => void
  onSkipForward?: (event: Event) => void
  onRecordToggle?: (event: Event) => void
  onLoopToggle?: (event: Event) => void
  timeDisplay?: unknown
  className?: string

  @ViewChild('timeSlot') timeSlotRef?: ElementRef<HTMLElement>
  @ViewChild('childSlot') childSlotRef?: ElementRef<HTMLElement>
  @ViewChild('namedSlot') namedSlotRef?: ElementRef<HTMLElement>

  private readonly i18n = useTranslation()
  private readonly host: HTMLElement = inject(ElementRef).nativeElement

  private readonly childProjected = signal(false)
  private readonly namedProjected = signal(false)
  private placed: HTMLElement | null = null

  constructor() {
    usePlacement((hasContent) => this.reconcile(hasContent))
  }

  cm(): UIClassMap {
    return getClassMap()
  }

  classes(): string {
    return this.cm().cn(
      this.cm().flex({ align: 'center', gap: 'sm' }),
      this.cm().sp('p', 2),
      this.className,
    )
  }

  controlClasses(): string {
    return this.cm().cn(this.cm().cursorPointer, this.cm().sp('p', 1))
  }

  timeClasses(): string {
    return this.cm().cn(this.cm().textSize('sm'), this.cm().sp('px', 2))
  }

  regionLabel(): string {
    return this.i18n.t(
      'transportBar.aria.region',
      {},
      { defaultValue: 'Playback transport controls' },
    )
  }

  skipBackLabel(): string {
    return this.i18n.t('transportBar.aria.skipBack', {}, { defaultValue: 'Skip backward' })
  }

  skipForwardLabel(): string {
    return this.i18n.t('transportBar.aria.skipForward', {}, { defaultValue: 'Skip forward' })
  }

  playLabel(): string {
    return this.i18n.t('transportBar.aria.play', {}, { defaultValue: 'Play' })
  }

  pauseLabel(): string {
    return this.i18n.t('transportBar.aria.pause', {}, { defaultValue: 'Pause' })
  }

  stopLabel(): string {
    return this.i18n.t('transportBar.aria.stop', {}, { defaultValue: 'Stop' })
  }

  recordLabel(): string {
    return this.i18n.t('transportBar.aria.record', {}, { defaultValue: 'Record' })
  }

  stopRecordingLabel(): string {
    return this.i18n.t('transportBar.aria.stopRecording', {}, { defaultValue: 'Stop recording' })
  }

  loopOnLabel(): string {
    return this.i18n.t('transportBar.aria.loopOn', {}, { defaultValue: 'Disable loop' })
  }

  loopOffLabel(): string {
    return this.i18n.t('transportBar.aria.loopOff', {}, { defaultValue: 'Enable loop' })
  }

  canStopValue(): boolean {
    return this.canStop ?? true
  }

  canSkipValue(): boolean {
    return this.canSkip ?? true
  }

  slotPresent(): boolean {
    return this.namedPresent() || this.childProjected()
  }

  namedPresent(): boolean {
    return this.timeDisplayPresent() || this.namedProjected()
  }

  isTemplate(value: unknown): value is TemplateRef<unknown> {
    return isTemplate(value)
  }

  asTemplate(value: unknown): TemplateRef<unknown> {
    return value as TemplateRef<unknown>
  }

  timeDisplayText(): string {
    const value = this.timeDisplay
    if (typeof value === 'string') return value
    if (typeof value === 'number' && value !== 0 && !Number.isNaN(value)) return String(value)
    return ''
  }

  falsySlotText(): string {
    if (this.slotPresent()) return ''
    return typeof this.timeDisplay === 'number' ? String(this.timeDisplay) : ''
  }

  callPlayToggle(event: Event): void {
    this.onPlayToggle?.(event)
  }

  callStop(event: Event): void {
    this.onStop?.(event)
  }

  callSkipBack(event: Event): void {
    this.onSkipBack?.(event)
  }

  callSkipForward(event: Event): void {
    this.onSkipForward?.(event)
  }

  callRecordToggle(event: Event): void {
    this.onRecordToggle?.(event)
  }

  callLoopToggle(event: Event): void {
    this.onLoopToggle?.(event)
  }

  private timeDisplayPresent(): boolean {
    const value = this.timeDisplay
    if (isTemplate(value)) return true
    if (typeof value === 'number') return value !== 0 && !Number.isNaN(value)
    if (typeof value === 'string') return value !== ''
    return value === true
  }
// … truncated — 3 more members: reconcile, hoist, withhold; the full declaration is in node_modules/@molecule/app-feature-transport-bar-angular/dist/transport-bar.component.d.ts

(Member comments are left out to fit; the full declaration is in node_modules/@molecule/app-feature-transport-bar-angular/dist/transport-bar.component.d.ts.)

Injection Notes

Requirements

Peer dependencies:

  • @angular/common ^22.0.0
  • @angular/core ^22.0.0
  • @angular/platform-browser ^22.0.0
  • @molecule/app-angular ^3.13.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-angular ^1.1.0

Runtime Dependencies

  • @angular/common

  • @angular/core

  • @angular/platform-browser

  • @molecule/app-angular

  • @molecule/app-ui

  • @molecule/app-ui-angular

  • Requires a bonded ClassMap (getClassMap() throws otherwise).

  • All user-visible text (button labels) routes through t() via the companion @molecule/app-locales-feature-transport-bar locale bond.

  • Node props are projected content: the time-display slot is [slot=timeDisplay] content, and children is the element's default content. The named slot takes precedence over the default content, as React's timeDisplay does over children.

Translations

Translation strings are provided by @molecule/app-locales-feature-transport-bar.