<x-widget.price-roll>
Price roll Blade component for Laravel and Livewire
Odometer-style price that rolls its digits when data-value changes, with an optional change badge (since a previous price), trend colours that can be inverted or switched off, and before/after slots for your own markup. Formats with Intl on both server and client. Works inside Livewire components: a render with a new value rolls to it.
php artisan bladewell:add price-roll
- Also adds
- Nothing else. It stands alone.
- Needs PHP extension
intl- Works with
- Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
Usage
Livewire
In a Livewire component, pass the price from a property: each render rolls the digits to the new one and updates the change badge, on wire:poll too. A price roll that arrives with a render sets itself up.
<div wire:poll.5s="refreshQuote">
<x-widget.price-roll :value="$quote->price" :previous="$quote->open" currency="USD" label="BTC" live class="text-4xl font-semibold" />
</div>
Examples
Live price
Change data-value from anywhere and the digits roll to the new price, flashing green or red; here the script beside this does it. live announces changes to screen readers.
Show code Hide code
<div class="flex flex-col items-start gap-4">
<x-widget.price-roll id="btc-price" :value="64210.50" currency="USD" label="Price" live class="text-4xl font-semibold" />
<div class="flex gap-2">
<button type="button" class="bg-field text-foreground rounded-full px-4 py-2 text-sm font-medium" data-price-change="1375.25" aria-controls="btc-price">Price up</button>
<button type="button" class="bg-field text-foreground rounded-full px-4 py-2 text-sm font-medium" data-price-change="-842.75" aria-controls="btc-price">Price down</button>
</div>
</div>
// In a real app the new price comes from your server (polling, a websocket); setting data-value is all it takes.
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-price-change]');
const price = button && document.getElementById(button.getAttribute('aria-controls'));
if (price) {
price.dataset.value = Math.max(0, Number(price.dataset.value) + Number(button.dataset.priceChange)).toFixed(2);
}
});
With change
previous is where the price started (today's open, say); the badge shows the change since then and follows the price as it rolls. change="percent" (the default), "amount" or "both". Screen readers hear it with the price: "Price: $65,585.75, up 4.38%".
Show code Hide code
<div class="flex flex-col items-start gap-4">
<x-widget.price-roll id="eth-price" :value="3218.40" :previous="3102.75" currency="USD" locale="en-US" label="Ether" change="both" live class="text-4xl font-semibold" />
<div class="flex gap-2">
<button type="button" class="bg-field text-foreground rounded-full px-4 py-2 text-sm font-medium" data-price-step="84.60" aria-controls="eth-price">Price up</button>
<button type="button" class="bg-field text-foreground rounded-full px-4 py-2 text-sm font-medium" data-price-step="-131.25" aria-controls="eth-price">Price down</button>
</div>
</div>
// A new price from your server is all it takes: set data-value, and the digits and the badge follow.
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-price-step]');
const price = button && document.getElementById(button.getAttribute('aria-controls'));
if (price) {
price.dataset.value = Math.max(0, Number(price.dataset.value) + Number(button.dataset.priceStep)).toFixed(2);
}
});
Trend colors
Up is good by default (green). trend-colors="inverse" is for values where up is bad, like a delivery fee or a wait; "none" drops the colours, for a total that is neither good nor bad news.
Portfolio
Portfolio: $12,480, up 3.14%Delivery fee
Delivery fee: $6.50, up $1.51Cart total
Cart total: $84.20, up $4.30Show code Hide code
<div class="grid gap-6 sm:grid-cols-3">
<div>
<p class="text-foreground/75 mb-1 text-sm">Portfolio</p>
<x-widget.price-roll id="trend-default" :value="12480" :previous="12100" currency="USD" locale="en-US" :decimals="0" label="Portfolio" class="text-2xl font-semibold" />
</div>
<div>
<p class="text-foreground/75 mb-1 text-sm">Delivery fee</p>
<x-widget.price-roll id="trend-inverse" :value="6.50" :previous="4.99" currency="USD" locale="en-US" label="Delivery fee" trend-colors="inverse" change="amount" class="text-2xl font-semibold" />
</div>
<div>
<p class="text-foreground/75 mb-1 text-sm">Cart total</p>
<x-widget.price-roll id="trend-none" :value="84.20" :previous="79.90" currency="USD" locale="en-US" label="Cart total" trend-colors="none" change="amount" class="text-2xl font-semibold" />
</div>
<button type="button" class="bg-field text-foreground justify-self-start rounded-full px-4 py-2 text-sm font-medium sm:col-span-3" data-raise-all="trend-default trend-inverse trend-none">Raise all three</button>
</div>
// Raises each listed price by 5%, to show how each colour mode treats the same move.
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-raise-all]');
if (!button) {
return;
}
for (const id of button.dataset.raiseAll.split(' ')) {
const price = document.getElementById(id);
price.dataset.value = (Number(price.dataset.value) * 1.05).toFixed(2);
}
});
Slots
The before and after slots hold your own markup around the rolling number: "from", "/month", a unit or an icon. They aren't rolled, and screen readers read them as written, around the price. Here the plan toggle rolls between the monthly and the yearly price.
Team plan
Yearly billing saves 20%.
Show code Hide code
<div class="border-line bg-surface w-full max-w-sm rounded-3xl border p-5 sm:p-6">
<div class="flex flex-wrap items-center justify-between gap-x-3 gap-y-3">
<p class="text-base font-semibold sm:text-lg">Team plan</p>
<div class="bg-field inline-flex rounded-full p-1 text-sm" role="group" aria-label="Billing period">
<button type="button" class="aria-pressed:bg-surface aria-pressed:shadow-sm rounded-full px-3 py-1 font-medium" aria-pressed="true" data-billing="24" aria-controls="team-price">Monthly</button>
<button type="button" class="aria-pressed:bg-surface aria-pressed:shadow-sm rounded-full px-3 py-1 font-medium" aria-pressed="false" data-billing="19" aria-controls="team-price">Yearly</button>
</div>
</div>
<x-widget.price-roll id="team-price" :value="24" currency="USD" locale="en-US" :decimals="0" label="Team plan" trend-colors="none" live class="mt-4 text-5xl font-bold">
<x-slot:before class="text-foreground/75 text-base font-medium">from</x-slot:before>
<x-slot:after class="text-foreground/75 text-base font-medium">per seat / month</x-slot:after>
</x-widget.price-roll>
<p class="text-foreground/75 mt-2 text-sm">Yearly billing saves 20%.</p>
</div>
// The billing toggle: press one, and the price rolls to its amount.
document.addEventListener('click', (event) => {
const button = event.target.closest('[data-billing]');
const price = button && document.getElementById(button.getAttribute('aria-controls'));
if (!price) {
return;
}
button.parentElement.querySelectorAll('[data-billing]').forEach((other) => other.setAttribute('aria-pressed', String(other === button)));
price.dataset.value = button.dataset.billing;
});
Sizes
Size and weight come from your own classes, so it fits a hero, a card or a sentence. The digits roll within the line they're given.
Balance
Balance: $2,408.17Your next invoice is Next invoice: $49.00 , due on 1 October.
Show code Hide code
<div class="grid gap-8">
<x-widget.price-roll :value="1284930" currency="USD" locale="en-US" :decimals="0" label="Raised so far" class="text-4xl font-bold tracking-tight sm:text-6xl" />
<div class="border-line bg-surface max-w-xs rounded-2xl border p-4">
<p class="text-foreground/75 text-sm">Balance</p>
<x-widget.price-roll :value="2408.17" currency="USD" locale="en-US" label="Balance" class="text-2xl font-semibold" />
</div>
<p class="text-foreground/75 max-w-prose">Your next invoice is <x-widget.price-roll :value="49" currency="USD" locale="en-US" label="Next invoice" class="text-foreground font-semibold" />, due on 1 October.</p>
</div>
Formats
Formatting follows the locale, on the server and in the browser. currency=false formats a plain number. Without currency it uses config('app.currency').
Show code Hide code
<div class="flex flex-wrap items-baseline gap-8">
<x-widget.price-roll :value="1234567.5" currency="INR" locale="en-IN" class="text-2xl" />
<x-widget.price-roll :value="999" currency="EUR" locale="de-DE" :decimals="0" class="text-2xl" />
<x-widget.price-roll :value="1284" :currency="false" class="text-2xl" />
</div>
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.price-roll>
| Prop | Default | Description |
|---|---|---|
| value |
0
|
The number to show. Set data-value on it later and the digits roll to the new one. |
| currency |
null
|
A currency code like USD or EUR; config('app.currency') (or USD) when left out, and false for a plain number. |
| locale |
null
|
How the number is written, e.g. en-IN or de-DE: separators, symbol and its place. Defaults to the app's locale. |
| decimals |
null
|
Digits after the decimal point, always that many. Left out, the currency's usual number (up to 3 without one). |
| label |
null
|
Said before the price by screen readers ("Price: $64,210.50"); not shown. |
| live |
false
|
Announces each new price to screen readers as it changes. |
| previous |
null
|
Where the price started (today's open, say): adds a badge with the change since then, kept up to date as it rolls. |
| change |
'percent'
|
What the badge shows: percent (+4.38%), amount (+$115.65) or both. From a previous of 0, always the amount. |
| trend-colors |
'default'
|
How the change is coloured: default (up is green, down red), inverse (up is red, for a cost or a wait) or none. |
Accessibility
All 6 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.
Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.
Source
What bladewell:add price-roll writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from
the components it also adds , and the theme and base CSS.
resources/views/components/widget/price-roll/index.blade.php Show
resources/js/widget/price-roll/index.js Show