All components · Category: Calculators
Loan simulator
A calculator with a range, a list of terms and two languages.
The visitor moves an amount and picks a term and sees the installment at once. Limits, rate, currency and the proposal link are props, so each site sets its own.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<finance-simulator
rate="1.2"
min-amount="5000"
max-amount="60000"
amount="24000"
currency="USD"
locale="en"
terms="[12,24,36,48]"
></finance-simulator>
<script>
const element = document.querySelector("finance-simulator");
element.addEventListener("finance-simulator:simulate", (event) => {
console.log(event.detail);
});
element.addEventListener("finance-simulator:proposal", (event) => {
console.log(event.detail);
});
</script>
- Add the site's Taggor script once; the component appears when it loads.
taggor-component.js
const element = document.createElement("finance-simulator");
element.setAttribute("rate", "1.2");
element.setAttribute("min-amount", "5000");
element.setAttribute("max-amount", "60000");
element.setAttribute("amount", "24000");
element.setAttribute("currency", "USD");
element.setAttribute("locale", "en");
element.terms = [
12,
24,
36,
48
];
element.addEventListener("finance-simulator:simulate", (event) => {
console.log(event.detail);
});
element.addEventListener("finance-simulator:proposal", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
- Lists and objects go in as a property of the element, not an attribute.
FinanceSimulator.tsx
import { useEffect, useRef } from "react";
export function FinanceSimulator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
Object.assign(element, {
terms: [
12,
24,
36,
48
],
});
const onSimulate = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("finance-simulator:simulate", onSimulate);
const onProposal = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("finance-simulator:proposal", onProposal);
return () => {
element.removeEventListener("finance-simulator:simulate", onSimulate);
element.removeEventListener("finance-simulator:proposal", onProposal);
};
}, []);
return <finance-simulator
ref={ref}
rate="1.2"
min-amount="5000"
max-amount="60000"
amount="24000"
currency="USD"
locale="en"
/>;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 18 sends every prop of a custom element as a text attribute.
- Lists and objects go in as a property of the element, not an attribute.
- The event is heard with addEventListener, inside an effect.
FinanceSimulator.tsx
import { useEffect, useRef } from "react";
export function FinanceSimulator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
Object.assign(element, {
terms: [
12,
24,
36,
48
],
});
const onSimulate = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("finance-simulator:simulate", onSimulate);
const onProposal = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("finance-simulator:proposal", onProposal);
return () => {
element.removeEventListener("finance-simulator:simulate", onSimulate);
element.removeEventListener("finance-simulator:proposal", onProposal);
};
}, []);
return <finance-simulator
ref={ref}
rate={1.2}
min-amount={5000}
max-amount={60000}
amount={24000}
currency="USD"
locale="en"
/>;
}
- Add the site's Taggor script once; the component appears when it loads.
- React 19 sets a property when the element already has it, an attribute otherwise.
- Lists and objects go in as a property of the element, not an attribute.
- The event is heard with addEventListener, inside an effect.
src/FinanceSimulator.vue
<script setup lang="ts">
function onSimulate(event: Event) {
console.log((event as CustomEvent).detail);
}
function onProposal(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<finance-simulator
:rate.prop="1.2"
:minAmount.prop="5000"
:maxAmount.prop="60000"
:amount.prop="24000"
currency="USD"
locale="en"
:terms.prop="[12,24,36,48]"
@finance-simulator:simulate="onSimulate"
@finance-simulator:proposal="onProposal"
/>
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "finance-simulator",
},
},
}),
],
});
- Add the site's Taggor script once; the component appears when it loads.
- vite.config.ts tells Vue that this tag is not a Vue component.
- Lists and objects go in as a property of the element, not an attribute.
src/app/finance-simulator.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-finance-simulator",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<finance-simulator
[rate]="1.2"
[minAmount]="5000"
[maxAmount]="60000"
[amount]="24000"
currency="USD"
locale="en"
[terms]="values.terms"
></finance-simulator>
`,
})
export class FinanceSimulatorComponent {
readonly values = {
terms: [
12,
24,
36,
48
],
};
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("finance-simulator");
const onSimulate = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("finance-simulator:simulate", onSimulate));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("finance-simulator:simulate", onSimulate));
const onProposal = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("finance-simulator:proposal", onProposal));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("finance-simulator:proposal", onProposal));
}
}
- Add the site's Taggor script once; the component appears when it loads.
- The component declares CUSTOM_ELEMENTS_SCHEMA.
- Lists and objects go in as a property of the element, not an attribute.
- The event is heard with addEventListener, inside an effect.
src/TaggorComponent.svelte
<script>
function onSimulate(event) {
console.log(event.detail);
}
function onProposal(event) {
console.log(event.detail);
}
</script>
<finance-simulator
rate={1.2}
min-amount={5000}
max-amount={60000}
amount={24000}
currency="USD"
locale="en"
terms={[
12,
24,
36,
48
]}
onfinance-simulator:simulate={onSimulate}
onfinance-simulator:proposal={onProposal}
></finance-simulator>
- Add the site's Taggor script once; the component appears when it loads.
How an agent gets a component like this onto a site:
taggor checktaggor publishThe CSS variables the component exposes, set the way a customer's page would.
styles.css
finance-simulator {
--fs-accent: #0a7d5a;
--fs-radius: 8px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| headline | string | none | Replaces the default heading. |
| rate | number 0 to 20 | 1.2 | Monthly interest rate, in percent. |
| minAmount | number 100 to 10000000 | 5000 | – |
| maxAmount | number 100 to 10000000 | 200000 | – |
| amount | number 100 to 10000000 | 50000 | Starting amount, kept between minAmount and maxAmount. |
| terms | list | [12,24,36,48,60] | Terms offered, in months. |
| currency | BRL | USD | EUR | BRL | – |
| proposalUrl | url | none | Where the proposal button leads; hidden when absent. |
| locale | pt-BR | en | pt-BR | – |
Prop names and descriptions are the component's own, in English, as its author wrote them.
03
Events
| Event | When it fires |
|---|---|
| simulate | The visitor changed the amount or the term. |
| proposal | The visitor clicked the proposal button. |
04
Build one with your agent
Paste this into your agent. It asks you before it signs in, pays or goes further than checking and publishing.
Build me a Taggor component like "Loan simulator" (finance-simulator): A calculator with a range, a list of terms and two languages.
Fetch https://taggor.dev/agent-setup/prompt.md and follow its instructions to set me up for Taggor. Ask me before you sign in, create an account, accept terms, pay for anything or type a secret.
Check it with `taggor check` and publish it with `taggor publish`, and stop there.
Do not promote it to production, attach it to a site, roll back anything or use --yes, --force or --force-drop-invalid unless I ask for exactly that in this conversation.
05
Related components
- Budget calculator<budget-calculator>
- Return calculator<roi-calculator>
- Pricing configurator<pricing-configurator>