@molecule/app-reading-progress-bar-solid

Feature · reading-progress-bar · App (browser) · v1.1.1 · Apache-2.0

Top-of-page scroll progress bar for article pages

npm install @molecule/app-reading-progress-bar-solid

npm · Source on GitHub

How it works

@molecule/app-reading-progress-bar-solid is a ready-made reading-progress-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 { createSignal } from 'solid-js'
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-solid'

export function Article() {
  const [article, setArticle] = createSignal<Element>()
  // `<ReadingProgressBar containerRef={{ get current() { return article() } }} />`
  // pins to the article; without containerRef the bar tracks whole-page scroll.
  return (
    <ReadingProgressBar
      containerRef={{
        get current() {
          return article()
        },
      }}
      color="var(--brand)"
      thickness={4}
    />
  )
}

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

Reference

Solid reading progress bar.

Exports ReadingProgressBar — a thin top-of-page bar that fills as the user scrolls through an article. Used by blog and news-aggregator article pages. It is the Solid counterpart of @molecule/app-reading-progress-bar-react: same export names, same props, same DOM for the same input.

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 { createSignal } from 'solid-js'
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-solid'

export function Article() {
  const [article, setArticle] = createSignal<Element>()
  // `<ReadingProgressBar containerRef={{ get current() { return article() } }} />`
  // pins to the article; without containerRef the bar tracks whole-page scroll.
  return (
    <ReadingProgressBar
      containerRef={{
        get current() {
          return article()
        },
      }}
      color="var(--brand)"
      thickness={4}
    />
  )
}

Type

feature

Installation

npm install @molecule/app-reading-progress-bar-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

ReadingProgressBarProps

Props accepted by the ReadingProgressBar component.

interface ReadingProgressBarProps {
  /**
   * Optional ref to the article element. When provided, progress is measured
   * against that element's bounding rect (so the bar fills as the user scrolls
   * through the article body, not the whole page). When omitted, progress
   * falls back to `window` scroll position.
   */
  containerRef?: { readonly current?: Element | null }
  /** Bar thickness in pixels. Defaults to `3`. */
  thickness?: number
  /**
   * Where the bar pins. Defaults to `'top'`. Both variants render fixed across
   * the full viewport width with a high z-index.
   */
  position?: 'top' | 'bottom'
  /**
   * CSS color for the filled portion of the bar. Defaults to `'currentColor'`
   * so the bar inherits whatever text color is in scope — letting the
   * surrounding theme drive it. Pass a theme-aware color (`'var(--brand)'`,
   * etc.) to override.
   */
  color?: string
  /** Extra classes on the outer wrapper. */
  className?: string
  /** `data-mol-id` for AI-agent / E2E selectors. */
  dataMolId?: string
}

Functions

ReadingProgressBar(props)

Top-of-page reading progress bar.

Tracks how far the user has scrolled through an article and renders a thin horizontal bar pinned to the top (or bottom) of the viewport, filling left-to-right from 0% to 100% as they read.

Throttles scroll updates with requestAnimationFrame so the work runs at most once per frame — the handler attaches in passive mode. Listens to both scroll and resize because progress changes when the viewport height changes (e.g. mobile toolbar collapse).

This is the Solid counterpart of @molecule/app-reading-progress-bar-react: the same props (React names), the same ClassMap tokens, the same i18n key, and the same DOM for the same input.

function ReadingProgressBar(props: ReadingProgressBarProps): JSX.Element
  • props — Component props (see ReadingProgressBarProps).

Returns: The rendered reading progress bar.

computeArticleProgress(el, viewportHeight)

Computes the scroll progress (0..1) of an element, measured by how much of the element has scrolled past the top of the viewport.

Returns 0 when the element's top is at or below the viewport top, 1 when its bottom is at or above the viewport top plus the viewport height (fully read), and linearly interpolates between those endpoints in the middle. An element shorter than the viewport counts as fully read once its top reaches the viewport top.

function computeArticleProgress(el: Element, viewportHeight: number): number
  • el — The article element whose read-through progress we want.
  • viewportHeight — The viewport height to use as the denominator.

Returns: A number in [0, 1].

computeWindowProgress()

Computes window scroll progress (0..1) using scrollY and the document's total scrollable height.

function computeWindowProgress(): number

Returns: A number in [0, 1]. Falls back to 0 when there is nothing to scroll (page shorter than the viewport).

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-solid
  • @molecule/app-ui
  • @molecule/app-ui-solid
  • solid-js

Companion locale bond: @molecule/app-locales-reading-progress-bar (the progressbar aria-label). The fill defaults to currentColor — it inherits the surrounding text color, so pass color (e.g. var(--color-primary)) when the ambient text color is low-contrast against the page edge. The bar renders position: fixed at z-index: 1000 spanning the viewport width; it only listens to window scroll — containerRef changes what is measured, not which scroller is observed (inner scroll containers won't drive it). Requires the Solid binding's i18n provider and a wired ClassMap bond.

Translations

Translation strings are provided by @molecule/app-locales-reading-progress-bar.