Newsletter Popup
Promote newsletter subscriptions with a popup
npm run add NewsletterPopupUse 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.
---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><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:
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:
<NewsletterPopup ... form={[ { type: 'group', fields: [ { type: 'text', placeholder: 'Name', name: 'name' }, { type: 'email', placeholder: 'Email', name: 'email' } ] }, { type: 'button', label: 'Join', theme: 'success' } ]}/>onChange, onSubmit and onError calls inside the component. API
type NewsletterCardProps = { heading?: string text?: string form?: FormField[] img: { src: string alt: string width: number height: number }} & ModalProps| Prop | Purpose |
|---|---|
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. |