All components · Category: Pricing and counters
Mini cart
A small cart with steppers, a badge and a subtotal, all local.
Quantity steppers, a count badge that pops and a subtotal in the visitor's currency format. The cart lives only in the component: there is no checkout, nothing is saved and nothing is sent. Products are marked as sample content until you pass your own.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<mini-cart locale="en"></mini-cart>
<script>
const element = document.querySelector("mini-cart");
element.addEventListener("mini-cart:change", (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("mini-cart");
element.setAttribute("locale", "en");
element.addEventListener("mini-cart:change", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
MiniCart.tsx
import { useEffect, useRef } from "react";
export function MiniCart() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onChange = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("mini-cart:change", onChange);
return () => {
element.removeEventListener("mini-cart:change", onChange);
};
}, []);
return <mini-cart ref={ref} 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.
- The event is heard with addEventListener, inside an effect.
MiniCart.tsx
import { useEffect, useRef } from "react";
export function MiniCart() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onChange = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("mini-cart:change", onChange);
return () => {
element.removeEventListener("mini-cart:change", onChange);
};
}, []);
return <mini-cart ref={ref} 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.
- The event is heard with addEventListener, inside an effect.
src/MiniCart.vue
<script setup lang="ts">
function onChange(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<mini-cart locale="en" @mini-cart:change="onChange" />
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "mini-cart",
},
},
}),
],
});
- 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.
src/app/mini-cart.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-mini-cart",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<mini-cart locale="en"></mini-cart>
`,
})
export class MiniCartComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("mini-cart");
const onChange = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("mini-cart:change", onChange));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("mini-cart:change", onChange));
}
}
- Add the site's Taggor script once; the component appears when it loads.
- The component declares CUSTOM_ELEMENTS_SCHEMA.
- The event is heard with addEventListener, inside an effect.
src/TaggorComponent.svelte
<script>
function onChange(event) {
console.log(event.detail);
}
</script>
<mini-cart locale="en" onmini-cart:change={onChange}></mini-cart>
- 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
mini-cart {
--mc-radius: 18px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| items | list | none | The products: a name, a unit price, how many start in the cart and a hue for the picture. |
| currency | string | USD | ISO 4217 code of the prices. |
| hideSample | boolean | false | Hides the Sample content mark (use it with your own products). |
| 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 |
|---|---|
| change | The cart 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 "Mini cart" (mini-cart): A small cart with steppers, a badge and a subtotal, all local.
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
- Free shipping bar<free-shipping-bar>
- Variant picker<variant-picker>
- Quote wizard<quote-wizard>