Taggor

All components · Category: Forms

Contact hours

A contact button that says if you are available now, or when you open.

Give it a weekly schedule and a time zone and it shows Available now or the next opening, with a pulsing dot. It uses the visitor's clock, needs no network and flips at the right minute by itself.

01

Try it

<contact-hours>
View

Props

Accent
Corners
contact-hours: A contact button that says if you are available now, or when you open. 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

<contact-hours locale="en"></contact-hours>

<script>
  const element = document.querySelector("contact-hours");
  element.addEventListener("contact-hours:contact", (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("contact-hours");
element.setAttribute("locale", "en");
element.addEventListener("contact-hours:contact", (event) => {
  console.log(event.detail);
});
document.body.append(element);
  • Add the site's Taggor script once; the component appears when it loads.

ContactHours.tsx

import { useEffect, useRef } from "react";

export function ContactHours() {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    const onContact = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("contact-hours:contact", onContact);
    return () => {
      element.removeEventListener("contact-hours:contact", onContact);
    };
  }, []);

  return <contact-hours 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.

ContactHours.tsx

import { useEffect, useRef } from "react";

export function ContactHours() {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    const onContact = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("contact-hours:contact", onContact);
    return () => {
      element.removeEventListener("contact-hours:contact", onContact);
    };
  }, []);

  return <contact-hours 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/ContactHours.vue

<script setup lang="ts">
function onContact(event: Event) {
  console.log((event as CustomEvent).detail);
}
</script>

<template>
  <contact-hours locale="en" @contact-hours:contact="onContact" />
</template>

vite.config.ts

import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag === "contact-hours",
        },
      },
    }),
  ],
});
  • 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/contact-hours.component.ts

import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";

@Component({
  selector: "app-contact-hours",
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <contact-hours locale="en"></contact-hours>
  `,
})
export class ContactHoursComponent {
  constructor() {
    const host = inject<ElementRef<HTMLElement>>(ElementRef);
    const element = () => host.nativeElement.querySelector("contact-hours");
    const onContact = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    afterNextRender(() => element()?.addEventListener("contact-hours:contact", onContact));
    inject(DestroyRef).onDestroy(() => element()?.removeEventListener("contact-hours:contact", onContact));
  }
}
  • 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 onContact(event) {
    console.log(event.detail);
  }
</script>

<contact-hours locale="en" oncontact-hours:contact={onContact}></contact-hours>
  • 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

contact-hours {
  --ch-radius: 18px;
}

02

Props

Props of the component, read from its manifest
PropTypeDefaultWhat it does
schedulelist[{"day":"mon","open":"09:00","close":"17:00"},{…Opening windows: a day (mon to sun) with open and close as HH:MM, same day.
timeZonestringAmerica/Sao_PauloThe schedule's IANA time zone, for example America/Sao_Paulo.
labelstringnoneReplaces the button text.
hrefurlnoneWhere the button goes; without it the button only tells the page.
hideWeekbooleanfalseHides the list of weekly hours.
hideSamplebooleanfalseHides the Sample content mark (use it with your own hours).
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
contactThe visitor pressed the contact button.

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 "Contact hours" (contact-hours): A contact button that says if you are available now, or when you open. 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