@molecule/app-contact-form-svelte

Feature · contact-form · App (browser) · v1.1.4 · Apache-2.0

Generic name + email + message form with submit handler

npm install @molecule/app-contact-form-svelte

npm · Source on GitHub

How it works

@molecule/app-contact-form-svelte is a ready-made contact-form 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 { ContactForm } from '@molecule/app-contact-form-svelte'

  async function send(values: { name: string; email: string; message: string }) {
    await api.sendContactMessage(values)
  }
</script>

<ContactForm
  title="Get in touch"
  description="We'll respond within one business day."
  onSubmit={send}
>
  {#snippet successContent()}
    <p>Thanks! We'll be in touch soon.</p>
  {/snippet}
</ContactForm>

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

Reference

Svelte generic contact form — the Svelte counterpart of @molecule/app-contact-form-react, with the same props and the same DOM for the same input.

Exports <ContactForm> and the ContactFormValues type: name + email + message fields with submit handling and success state, plus an extraFields slot for app-specific inputs.

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

<script lang="ts">
  import { ContactForm } from '@molecule/app-contact-form-svelte'

  async function send(values: { name: string; email: string; message: string }) {
    await api.sendContactMessage(values)
  }
</script>

<ContactForm
  title="Get in touch"
  description="We'll respond within one business day."
  onSubmit={send}
>
  {#snippet successContent()}
    <p>Thanks! We'll be in touch soon.</p>
  {/snippet}
</ContactForm>

Type

feature

Installation

npm install @molecule/app-contact-form-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

ContactFormValues

Shape of values collected by the contact form and passed to onSubmit.

interface ContactFormValues {
  name: string
  email: string
  message: string
  /** App-supplied additional fields. */
  [key: string]: string
}

ContactFormProps

Props for ContactForm — the same props (React names) as @molecule/app-contact-form-react.

interface ContactFormProps {
  /** Called with the form values on submit. Return a Promise to block double-submit. */
  onSubmit: (values: ContactFormValues) => void | Promise<void>
  /** Form heading — a snippet or a plain string. */
  title?: Snippet | string
  /** Optional supporting copy under the heading — a snippet or a plain string. */
  description?: Snippet | string
  /** Custom submit-button label — a snippet or a plain string. */
  submitLabel?: Snippet | string
  /** Rendered when the form successfully submits — a snippet or a plain string. */
  successContent?: Snippet | string
  /** Extra fields rendered above the message textarea — a snippet or a plain string. */
  extraFields?: Snippet | string
  /** Extra classes. */
  className?: string
}

Constants

ContactForm

const ContactForm: 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.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte
  • @molecule/app-ui
  • @molecule/app-ui-svelte
  • svelte

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-contact-form for the placeholder / button strings in 79 languages.

onSubmit receives ONLY { name, email, message } — inputs rendered via the extraFields snippet are displayed but NOT collected; own their state in the parent and merge them inside your onSubmit. Always pass successContent: without it the form clears silently after a successful submit. If onSubmit rejects, the thrown Error.message is shown verbatim below the form — throw translated, user-safe messages.

Translations

Translation strings are provided by @molecule/app-locales-contact-form.