ComponentsForms & inputs

Estimator

A live calculator: declarative inputs (number, slider, select, toggle, option cards, add-on checkboxes) feed a pure formula you pass, and a summary panel shows the total or a range, line items, a spec sheet, notes and a call to action that hands the selection on. Fee estimates, quotes, package builders, usage pricing and planners. Sticky beside the inputs on wide containers, a bottom bar on narrow ones.

components/estimator.tsxtheme · material · accent · density · font
Home size
Extras

Installation

$ pnpm add @vamos-ui/react

The whole kit as one package — get updates by bumping the version. Add the styles to globals.css: @import "@vamos-ui/react/styles.css";

Usage

import { Estimator } from "@vamos-ui/react";

<Estimator
  inputs={[
    { type: "options", id: "size", label: "Home size", variant: "segmented", options: [{ value: "s", label: "Studio" }, { value: "m", label: "2 rooms" }] },
    { type: "slider", id: "km", label: "Distance", min: 1, max: 80, format: (v) => `${v} km` },
    { type: "addons", id: "extras", label: "Extras", options: [{ value: "pack", label: "Packing", meta: "+ $900" }] },
  ]}
  formula={(v) => {
    const total = base[v.size as string] + (v.km as number) * 18;
    return { total, range: [total * 0.9, total * 1.1], lines: [{ id: "base", label: "Crew and truck", amount: total }] };
  }}
  cta="Get a fixed price"
  onSubmit={(values, result) => openQuoteForm(values, result)}
/>

The figure is announced once per change through a polite live region ("Total: $8,200"); line items stay in a description list.

Inputs are kit controls — RadioGroup, Checkbox cards, Slider, Switch, NumberInput, NativeSelect — so keyboard behaviour and labels come with them.

Keep the formula the single source of prices: use the same function for the "from" prices on the page and on the server that confirms the quote.

Examples

Fee statement into a form

numbered inputs, an add-on shown only for one company type (when), subtotal and tax lines, and name + form posting the selection as JSON with a contact form elsewhere on the page.

01What kind of company?

$90 per person a month: payslips and filings.

03Invoices a month
04Anything extra?

Usage pricing across plans

Lines compare plans; the cheapest that fits is highlighted with a badge, plans that do not fit show text instead of an amount.

Viewers are free on every plan.

Planner with extra content

A select and two sliders drive a projection; facts carry the goal and the month it is reached, summaryExtra adds a progress bar (or a chart).

API

Estimator

PropTypeDefault
inputs
Each { type, id, label, hint?, when?, disabled? } plus per type — "number": min/max/step · "slider": min, max, step?, marks?, format?, withInput? · "select": options (string labels) · "toggle": description? · "options": options, variant "card" | "segmented", columns? · "addons": options, columns?. Options are { value, label, description?, meta?, icon?, disabled?, when? }.
EstimatorInput[]—
formula
Pure. Returns { total: number | null, range?: [low, high], lines?, facts?, notes?, ready? }. Lines are { id, label, amount?, text?, detail?, kind?: "item" | "discount" | "subtotal" | "tax" | "info", highlight?, badge? }.
(values) => EstimateResult—
values / defaultValues / onValuesChange
Record<id, number | string | boolean | string[]>. onValuesChange gets (values, result).
EstimatorValues—
format
How amounts read; currency uses the provider currency or `currency`.
"currency" | "number" | (n) => string"currency"
currency / fractionDigits
Currency code and fraction digits.
string / numberprovider / 0
title / totalLabel / totalSuffix
Panel heading, label beside the figure ("Monthly, excl. tax") and text after it ("/ month").
ReactNode—
numbered
01, 02… before each input label.
booleanfalse
cta / ctaHref / onSubmit
The call to action. Disabled while the result is not ready (total null or ready: false).
ReactNode / string / (values, result) => void—
name / form / serialize
A hidden field with the selection (default JSON of { values, total, range }); form ties it to a form elsewhere.
string / string / (values, result) => string—
summaryExtra
Extra content in the panel: a chart, a timeline.
(values, result) => ReactNode—
stickyTop
Sticky offset below a fixed header.
string"1.5rem"
labels
Dictionary namespace "estimator": summary, total, range, live, empty, details, step.
Partial<EstimatorLabels>—

estimatorDefaults(inputs, overrides?) · effectiveEstimatorValues(inputs, values)

PropTypeDefault
returns
Initial values, and the values the formula sees (hidden add-ons dropped). Use them to run the formula on the server or in tests.
EstimatorValues—