Zubra UI
Code for
GitHub

number-ticker

A number that counts to value when it scrolls into view, and on from there when value changes: for stats and dashboards. Formatted for locale with decimals, prefix and suffix; screen readers get the final number, and reduced motion shows it at once.

This one has no events: it shows what it's given.

Source: number-ticker.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/number-ticker.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/number-ticker.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/number-ticker.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/number-ticker.json
One file, no dependencies (2.5 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/number-ticker.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/number-ticker.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/number-ticker.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/number-ticker.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/number-ticker.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/number-ticker.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/number-ticker.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/number-ticker.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/number-ticker.js"></script>

The compiled install writes src/components/zubra/number-ticker.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<number-ticker suffix=" loaves" locale="en-US"></number-ticker>

<script type="module">
  import './components/zubra/number-ticker.js';

  const element = document.querySelector('number-ticker');
  element.value = 12480;
  element.duration = 1600;
</script>
Example.jsx
import './components/zubra/number-ticker.js';

const value = 12480;
const duration = 1600;

export function NumberTickerExample() {
  return (
    <number-ticker
      suffix=" loaves"
      locale="en-US"
      value={value}
      duration={duration}
    ></number-ticker>
  );
}
Example.vue
<script setup>
import './components/zubra/number-ticker.js';
const value = 12480;
const duration = 1600;
</script>

<template>
  <number-ticker
    suffix=" loaves"
    locale="en-US"
    :value.prop="value"
    :duration.prop="duration"
  ></number-ticker>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/number-ticker.js';
  const value = 12480;
  const duration = 1600;
</script>

<number-ticker suffix=" loaves" locale="en-US" {value} {duration}></number-ticker>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/number-ticker.js';

@Component({
  selector: 'app-number-ticker-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <number-ticker
      suffix=" loaves"
      locale="en-US"
      [value]="value"
      [duration]="duration"
    ></number-ticker>
  `,
})
export class NumberTickerExample {
  value = 12480;

  duration = 1600;
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuenumber0
fromnumber0
durationnumber1500
decimalsnumber0
prefixstring""
suffixstring""
localestring""

Size

1.1 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.7 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour