Skip to content
العربية
Motion

NumberRoll

Digits roll to the new value when it changes (prices, totals). The first render shows the value as it is. Screen readers get only the value. No roll off screen or with reduced motion.

import { NumberRoll } from "@percentsa/motion";

Examples

1,250

per month

Code
export function NumberRollExample() {
  const t = useT();
  const strings = useStrings();
  const [period, setPeriod] = useState("month");
  const yearly = period === "year";
  return (
    <Stack gap={6} align="start">
      <SegmentedControl
        aria-label={t("Billing period", "فترة الفوترة")}
        value={period}
        onValueChange={setPeriod}
        options={[
          { value: "month", label: t("Monthly", "شهري") },
          { value: "year", label: t("Yearly", "سنوي") },
        ]}
      />
      <div>
        {/* The Riyal sign stays left of the number, also in Arabic. */}
        <p dir="ltr" className="display text-6xl">
          <RiyalSign label={strings.riyal} /> <NumberRoll value={yearly ? 12500 : 1250} />
        </p>
        <Text size="sm" tone="muted">
          {yearly ? t("per year, two months free", "في السنة، مع شهرين مجانًا") : t("per month", "في الشهر")}
        </Text>
      </div>
    </Stack>
  );
}