Taggor

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

<finance-simulator>
View

Props

Site
Accent
Corners
Language
finance-simulator: a calculator with numbers, a list of terms and two languages. A picture of the real component, drawn from its own code. The controls change the picture and the code beside it; nothing here is sent or stored.

Generated from the component's manifest and the values above.

Code for

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 publish

The 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

Props of the component, read from its manifest
PropTypeDefaultWhat it does
headlinestringnoneReplaces the default heading.
ratenumber 0 to 201.2Monthly interest rate, in percent.
minAmountnumber 100 to 100000005000–
maxAmountnumber 100 to 10000000200000–
amountnumber 100 to 1000000050000Starting amount, kept between minAmount and maxAmount.
termslist[12,24,36,48,60]Terms offered, in months.
currencyBRL | USD | EURBRL–
proposalUrlurlnoneWhere the proposal button leads; hidden when absent.
localept-BR | enpt-BR–

Prop names and descriptions are the component's own, in English, as its author wrote them.

03

Events

Events of the component, read from its manifest
EventWhen it fires
simulateThe visitor changed the amount or the term.
proposalThe 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