Taggor

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

<cube-rotator>
View

Props

Accent
Corners
cube-rotator: Features on the faces of a cube that turns, with a pause control. 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

<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 publish

The CSS variables the component exposes, set the way a customer's page would.

styles.css

cube-rotator {
  --cr-radius: 16px;
}

02

Props

Props of the component, read from its manifest
PropTypeDefaultWhat it does
featureslistnoneOne face each: a title and a short text (3 to 6 faces).
intervalnumber 2 to 124Seconds each face stays.
pausedbooleanfalseStarts paused.
localept-BR | enen–

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
turnA 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