DDBS UI
section

Option Calculator

A playful estimator: each step is a dashed circle that cycles through its options when pressed, and a live result updates as choices change. The maths is a callback.

npx shadcn@latest add https://ui.develop-better-solutions.com/r/option-calculator.json
Dependencies:lucide-react
Fullscreen

Simple saving
calculator

Property type
Sun exposure
Roof age

Pick the three options that describe your roof to see a rough yearly saving.

Est. savings: $3,019/yr

Usage

option-calculator-example.tsx
"use client";

import { Home, Sun, Hourglass } from "lucide-react";
import { OptionCalculator } from "@dbs/ui";

const BASE: Record<string, number> = { Residential: 2100, Commercial: 4200, Industrial: 8400 };
const SUN: Record<string, number> = { "Full sun": 1.25, "Some shade": 1, "Heavy shade": 0.75 };
const AGE: Record<string, number> = { "Under 10 years": 1.15, "10 to 20 years": 1.05, "Over 20 years": 0.95 };

export default function OptionCalculatorExample() {
  return (
    <OptionCalculator
      heading={<>Simple saving<br />calculator</>}
      description="Pick the three options that describe your roof to see a rough yearly saving."
      resultLabel="Est. savings"
      submitLabel="Custom estimate"
      steps={[
        { id: "type", title: "Property type", options: ["Residential", "Commercial", "Industrial"], icon: <Home /> },
        { id: "sun", title: "Sun exposure", options: ["Full sun", "Some shade", "Heavy shade"], icon: <Sun /> },
        { id: "age", title: "Roof age", options: ["Under 10 years", "10 to 20 years", "Over 20 years"], icon: <Hourglass /> },
      ]}
      compute={(c) => `$${Math.round((BASE[c.type ?? ""] ?? 0) * (SUN[c.sun ?? ""] ?? 1) * (AGE[c.age ?? ""] ?? 1)).toLocaleString("en-US")}/yr`}
    />
  );
}