Calculator
ProNewA calculator built from fields and formulas: sliders, number inputs, selects, radios, checkboxes and toggles feed a result panel that counts to the new total.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
<Calculator>
| Prop | Type | Default |
|---|---|---|
| title | string | — |
| description | string | — |
| fields* | CalculatorField[]The inputs, in order. | — |
| results* | CalculatorResult[]The first result is the headline number; the rest are listed under it. | — |
| breakdown | { label: string; value: (values: CalculatorValues) => number }[]Parts of a whole drawn as a stacked bar with a legend, e.g. principal and interest. | — |
| cta | CalculatorCtaA call to action at the bottom of the result panel. | — |
| layout | "side" | "stacked"`side` puts the results beside the fields when there is room; `stacked` always puts them below. | "side" |
| tone | "muted" | "tint" | "solid" | "dark"Look of the result panel: neutral, a tint of the accent, the accent itself, or near black. | "muted" |
| fieldStyle | "filled" | "outlined"Look of the value boxes and selects. | "filled" |
| align | "start" | "center"Title alignment. | "start" |
| accent | stringAccent for slider fills, checks and the button. Any CSS color. | "var(--primary)" |
| accentForeground | stringText color on top of the accent. | "var(--primary-foreground)" |
| locale | stringBCP 47 locale for number formatting. | "en-US" |
| resettable | booleanShow a reset link once a value differs from its default. | true |
| resetLabel | stringText of the reset link. | "Reset" |
| disabled | booleanDisable every input. | — |
| onValuesChange | (values: CalculatorValues) => voidCalled with the resolved values whenever one changes. | — |
| className | string | — |
<Field>
| Prop | Type | Default |
|---|---|---|
| field* | CalculatorField | — |
| raw* | Raw | — |
| onChange* | (raw: Raw) => void | — |
| disabled | boolean | — |
| number* | Intl.NumberFormat | — |
| box* | string | — |
Accessibility
- Sliders are Radix sliders with arrow, Page and Home/End keys, and announce the formatted value such as “$500,000”.
- Each value box is a labelled input; Enter commits, Escape restores, and out-of-range entries are clamped.
- Selects, radios and checkboxes are native controls; the toggle is a switch named by its label.
- Results are announced through a status region once the value settles, not on every step of a drag.
- Numbers change instantly, without counting, under reduced motion.