Taggor

All components · Category: Banners and notices

Toast stack

Short notices you can dismiss by swiping, with a button or with Escape.

A stack of notices with their own icons. Swipe one sideways, press its close button or hit Escape to dismiss it. If you set a time, a notice waits while the pointer or the keyboard focus is on it. New notices are announced politely to screen readers.

01

Try it

<toast-stack>
View

Props

Corners
toast-stack: Short notices you can dismiss by swiping, with a button or with Escape. 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

<toast-stack
  locale="en"
  toasts="[{&quot;kind&quot;:&quot;success&quot;,&quot;text&quot;:&quot;Saved. Your changes are live.&quot;},{&quot;kind&quot;:&quot;info&quot;,&quot;text&quot;:&quot;A new comment arrived on the launch page.&quot;},{&quot;kind&quot;:&quot;warning&quot;,&quot;text&quot;:&quot;Heads up: the sample import is running slowly.&quot;}]"
></toast-stack>

<script>
  const element = document.querySelector("toast-stack");
  element.addEventListener("toast-stack:dismissed", (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("toast-stack");
element.setAttribute("locale", "en");
element.toasts = [
  {
    "kind": "success",
    "text": "Saved. Your changes are live."
  },
  {
    "kind": "info",
    "text": "A new comment arrived on the launch page."
  },
  {
    "kind": "warning",
    "text": "Heads up: the sample import is running slowly."
  }
];
element.addEventListener("toast-stack:dismissed", (event) => {
  console.log(event.detail);
});
document.body.append(element);
  • Add the site's Taggor script once; the component appears when it loads.
  • Lists and objects go in as a property of the element, not an attribute.

ToastStack.tsx

import { useEffect, useRef } from "react";

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

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    Object.assign(element, {
      toasts: [
        {
          "kind": "success",
          "text": "Saved. Your changes are live."
        },
        {
          "kind": "info",
          "text": "A new comment arrived on the launch page."
        },
        {
          "kind": "warning",
          "text": "Heads up: the sample import is running slowly."
        }
      ],
    });
    const onDismissed = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("toast-stack:dismissed", onDismissed);
    return () => {
      element.removeEventListener("toast-stack:dismissed", onDismissed);
    };
  }, []);

  return <toast-stack 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.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

ToastStack.tsx

import { useEffect, useRef } from "react";

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

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    Object.assign(element, {
      toasts: [
        {
          "kind": "success",
          "text": "Saved. Your changes are live."
        },
        {
          "kind": "info",
          "text": "A new comment arrived on the launch page."
        },
        {
          "kind": "warning",
          "text": "Heads up: the sample import is running slowly."
        }
      ],
    });
    const onDismissed = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("toast-stack:dismissed", onDismissed);
    return () => {
      element.removeEventListener("toast-stack:dismissed", onDismissed);
    };
  }, []);

  return <toast-stack 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.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

src/ToastStack.vue

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

<template>
  <toast-stack
    locale="en"
    :toasts.prop="[{&quot;kind&quot;:&quot;success&quot;,&quot;text&quot;:&quot;Saved. Your changes are live.&quot;},{&quot;kind&quot;:&quot;info&quot;,&quot;text&quot;:&quot;A new comment arrived on the launch page.&quot;},{&quot;kind&quot;:&quot;warning&quot;,&quot;text&quot;:&quot;Heads up: the sample import is running slowly.&quot;}]"
    @toast-stack:dismissed="onDismissed"
  />
</template>

vite.config.ts

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

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag === "toast-stack",
        },
      },
    }),
  ],
});
  • 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.
  • Lists and objects go in as a property of the element, not an attribute.

src/app/toast-stack.component.ts

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

@Component({
  selector: "app-toast-stack",
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <toast-stack locale="en" [toasts]="values.toasts"></toast-stack>
  `,
})
export class ToastStackComponent {
  readonly values = {
    toasts: [
      {
        "kind": "success",
        "text": "Saved. Your changes are live."
      },
      {
        "kind": "info",
        "text": "A new comment arrived on the launch page."
      },
      {
        "kind": "warning",
        "text": "Heads up: the sample import is running slowly."
      }
    ],
  };

  constructor() {
    const host = inject<ElementRef<HTMLElement>>(ElementRef);
    const element = () => host.nativeElement.querySelector("toast-stack");
    const onDismissed = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    afterNextRender(() => element()?.addEventListener("toast-stack:dismissed", onDismissed));
    inject(DestroyRef).onDestroy(() => element()?.removeEventListener("toast-stack:dismissed", onDismissed));
  }
}
  • Add the site's Taggor script once; the component appears when it loads.
  • The component declares CUSTOM_ELEMENTS_SCHEMA.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

src/TaggorComponent.svelte

<script>
  function onDismissed(event) {
    console.log(event.detail);
  }
</script>

<toast-stack
  locale="en"
  toasts={[
    {
      "kind": "success",
      "text": "Saved. Your changes are live."
    },
    {
      "kind": "info",
      "text": "A new comment arrived on the launch page."
    },
    {
      "kind": "warning",
      "text": "Heads up: the sample import is running slowly."
    }
  ]}
  ontoast-stack:dismissed={onDismissed}
></toast-stack>
  • 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

toast-stack {
  --ts-radius: 14px;
}

02

Props

Props of the component, read from its manifest
PropTypeDefaultWhat it does
toastslistnoneThe toasts on screen at the start: a kind and a text each.
durationnumber 0 to 600Seconds before a toast goes away by itself; 0 keeps it until dismissed.
hideControlsbooleanfalseHides the Show and Clear buttons.
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
dismissedA toast was dismissed.

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 "Toast stack" (toast-stack): Short notices you can dismiss by swiping, with a button or with Escape. 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