NewsletterForm
A blog's sign-up form as composable parts.
View code
<NewsletterForm action="/subscribe">
<NewsletterForm.Field>
<NewsletterForm.Label>Email address</NewsletterForm.Label>
<NewsletterForm.Input />
</NewsletterForm.Field>
<NewsletterForm.Submit>Subscribe</NewsletterForm.Submit>
</NewsletterForm>
{/* In a narrow sidebar the button drops below the field */}
<NewsletterForm action="/subscribe">
<NewsletterForm.Field>
<NewsletterForm.Label>Get the monthly letter</NewsletterForm.Label>
<NewsletterForm.Input />
</NewsletterForm.Field>
<NewsletterForm.Submit>Send it to me</NewsletterForm.Submit>
</NewsletterForm>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { NewsletterForm } from "@sdxc/ui/blog";Renders a method="post" form laying out its parts in a wrapping row: the
NewsletterForm.Field fills the row beside the NewsletterForm.Submit, and
once the pair no longer fits, the button drops below and spans the form. The server answers
the post with its own confirmation page, so the form works with script off.
Composition
The parts the component publishes, each a static property of the host.
NewsletterFormNewsletterForm.FieldThe label and its control stacked, taking the row's free width beside the button down to a shared minimum, past which the row wraps.NewsletterForm.LabelThe field's visible label, tied to the form's email control; inside a NewsletterForm it points at the form's control whateverhtmlForsays.NewsletterForm.InputThe required email control the form posts, namedemailand filled in by the browser's saved address; setnameorplaceholderto change either.NewsletterForm.SubmitThe form's submit button in the brand colour, growing to fill its line once it wraps below the field.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
action | string | — | Yes | The blog's sign-up address, which the form posts to. |
Also accepts everything in Omit<TagProps<"form">, "method" | "action">.
NewsletterForm.Field
Also accepts everything in TagProps<"div">.
NewsletterForm.Label
Also accepts everything in Label.Props.
NewsletterForm.Input
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
color | Input.Color | — | No | The focus ring's colour role. |
Also accepts everything in Omit<TagProps<"input">, "type" | "role">.
NewsletterForm.Submit
Also accepts everything in Button.Props.