All components · Category: Pricing and counters
Plan calculator
Usage sliders that light the plan that fits.
Two sliders for how much a visitor will use, and a row of plans where the cheapest one that covers it lights up. Plans, prices and limits come from props. A sentence for screen readers says which plan fits, or that the need is beyond them all.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<plan-calculator
currency="USD"
locale="en"
plans="[{"name":"Free","price":0,"sites":3,"renders":10000},{"name":"Pro","price":14,"sites":25,"renders":1250000},{"name":"Agency","price":49,"sites":100,"renders":4000000}]"
></plan-calculator>
<script>
const element = document.querySelector("plan-calculator");
element.addEventListener("plan-calculator:fit", (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("plan-calculator");
element.setAttribute("currency", "USD");
element.setAttribute("locale", "en");
element.plans = [
{
"name": "Free",
"price": 0,
"sites": 3,
"renders": 10000
},
{
"name": "Pro",
"price": 14,
"sites": 25,
"renders": 1250000
},
{
"name": "Agency",
"price": 49,
"sites": 100,
"renders": 4000000
}
];
element.addEventListener("plan-calculator:fit", (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.
PlanCalculator.tsx
import { useEffect, useRef } from "react";
export function PlanCalculator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
Object.assign(element, {
plans: [
{
"name": "Free",
"price": 0,
"sites": 3,
"renders": 10000
},
{
"name": "Pro",
"price": 14,
"sites": 25,
"renders": 1250000
},
{
"name": "Agency",
"price": 49,
"sites": 100,
"renders": 4000000
}
],
});
const onFit = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("plan-calculator:fit", onFit);
return () => {
element.removeEventListener("plan-calculator:fit", onFit);
};
}, []);
return <plan-calculator ref={ref} 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.
PlanCalculator.tsx
import { useEffect, useRef } from "react";
export function PlanCalculator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
Object.assign(element, {
plans: [
{
"name": "Free",
"price": 0,
"sites": 3,
"renders": 10000
},
{
"name": "Pro",
"price": 14,
"sites": 25,
"renders": 1250000
},
{
"name": "Agency",
"price": 49,
"sites": 100,
"renders": 4000000
}
],
});
const onFit = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("plan-calculator:fit", onFit);
return () => {
element.removeEventListener("plan-calculator:fit", onFit);
};
}, []);
return <plan-calculator ref={ref} 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/PlanCalculator.vue
<script setup lang="ts">
function onFit(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<plan-calculator
currency="USD"
locale="en"
:plans.prop="[{"name":"Free","price":0,"sites":3,"renders":10000},{"name":"Pro","price":14,"sites":25,"renders":1250000},{"name":"Agency","price":49,"sites":100,"renders":4000000}]"
@plan-calculator:fit="onFit"
/>
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "plan-calculator",
},
},
}),
],
});
- 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/plan-calculator.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-plan-calculator",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<plan-calculator currency="USD" locale="en" [plans]="values.plans"></plan-calculator>
`,
})
export class PlanCalculatorComponent {
readonly values = {
plans: [
{
"name": "Free",
"price": 0,
"sites": 3,
"renders": 10000
},
{
"name": "Pro",
"price": 14,
"sites": 25,
"renders": 1250000
},
{
"name": "Agency",
"price": 49,
"sites": 100,
"renders": 4000000
}
],
};
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("plan-calculator");
const onFit = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("plan-calculator:fit", onFit));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("plan-calculator:fit", onFit));
}
}
- 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 onFit(event) {
console.log(event.detail);
}
</script>
<plan-calculator
currency="USD"
locale="en"
plans={[
{
"name": "Free",
"price": 0,
"sites": 3,
"renders": 10000
},
{
"name": "Pro",
"price": 14,
"sites": 25,
"renders": 1250000
},
{
"name": "Agency",
"price": 49,
"sites": 100,
"renders": 4000000
}
]}
onplan-calculator:fit={onFit}
></plan-calculator>
- 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
plan-calculator {
--pc-radius: 18px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| plans | list | none | The plans: a name, a price a month and the sites and page views a month they include. |
| currency | string | USD | ISO 4217 code of the prices. |
| hideSample | boolean | false | Hides the Sample content mark (use it with your own plans). |
| locale | pt-BR | en | en | – |
Prop names and descriptions are the component's own, in English, as its author wrote them.
03
Events
| Event | When it fires |
|---|---|
| fit | The plan that fits changed. |
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 "Plan calculator" (plan-calculator): Usage sliders that light the plan that fits.
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
- Pricing toggle<pricing-toggle>
- Return calculator<roi-calculator>
- Budget calculator<budget-calculator>