@molecule/app-newsletter-signup-vue

Feature · newsletter-signup · App (browser) · v1.1.3 · Apache-2.0

Email + subscribe button with success state for newsletter capture

npm install @molecule/app-newsletter-signup-vue

npm · Source on GitHub

How it works

@molecule/app-newsletter-signup-vue 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.

import { defineComponent, h, ref } from 'vue'
import { NewsletterSignup } from '@molecule/app-newsletter-signup-vue'

const Subscribe = defineComponent({
  setup() {
    const subscribe = async (email: string): Promise<void> => {
      await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }) })
    }
    return () =>
      h(
        NewsletterSignup,
        {
          title: 'Stay in the loop',
          description: 'Get weekly updates delivered to your inbox.',
          layout: 'inline',
          onSubscribe: subscribe,
        },
        { successContent: () => [h('p', 'Thanks for subscribing!')] },
      )
  },
})

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue email subscribe form.

Exports <NewsletterSignup> with inline + stacked layouts. Tracks its own submitting / error / success state; the app owns the subscription side-effect via onSubscribe. It is the Vue counterpart of @molecule/app-newsletter-signup-react: same props (React names) and the same DOM for the same input.

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.ts JSDoc, not this file.

Quick Start

import { defineComponent, h, ref } from 'vue'
import { NewsletterSignup } from '@molecule/app-newsletter-signup-vue'

const Subscribe = defineComponent({
  setup() {
    const subscribe = async (email: string): Promise<void> => {
      await fetch('/api/subscribe', { method: 'POST', body: JSON.stringify({ email }) })
    }
    return () =>
      h(
        NewsletterSignup,
        {
          title: 'Stay in the loop',
          description: 'Get weekly updates delivered to your inbox.',
          layout: 'inline',
          onSubscribe: subscribe,
        },
        { successContent: () => [h('p', 'Thanks for subscribing!')] },
      )
  },
})

Type

feature

Installation

npm install @molecule/app-newsletter-signup-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

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. Passed as a prop or as the same-named slot. */
  title?: VNodeChild
  /** Optional supporting copy under the title. Passed as a prop or as the same-named slot. */
  description?: VNodeChild
  /** Placeholder for the email input. */
  placeholder?: string
  /** Submit-button label. Passed as a prop or as the same-named slot. */
  buttonLabel?: VNodeChild
  /** Rendered after successful subscription. Passed as a prop or as the same-named slot. */
  successContent?: VNodeChild
  /** Layout — `'inline'` default (input + button on one row) or `'stacked'`. */
  layout?: 'inline' | 'stacked'
  /** Extra classes. */
  className?: string
}

Constants

NewsletterSignup

Email + subscribe button widget. Tracks its own submitting/error/success state. Apps own the actual subscription side-effect via onSubscribe.

Always pass successContent — without it a successful submit only clears the input and re-renders the empty form. 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.

const NewsletterSignup: DefineComponent<
  ExtractPropTypes<{
    onSubscribe: { type: PropType<(email: string) => void | Promise<void>>; required: true }
    title: null
    description: null
    placeholder: StringConstructor
    buttonLabel: null
    successContent: null
    layout: { type: PropType<'inline' | 'stacked'>; default: string }
    className: StringConstructor
  }>,
  () => VNodeChild,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      onSubscribe: { type: PropType<(email: string) => void | Promise<void>>; required: true }
      title: null
      description: null
      placeholder: StringConstructor
      buttonLabel: null
      successContent: null
      layout: { type: PropType<'inline' | 'stacked'>; default: string }
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { layout: 'inline' | 'stacked' },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see NewsletterSignupProps).

Returns: The newsletter signup form component.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.13.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui
  • @molecule/app-ui-vue
  • @molecule/app-vue
  • vue

Requires a wired ClassMap bond and the Vue binding'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. Node-valued props arrive as a prop AND a same-named slot; components accept either.

Translations

Translation strings are provided by @molecule/app-locales-newsletter-signup.