Unit Price

Unit Price is a copy-paste React component that stops bigger pack costs more per kg before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/unit-price
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsBigger pack costs more per kg

Was this component page useful?

How do I install Unit Price?

pnpm dlx shadcn@latest add @bollard/unit-price

The files land in your project. They're yours to edit.

How do I use Unit Price in React?

unit-price-usage.tsx
import { UnitPrice, type PriceOption } from "@/components/ui/unit-price"

<UnitPrice options={teas} value={picked} onValueChange={setPicked} />

What input mistakes does Unit Price catch?

  • Bigger packs that cost more per unit
  • Multi-buy offers that cost more than buying singles
  • Shrinkflation: a smaller pack at the same price
  • The true cheapest per dimension (weight, volume, count)

What props does Unit Price accept?

UnitPrice props
PropTypeDefault
options* (required)

Packs to compare, with price, size and unit.

PriceOption[]—
value

Controlled id of the chosen option.

string—
defaultValue

Initial choice when uncontrolled.

string—
onValueChange

Called with the chosen option id.

(id: string) => void—
basis

Override the quantity each kind is priced per (e.g. per kg).

Record<Dimension, { quantity: number; label: string }>DEFAULT_BASIS
currency

ISO 4217 currency code.

string"INR"
locale

Locale for money formatting.

string"en-IN"
label

Visible label of the options.

string"Compare by unit price"
cheapestLabel

Templates. `{name}`, `{amount}`, `{size}`, `{pct}`, `{offer}` are filled in.

string"Cheapest"
dealWorseText

Warning when a multi-buy costs more per unit.

string"{offer} costs {amount} more than buying singles."
bulkTrapText

Warning when a bigger pack costs more per unit.

string"Bigger isn't cheaper: {pct} more per {size} than {name}."
shrankText

Warning when a pack shrank at the same price.

string"Pack shrank from {size}: {pct} more per unit at the same…
pickedText

Readback of the picked option against the cheapest.

string"The same amount of {name} costs {amount} less."
switchLabel

Label of the switch-to-cheapest fix.

string"Switch to {name}"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Unit Price accessible?

  • Options are a roving-tabindex radiogroup with arrow keys
  • Cheapest and warnings marked with icons and text
  • Findings in a polite live region

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

  • Compares only the options and sizes you pass
  • Ignores quality, expiry and delivery costs

What expensive mistakes does Unit Price stop?

Bigger pack costs more per kg

Also known as

unit price · price per 100g · grocery · blinkit · zepto · bigbasket · pack size · shrinkflation

Field type

What dependencies does Unit Price require?

Unit Price facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameUnit Price
Registry identifier@bollard/unit-price
Install commandnpx shadcn@latest add @bollard/unit-price
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Unit Price

How does Unit Price validate Indian financial identifiers?

Unit Price stops bigger pack costs more per kg. Complies with national standards for Bigger packs that cost more per unit, Multi-buy offers that cost more than buying singles, Shrinkflation: a smaller pack at the same price, The true cheapest per dimension (weight, volume, count). Limitation: verify unit-price with issuer gateway.

How do I install unit-price with shadcn?

Run `npx shadcn@latest add @bollard/unit-price`. Sources added: registry/default/unit-price/unit-price.tsx. Package requirements: lucide-react.

What props customize Unit Price?

Unit Price accepts `options`, `value`, `defaultValue`, `onValueChange`, `basis`. Configures unit price, price per 100g, grocery behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of unit-price?

Compares only the options and sizes you pass. Ignores quality, expiry and delivery costs Server requirement: backend verification for unit-price.

How does Unit Price meet accessibility guidelines?

Options are a roving-tabindex radiogroup with arrow keys. Cheapest and warnings marked with icons and text. Findings in a polite live region. Minimizes errors: bigger pack costs more, price per kg.

Which components pair with Unit Price?