All components · Category: Depth and layers
Cube rotator
Features on the faces of a cube that turns, with a pause control.
Features on the faces of a prism that turns in CSS depth, with previous, next, pause and one button per face. It stops while the pointer or focus is inside and while it is off screen, and under reduced motion it never turns by itself.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<cube-rotator locale="en"></cube-rotator>
<script>
const element = document.querySelector("cube-rotator");
element.addEventListener("cube-rotator:turn", (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("cube-rotator");
element.setAttribute("locale", "en");
element.addEventListener("cube-rotator:turn", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
CubeRotator.tsx
import { useEffect, useRef } from "react";
export function CubeRotator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onTurn = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("cube-rotator:turn", onTurn);
return () => {
element.removeEventListener("cube-rotator:turn", onTurn);
};
}, []);
return <cube-rotator 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.
CubeRotator.tsx
import { useEffect, useRef } from "react";
export function CubeRotator() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onTurn = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("cube-rotator:turn", onTurn);
return () => {
element.removeEventListener("cube-rotator:turn", onTurn);
};
}, []);
return <cube-rotator 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/CubeRotator.vue
<script setup lang="ts">
function onTurn(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<cube-rotator locale="en" @cube-rotator:turn="onTurn" />
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "cube-rotator",
},
},
}),
],
});
- 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/cube-rotator.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-cube-rotator",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<cube-rotator locale="en"></cube-rotator>
`,
})
export class CubeRotatorComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("cube-rotator");
const onTurn = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("cube-rotator:turn", onTurn));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("cube-rotator:turn", onTurn));
}
}
- 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 onTurn(event) {
console.log(event.detail);
}
</script>
<cube-rotator locale="en" oncube-rotator:turn={onTurn}></cube-rotator>
- 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
cube-rotator {
--cr-radius: 16px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| features | list | none | One face each: a title and a short text (3 to 6 faces). |
| interval | number 2 to 12 | 4 | Seconds each face stays. |
| paused | boolean | false | Starts paused. |
| 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 |
|---|---|
| turn | A face came to the front. |
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 "Cube rotator" (cube-rotator): Features on the faces of a cube that turns, with a pause control.
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
- Product card flip<card-flip-3d>
- Card carousel<card-carousel>