SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

NewsletterForm

A blog's sign-up form as composable parts.

View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
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.

  • NewsletterForm
  • NewsletterForm.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 whatever htmlFor says.
  • NewsletterForm.InputThe required email control the form posts, named email and filled in by the browser's saved address; set name or placeholder to 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.

PropTypeDefaultRequiredDescription
actionstring—YesThe 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

PropTypeDefaultRequiredDescription
colorInput.Color—NoThe focus ring's colour role.

Also accepts everything in Omit<TagProps<"input">, "type" | "role">.

NewsletterForm.Submit

Also accepts everything in Button.Props.

@sdxc/ui

Can’t find it? Contact us