Rolling text

A label whose changed characters roll, up as a value rises and down as it falls, while the unchanged ones slide into place and the width springs.

Features

  • Unchanged characters keep their key and slide; changed ones roll out one edge and in the other.
  • Direction from the value: up as it rises, down as it falls.
  • A 0.03 s stagger per changed glyph, capped at six; the width springs.

Use it for

  • Prices, counters, totals.
  • Button labels that change.

Installation

  1. Get runets.
    git clone https://github.com/ziyam-khan/runets
  2. Copy these files into your project, keeping their folders.
  3. Install what they use.
    pnpm add react motion
  4. Load the styles once. Bring your own base tokens, or use runets’ default theme.
    import 'runets/styles/theme.css'
    import 'runets/styles/kit.css'

Usage

import { RollingText } from 'runets'

<Button variant="submit"><RollingText text={`Pay $${price}`} value={price} /></Button>

API

PropTypeWhat it does
textstringThe label.
valuenumberOptional value that picks the roll direction.

Accessibility

Source

The code is in src/kit/controls.tsx in runets, MIT licensed.