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
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
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
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
<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
<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>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>
);
}<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('-') } } }) --><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>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
| Property | Type | Default |
|---|---|---|
heading | string | "Get the newsletter" |
text | string | "" |
button | string | "Subscribe" |
thanks | string | "Thanks! Check your inbox to confirm." |
note | string | "" |
action | string | "" |
name | string | "email" |
| Event | When |
|---|---|
subscribe | Someone 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.