Newsletter

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

Status: beta. Category: Blocks.

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

PropTypeDefaultDescription
onSubscribe (required)(email: string) => void | Promise<void>Called with the email. Reject (throw) to show errorMessage or the error's message.
title (required)ReactNode
animatebooleantrueEntrance 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.
buttonLabelReactNodeSubscribe
descriptionReactNode
errorMessageReactNode
headingLevelHeadingLevel2
invalidMessageReactNodeEnter a valid email address.
layout"split" | "centered"centeredcentered (default) or split with text beside the form on large screens.
placeholderstring[email protected]
privacyNoteReactNodeSmall print under the form, e.g. how often you send and how to unsubscribe.
successMessageReactNodeYou’re subscribed. Check your inbox to confirm.

Example: Centered

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

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

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