@molecule/app-newsletter-signup-svelte
Feature · newsletter-signup · App (browser) · v1.1.4 · Apache-2.0
Email + subscribe button with success state for newsletter capture
npm install @molecule/app-newsletter-signup-svelteHow it works
@molecule/app-newsletter-signup-svelte is a ready-made newsletter-signup feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { NewsletterSignup } from '@molecule/app-newsletter-signup-svelte'
async function subscribe(email: string): Promise<void> {
await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }) })
}
</script>
<NewsletterSignup
title="Stay in the loop"
description="Get weekly updates delivered to your inbox."
layout="inline"
onSubscribe={subscribe}
>
{#snippet successContent()}
<p>Thanks for subscribing!</p>
{/snippet}
</NewsletterSignup>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte email subscribe form — the Svelte counterpart of
@molecule/app-newsletter-signup-react, with the same props and the same
DOM for the same input.
Exports NewsletterSignup — email field + subscribe button with inline /
stacked layouts. It tracks its own submitting / error / success state; the
app owns the subscription side-effect via onSubscribe.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { NewsletterSignup } from '@molecule/app-newsletter-signup-svelte'
async function subscribe(email: string): Promise<void> {
await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }) })
}
</script>
<NewsletterSignup
title="Stay in the loop"
description="Get weekly updates delivered to your inbox."
layout="inline"
onSubscribe={subscribe}
>
{#snippet successContent()}
<p>Thanks for subscribing!</p>
{/snippet}
</NewsletterSignup>
Type
feature
Installation
npm install @molecule/app-newsletter-signup-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
NewsletterSignupProps
Props for NewsletterSignup — the same props (React names) as @molecule/app-newsletter-signup-react.
interface NewsletterSignupProps {
/** Called with the email on submit. Return a Promise to block double-submit. */
onSubscribe: (email: string) => void | Promise<void>
/** Optional title above the form — a snippet or a plain string. */
title?: Snippet | string
/** Optional supporting copy under the title — a snippet or a plain string. */
description?: Snippet | string
/** Placeholder for the email input. */
placeholder?: string
/** Submit-button label — a snippet or a plain string. */
buttonLabel?: Snippet | string
/** Rendered after successful subscription — a snippet or a plain string. */
successContent?: Snippet | string
/** Layout — `'inline'` default (input + button on one row) or `'stacked'`. */
layout?: 'inline' | 'stacked'
/** Extra classes. */
className?: string
}
Constants
NewsletterSignup
const NewsletterSignup: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.13.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
Requires a wired ClassMap bond and @molecule/app-svelte's i18n provider
above it — getClassMap() and useTranslation() both throw before wiring.
Pair with @molecule/app-locales-newsletter-signup for the placeholder /
button / label / error strings in 79 languages.
ALWAYS pass successContent — without it a successful submit only clears
the input and re-renders the empty form (no built-in "thanks" message).
Return a Promise from onSubscribe so double-submits are blocked while in
flight; a rejected Promise renders the error's message verbatim below the
form, so throw user-readable (ideally pre-translated) messages.
Translations
Translation strings are provided by @molecule/app-locales-newsletter-signup.