Calm motion: animations on this site only fade, with no movement
Newsletter signup
An email field and a button, with checks and a thank-you
Asks for an email address to join a list, in a footer or at the end of an article. Your server adds the address, and the component shows the result. For a full form, use the form.
Basic
One email a week. Leave at any time. Privacy policy
vue
<template>
<div style="display: grid; gap: 12px">
<BlessNewsletterSignup v-model="email" :status :error privacy-href="#" @subscribe="subscribe" />
<BlessButton
v-if="status === 'done'"
size="sm"
variant="outline"
style="justify-self: start"
@click="status = 'idle'"
>
Start again
</BlessButton>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { BlessButton, BlessNewsletterSignup } from "blessing-ui";
const email = ref("");
const status = ref<"idle" | "loading" | "done">("idle");
const error = ref<string>();
// a stand-in for your server: an address at example.com is already on the list
function subscribe(address: string) {
status.value = "loading";
error.value = undefined;
setTimeout(() => {
if (address.endsWith("@example.com")) {
status.value = "idle";
error.value = "This address is already on the list.";
} else status.value = "done";
}, 700);
}
</script>v-modelis the address. The button emitssubscribewith the address, without spaces at the ends.- Before it emits, the browser checks the form of the address. A bad address shows a hint under the field.
- Set
statustoloadingwhile your server works. The button shows a spinner, and a second send does not go out. - If the server cannot add the address, set
errorto the reason. If it can, setstatustodone. A thank-you takes the place of the form, and screen readers hear it. - A line under the field says what the reader gets.
privacy-hrefadds a link to your privacy policy. - Change the words with
labelsor a label pack:label,button,done,invalid,privacy, andpolicy.
Usage
ts
import { BlessNewsletterSignup } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
status | "done" | "loading" | "idle" | "idle" | `loading` while your server works, `done` after it took the address |
error | string | — | a reason from your server, for example "This address is already on the list" |
privacyHref | string | — | a link to the privacy policy |
labels | Partial<{ label: string; button: string; done: string; invalid: string; privacy: string; policy: string; }> | — | |
modelValue | string | "" |
Events
| Name | Payload | Description |
|---|---|---|
update:modelValue | [value: string] | |
subscribe | [email: string] |