🚀 Ship faster with premium components 🚀
Search documentation v1.2.0

Newsletter Popup

Promote newsletter subscriptions with a popup

Source Report Issue
Command docs
How to add this block to your project
npm run add NewsletterPopup

Use the NewsletterPopup component to display a modal for users to subscribe to a newsletter. They capture user attention effectively, boosting sign-up rates, and their high visibility ensures the offer stands out without relying on page placement.

Preview
Unlock code
How to use the NewsletterPopup component in Astro
---
import { Button } from 'webcoreui/astro'
---
<Button className="button">Show Popup</Button>
<NewsletterPopup
className="popup"
title="Preview - card title"
heading="Join our Newsletter"
text="Don't miss out on <b>important updates</b>!"
img={{
src: '/img/newsletter.png',
alt: 'Newsletter',
width: 250,
height: 300
}}
/>
<script>
import { modal } from 'webcoreui'
modal({
trigger: '.button',
modal: '.popup'
})
</script>
Unlock code
How to use the NewsletterPopup component in Astro
<NewsletterPopup
className="popup"
title="Preview - card title"
heading="Join our Newsletter"
text="Don't miss out on <b>important updates</b>!"
img={{
src: '/img/newsletter.png',
alt: 'Newsletter',
width: 250,
height: 300
}}
/>
<script>
import { modal } from 'webcoreui'
const modalInstance = modal('.popup')
// Trigger open
modalInstance.open()
</script>

Only the img and heading props are mandatory for the NewsletterPopup component. By default, it’ll use a form with an email and a “Subscribe” button that can be customized through the form prop, or directly inside the component. The additional props are optional. The component extends the Modal component, meaning you can use modal-specific props as well, such as showCloseIcon or theme.

Automatic Focus

To automatically focus the input field within the popup when it opens, you can extend the modal call with the following onOpen method:

Unlock code
How to focus the input automatically
modal({
trigger: '.your-trigger-selector'
modal: '.your-modal-selector',
onOpen({ modal }) {
modal.querySelector('input')?.focus()
}
})

Custom Form

You can also define a custom form through the form prop, or edit the default form directly inside the component:

newsletter image
Join our Newsletter
Don't miss out on important updates! Join now to level up your skills.
Unlock code
How to set custom forms
<NewsletterPopup
...
form={[
{
type: 'group',
fields: [
{
type: 'text',
placeholder: 'Name',
name: 'name'
},
{
type: 'email',
placeholder: 'Email',
name: 'email'
}
]
},
{
type: 'button',
label: 'Join',
theme: 'success'
}
]}
/>
To handle form submission and user interaction, you can edit the provided onChange, onSubmit and onError calls inside the component.

API

Unlock code
Component API reference
type NewsletterCardProps = {
heading?: string
text?: string
form?: FormField[]
img: {
src: string
alt: string
width: number
height: number
}
} & ModalProps
PropPurpose
heading Sets a heading for the popup.
text Sets a text under the heading. Supports the use of HTML.
form Sets a custom form for the popup. Defaults to an email input and a submit button.
img.src Sets the path for the image.
img.alt Sets an alternate text for the image.
img.width Sets the width of the image.
img.height Sets the height of the image.