All components · Category: Depth and layers
Product card flip
A product card that turns over to its specs, with color variants.
A product card that flips in CSS depth from the product to its spec sheet, with color variants you choose with the mouse or the arrow keys. The hidden face is out of reach of focus and screen readers. Reduced motion switches faces without the turn.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<card-flip-3d locale="en"></card-flip-3d>
<script>
const element = document.querySelector("card-flip-3d");
element.addEventListener("card-flip-3d:flip", (event) => {
console.log(event.detail);
});
element.addEventListener("card-flip-3d:variant", (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("card-flip-3d");
element.setAttribute("locale", "en");
element.addEventListener("card-flip-3d:flip", (event) => {
console.log(event.detail);
});
element.addEventListener("card-flip-3d:variant", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
CardFlip3d.tsx
import { useEffect, useRef } from "react";
export function CardFlip3d() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onFlip = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("card-flip-3d:flip", onFlip);
const onVariant = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("card-flip-3d:variant", onVariant);
return () => {
element.removeEventListener("card-flip-3d:flip", onFlip);
element.removeEventListener("card-flip-3d:variant", onVariant);
};
}, []);
return <card-flip-3d 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.
CardFlip3d.tsx
import { useEffect, useRef } from "react";
export function CardFlip3d() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onFlip = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("card-flip-3d:flip", onFlip);
const onVariant = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("card-flip-3d:variant", onVariant);
return () => {
element.removeEventListener("card-flip-3d:flip", onFlip);
element.removeEventListener("card-flip-3d:variant", onVariant);
};
}, []);
return <card-flip-3d 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/CardFlip3d.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
const element = ref<HTMLElement | null>(null);
function onFlip(event: Event) {
console.log((event as CustomEvent).detail);
}
function onVariant(event: Event) {
console.log((event as CustomEvent).detail);
}
onMounted(() => {
element.value?.addEventListener("card-flip-3d:flip", onFlip);
element.value?.addEventListener("card-flip-3d:variant", onVariant);
});
onBeforeUnmount(() => {
element.value?.removeEventListener("card-flip-3d:flip", onFlip);
element.value?.removeEventListener("card-flip-3d:variant", onVariant);
});
</script>
<template>
<card-flip-3d ref="element" locale="en" />
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "card-flip-3d",
},
},
}),
],
});
- 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.
- The event is heard with addEventListener, inside an effect.
src/app/card-flip-3d.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-card-flip-3d",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<card-flip-3d locale="en"></card-flip-3d>
`,
})
export class CardFlip3dComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("card-flip-3d");
const onFlip = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("card-flip-3d:flip", onFlip));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("card-flip-3d:flip", onFlip));
const onVariant = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("card-flip-3d:variant", onVariant));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("card-flip-3d:variant", onVariant));
}
}
- 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 onFlip(event) {
console.log(event.detail);
}
function onVariant(event) {
console.log(event.detail);
}
</script>
<card-flip-3d
locale="en"
oncard-flip-3d:flip={onFlip}
oncard-flip-3d:variant={onVariant}
></card-flip-3d>
- 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
card-flip-3d {
--cf-radius: 22px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| productName | string | none | Replaces the product name. |
| tagline | string | none | Replaces the line under the name. |
| variants | list | none | Colour variants: a name and a CSS colour (hex or name). |
| specs | list | none | Spec rows on the back of the card. |
| flipped | boolean | false | Starts on the spec sheet. |
| hideSample | boolean | false | Hides the Sample content mark (use your own product). |
| 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 |
|---|---|
| flip | The card turned to a side. |
| variant | The visitor chose a colour variant. |
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 "Product card flip" (card-flip-3d): A product card that turns over to its specs, with color variants.
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
- Tilting card<card-tilt>
- Cube rotator<cube-rotator>
- Card carousel<card-carousel>