@molecule/app-now-playing-bar-vue

Feature · now-playing-bar · App (browser) · v1.1.0 · Apache-2.0

Persistent now-playing bar — track artwork, title/artist, transport controls (prev/play-pause/next), scrubber, and volume slider

npm install @molecule/app-now-playing-bar-vue

npm · Source on GitHub

How it works

@molecule/app-now-playing-bar-vue is a ready-made now-playing-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 { defineComponent, h, ref } from 'vue'
import { NowPlayingBar } from '@molecule/app-now-playing-bar-vue'

const Player = defineComponent({
  setup() {
    const playing = ref(false)
    const time = ref(0)
    return () =>
      h('div', { style: { position: 'sticky', bottom: 0 } }, [
        h(NowPlayingBar, {
          track: { id: 't1', title: 'Untitled', artist: 'Various' },
          isPlaying: playing.value,
          onPlay: () => (playing.value = true),
          onPause: () => (playing.value = false),
          currentTime: time.value,
          duration: 240,
          onSeek: (seconds: number) => (time.value = seconds),
        }),
      ])
  },
})

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

Reference

Vue persistent now-playing bar — track artwork, title/artist, transport controls (prev/play-pause/next), scrubber, and volume slider.

Vue counterpart of @molecule/app-now-playing-bar-react: the same exports, the same props (React names), the same DOM for the same input. Used by music-streaming, podcast, and audiobook apps as a sticky dock at the bottom of the page (or panel) showing what's currently playing.

Sticky positioning is intentionally NOT enforced inside the component — the caller wraps <NowPlayingBar> in their own position: sticky / position: fixed container at whatever scope makes sense (page, layout shell, panel).

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 { defineComponent, h, ref } from 'vue'
import { NowPlayingBar } from '@molecule/app-now-playing-bar-vue'

const Player = defineComponent({
  setup() {
    const playing = ref(false)
    const time = ref(0)
    return () =>
      h('div', { style: { position: 'sticky', bottom: 0 } }, [
        h(NowPlayingBar, {
          track: { id: 't1', title: 'Untitled', artist: 'Various' },
          isPlaying: playing.value,
          onPlay: () => (playing.value = true),
          onPause: () => (playing.value = false),
          currentTime: time.value,
          duration: 240,
          onSeek: (seconds: number) => (time.value = seconds),
        }),
      ])
  },
})

Type

feature

Installation

npm install @molecule/app-now-playing-bar-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

NowPlayingTrack

A track currently loaded in the now-playing bar. Only id, title, and artist are required; artwork is an optional image URL displayed on the left edge of the bar.

interface NowPlayingTrack {
  /** Stable identifier for the track (used as a key by parent lists). */
  id: string
  /** Track title shown as the primary label in the bar. */
  title: string
  /** Artist / podcast / source label shown below the title. */
  artist: string
  /** Optional artwork image URL (square). */
  artwork?: string
}

NowPlayingBarProps

Now-playing bar component props (React names).

interface NowPlayingBarProps {
  /**
   * The currently loaded track, or `null`/`undefined` when nothing is playing.
   * When absent the bar renders a compact empty state ("Nothing playing")
   * instead of throwing — you can leave it mounted rather than conditionally
   * unmounting it.
   */
  track?: NowPlayingTrack | null
  /** True when the track is actively playing. Drives the play/pause toggle. */
  isPlaying: boolean
  /** Called when the user presses play. */
  onPlay: () => void
  /** Called when the user presses pause. */
  onPause: () => void
  /** Optional next-track handler. When omitted the next button is hidden. */
  onNext?: () => void
  /** Optional previous-track handler. When omitted the previous button is hidden. */
  onPrev?: () => void
  /** Current playback position in seconds. */
  currentTime: number
  /** Total track duration in seconds. */
  duration: number
  /** Called when the user scrubs to a new position (in seconds). */
  onSeek: (seconds: number) => void
  /** Volume level in `[0, 1]`. Optional — when omitted the volume control is hidden. */
  volume?: number
  /** Called when the volume slider changes (in `[0, 1]`). Required to render the volume control. */
  onVolumeChange?: (volume: number) => void
  /**
   * Optional slot rendered at the right edge (e.g. queue button, share
   * button). Passed as a prop or as the same-named slot — both work.
   */
  trailing?: VNodeChild
  /** Extra classes merged onto the root element. */
  className?: string
}

Functions

formatTime(seconds)

Format a number of seconds as m:ss (or 0:00 for non-finite input).

function formatTime(seconds: number): string
  • seconds — Seconds to format.

Returns: The formatted m:ss string.

Constants

NowPlayingBar

Persistent now-playing bar: track artwork, title/artist, transport controls (prev/play-pause/next), scrubber and volume slider.

Sticky positioning is intentionally NOT enforced inside the component — the caller wraps it in their own position: sticky / fixed container. All styling routes through getClassMap(); all user-visible text routes through t() so the bar translates via the companion locale bond.

const NowPlayingBar: DefineComponent<
  ExtractPropTypes<{
    track: { type: PropType<NowPlayingTrack | null>; default: undefined }
    isPlaying: { type: BooleanConstructor; default: boolean }
    onPlay: { type: PropType<NowPlayingBarProps['onPlay']>; default: undefined }
    onPause: { type: PropType<NowPlayingBarProps['onPause']>; default: undefined }
    onNext: { type: PropType<(event: MouseEvent) => void>; default: undefined }
    onPrev: { type: PropType<(event: MouseEvent) => void>; default: undefined }
    currentTime: { type: NumberConstructor; default: number }
    duration: { type: NumberConstructor; default: number }
    onSeek: { type: PropType<NowPlayingBarProps['onSeek']>; default: undefined }
    volume: { type: NumberConstructor; default: undefined }
    onVolumeChange: { type: PropType<NowPlayingBarProps['onVolumeChange']>; default: undefined }
    trailing: null
    className: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      track: { type: PropType<NowPlayingTrack | null>; default: undefined }
      isPlaying: { type: BooleanConstructor; default: boolean }
      onPlay: { type: PropType<NowPlayingBarProps['onPlay']>; default: undefined }
      onPause: { type: PropType<NowPlayingBarProps['onPause']>; default: undefined }
      onNext: { type: PropType<(event: MouseEvent) => void>; default: undefined }
      onPrev: { type: PropType<(event: MouseEvent) => void>; default: undefined }
      currentTime: { type: NumberConstructor; default: number }
      duration: { type: NumberConstructor; default: number }
      onSeek: { type: PropType<NowPlayingBarProps['onSeek']>; default: undefined }
      volume: { type: NumberConstructor; default: undefined }
      onVolumeChange: { type: PropType<NowPlayingBarProps['onVolumeChange']>; default: undefined }
      trailing: null
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  {
    onPlay: () => void
    onPause: () => void
    onSeek: (seconds: number) => void
    onVolumeChange: ((volume: number) => void) | undefined
    track: NowPlayingTrack | null
    isPlaying: boolean
    onNext: (event: MouseEvent) => void
    onPrev: (event: MouseEvent) => void
    currentTime: number
    duration: number
    volume: number
  },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui
  • @molecule/app-ui-vue
  • @molecule/app-vue
  • vue

Pair with @molecule/app-locales-now-playing-bar for translations in 79 languages. All styling routes through getClassMap(); all user-facing text routes through t().

track is optional: pass null/undefined (or omit it) when nothing is playing and the bar renders a compact empty state ("Nothing playing") instead of throwing, so you can leave it mounted rather than conditionally unmounting it. Requires a wired ClassMap bond and the Vue binding's i18n provider ancestor — getClassMap() and useTranslation() both throw before wiring. Transport buttons render text glyphs (not an icon set), so their size tracks the app font. The trailing node prop also arrives as a same-named slot; the component accepts either.

Translations

Translation strings are provided by @molecule/app-locales-now-playing-bar.