Zubra UI
Code for
GitHub

newsletter-signup

An email signup: a heading, a line on what people get, one email field and a button. It checks the address with the browser's own validation, fires subscribe with it, and says thank you in place (announced). Without JavaScript it's a plain form that posts to action.

Try it: events appear here (subscribe).

Source: newsletter-signup.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/newsletter-signup.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/newsletter-signup.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/newsletter-signup.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/newsletter-signup.json
One file, no dependencies (3.4 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/newsletter-signup.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/newsletter-signup.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/newsletter-signup.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/newsletter-signup.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/newsletter-signup.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/newsletter-signup.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/newsletter-signup.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/newsletter-signup.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/newsletter-signup.js"></script>

The compiled install writes src/components/zubra/newsletter-signup.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<newsletter-signup
  heading="Get the weekly loaf"
  text="One recipe and one technique, every Friday."
  note="No spam. Unsubscribe any time."
></newsletter-signup>

<script type="module">
  import './components/zubra/newsletter-signup.js';

  const element = document.querySelector('newsletter-signup');
  element.addEventListener('subscribe', (event) => console.log('subscribe', event.detail));
</script>
Example.jsx
import './components/zubra/newsletter-signup.js';

export function NewsletterSignupExample() {
  return (
    <newsletter-signup
      heading="Get the weekly loaf"
      text="One recipe and one technique, every Friday."
      note="No spam. Unsubscribe any time."
      onsubscribe={(event) => console.log('subscribe', event.detail)}
    ></newsletter-signup>
  );
}
Example.vue
<script setup>
import './components/zubra/newsletter-signup.js';
const onSubscribe = (event) => console.log('subscribe', event.detail);
</script>

<template>
  <newsletter-signup
    heading="Get the weekly loaf"
    text="One recipe and one technique, every Friday."
    note="No spam. Unsubscribe any time."
    @subscribe="onSubscribe"
  ></newsletter-signup>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/newsletter-signup.js';
</script>

<newsletter-signup
  heading="Get the weekly loaf"
  text="One recipe and one technique, every Friday."
  note="No spam. Unsubscribe any time."
  onsubscribe={(event) => console.log('subscribe', event.detail)}
></newsletter-signup>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/newsletter-signup.js';

@Component({
  selector: 'app-newsletter-signup-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <newsletter-signup
      heading="Get the weekly loaf"
      text="One recipe and one technique, every Friday."
      note="No spam. Unsubscribe any time."
      (subscribe)="onSubscribe($event)"
    ></newsletter-signup>
  `,
})
export class NewsletterSignupExample {
  onSubscribe(event: Event) {
    console.log('subscribe', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
headingstring"Get the newsletter"
textstring""
buttonstring"Subscribe"
thanksstring"Thanks! Check your inbox to confirm."
notestring""
actionstring""
namestring"email"
Events
EventWhen
subscribeSomeone signed up; detail is their email address. Cancel it to keep the form showing.

Size

1.5 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.2 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour