@molecule/app-reading-progress-bar-vue
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-vueHow it works
@molecule/app-reading-progress-bar-vue 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 { createApp, defineComponent, h, ref } from 'vue'
import { createI18nPlugin } from '@molecule/app-vue'
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-vue'
const articleEl = ref<Element | null>(null)
const Article = defineComponent({
setup() {
return () =>
h('div', [
h(ReadingProgressBar, { containerRef: articleEl, color: 'var(--brand)', thickness: 4 }),
h('article', { ref: articleEl }, '…long read…'),
])
},
})
createApp(Article).use(createI18nPlugin(i18nProvider)).mount('#app')Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue 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 Vue 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.tsJSDoc, not this file.
Quick Start
import { createApp, defineComponent, h, ref } from 'vue'
import { createI18nPlugin } from '@molecule/app-vue'
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-vue'
const articleEl = ref<Element | null>(null)
const Article = defineComponent({
setup() {
return () =>
h('div', [
h(ReadingProgressBar, { containerRef: articleEl, color: 'var(--brand)', thickness: 4 }),
h('article', { ref: articleEl }, '…long read…'),
])
},
})
createApp(Article).use(createI18nPlugin(i18nProvider)).mount('#app')
Type
feature
Installation
npm install @molecule/app-reading-progress-bar-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
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. React's `containerRef` is an object
* with a `current` field; a Vue template ref (an object with a `value` field)
* is accepted too.
*/
containerRef?: { readonly current?: Element | null; readonly value?: 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
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).
Constants
ReadingProgressBar
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).
const ReadingProgressBar: DefineComponent<
ExtractPropTypes<{
containerRef: {
type: PropType<NonNullable<ReadingProgressBarProps['containerRef']>>
default: undefined
}
thickness: { type: NumberConstructor; default: number }
position: { type: PropType<'top' | 'bottom'>; default: string }
color: StringConstructor
className: StringConstructor
dataMolId: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
containerRef: {
type: PropType<NonNullable<ReadingProgressBarProps['containerRef']>>
default: undefined
}
thickness: { type: NumberConstructor; default: number }
position: { type: PropType<'top' | 'bottom'>; default: string }
color: StringConstructor
className: StringConstructor
dataMolId: StringConstructor
}>
> &
Readonly<{}>,
{
containerRef: { readonly current?: Element | null; readonly value?: Element | null }
thickness: number
position: 'top' | 'bottom'
},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeReadingProgressBarProps).
Returns: The reading progress bar component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.5.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
@molecule/app-ui@molecule/app-ui-vue@molecule/app-vuevue
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 Vue binding's i18n provider and a wired ClassMap bond.
Translations
Translation strings are provided by @molecule/app-locales-reading-progress-bar.