Price Input
Collects an amount with a visible currency code, configurable decimal precision, and native validation.
pnpm dlx shadcn@latest add @haze/price-input---
import { cn } from "../../../lib/haze/utils";
import Input from "./input.astro";
interface Props {
id: string;
name?: string;
label?: string;
currency?: string;
value?: number | string;
min?: number;
max?: number;
fractionDigits?: 0 | 1 | 2 | 3;
required?: boolean;
class?: string;
[key: string]: unknown;
}
const { id, name = id, label = "Budget", currency = "USD", value, min = 0, max,
fractionDigits = 2, required, class: className, ...rest } = Astro.props;
---
<div class={cn("grid min-w-0 gap-2", className)}>
<label for={id} class="text-[0.8125rem]/5 font-medium">{label} <span class="sr-only">in {currency}</span></label>
<div class="relative flex min-w-0">
<Input {...rest} id={id} name={name} type="number" inputmode="decimal" value={value} min={min} max={max} step={10 ** -fractionDigits}
placeholder={fractionDigits ? `0.${"0".repeat(fractionDigits)}` : "0"} required={required} class="tabular-nums [padding-inline-end:4.1rem] [&::-webkit-inner-spin-button]:appearance-none" />
<span aria-hidden="true" class="pointer-events-none absolute inset-y-px end-px flex w-14 items-center justify-center rounded-e-lg border-s border-border bg-muted px-1 font-mono text-[0.75rem]/4 font-medium text-muted-foreground">{currency}</span>
</div>
</div>When to use
- A form collects prices, limits, or budgets in a known currency.
- Minimum, maximum, and decimal place rules should work during submission.
When not to use
- Users need to compare or convert several currencies.
Installation
Add the Haze registry to components.json once, then install Price Input with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/price-inputnpx shadcn@latest add @haze/price-inputyarn dlx shadcn@latest add @haze/price-inputbunx --bun shadcn@latest add @haze/price-inputFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique field ID. |
| name | string | id | Submitted field name. |
| label | string | Budget | Visible field label. |
| currency | string | USD | Display currency code. |
| value | number | string | – | Initial amount. |
| min | number | 0 | Lowest allowed amount. |
| max | number | – | Highest allowed amount. |
| fractionDigits | 0 | 1 | 2 | 3 | 2 | Decimal precision for native step validation. |
| required | boolean | – | Requires an amount. |
| class | string | – | Classes for the field wrapper. |
Keyboard interactions
- Tab
- Focus the amount input.
- ↑↓
- Increment or decrement by one valid step.
Accessibility
- The label includes the currency for screen readers.
- The input submits the numeric amount in native form data.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Price Input" with `npx shadcn@latest add @haze/price-input`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import PriceInput from "@/components/haze/ui/price-input.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/price-input.md
Customize with real content
Adapt the Haze price-input ui for our product. Replace the demo values of these props with our real content: id, name, label, currency, value, min, max, fractionDigits, required, class. Keep the layout, the heading level rules and these accessibility details: The label includes the currency for screen readers. The input submits the numeric amount in native form data. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using price-input, check it fits: use it when a form collects prices, limits, or budgets in a known currency.; minimum, maximum, and decimal place rules should work during submission.. Avoid it when users need to compare or convert several currencies.. Alternatives: @haze/input, @haze/quantity-stepper, @haze/input-group.
Dependencies
- @haze/input
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.