# Newsletter

> Email signup with validation and loading, success and error states built in.

Status: beta. Category: Blocks.

```ts
import { Newsletter } from '@glyphui/blocks'
```

Exports: `Newsletter`.

## Notes

- Throw from onSubscribe to show an error; its message is used unless you pass errorMessage.

## Newsletter props

| Prop | Type | Default | Description |
|---|---|---|---|
| `onSubscribe` (required) | `(email: string) => void \| Promise<void>` |  | Called with the email. Reject (throw) to show `errorMessage` or the error's message. |
| `title` (required) | `ReactNode` |  |  |
| `animate` | `boolean` | `true` | Entrance animations as the block scrolls into view. They follow the theme's motion level and the visitor's reduced-motion setting; `false` turns them off for this block. Default true. |
| `buttonLabel` | `ReactNode` | `Subscribe` |  |
| `description` | `ReactNode` |  |  |
| `errorMessage` | `ReactNode` |  |  |
| `headingLevel` | `HeadingLevel` | `2` |  |
| `invalidMessage` | `ReactNode` | `Enter a valid email address.` |  |
| `layout` | `"split" \| "centered"` | `centered` | `centered` (default) or `split` with text beside the form on large screens. |
| `placeholder` | `string` | `you@company.com` |  |
| `privacyNote` | `ReactNode` |  | Small print under the form, e.g. how often you send and how to unsubscribe. |
| `successMessage` | `ReactNode` | `You’re subscribed. Check your inbox to confirm.` |  |

## Example: Centered

Try an address ending in @fail.dev to see the error state.

```tsx
import { Newsletter } from '@glyphui/blocks'

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

export default function Example() {
  return (
    <Newsletter
      title="The Ledgerline letter"
      description="One email a month on billing, pricing and getting paid faster."
      privacyNote="No spam. Unsubscribe with one click."
      onSubscribe={async (email) => {
        await wait(800)
        if (email.endsWith('@fail.dev'))
          throw new Error('We couldn’t reach the mailing service. Try again.')
      }}
    />
  )
}
```

## Example: Split

```tsx
import { Newsletter } from '@glyphui/blocks'

export default function Example() {
  return (
    <Newsletter
      layout="split"
      title="Get the changelog"
      description="Release notes for every version, straight to your inbox."
      buttonLabel="Notify me"
      onSubscribe={() => new Promise((resolve) => setTimeout(resolve, 600))}
    />
  )
}
```

Live page: https://glyphui.xyz/components/newsletter
