FormSection
Splits a long form into parts with a title and a sentence that says what the fields are for. The title sits on the left on wide screens and on top on tablets and phones.
import { FormSection, Field } from '@sypnia/ui/react'
A settings page in two parts
Narrow the window: under tablet width the title goes on top.
General
How the project is called and where its data lives.
It cannot be changed after the project is created.
Backups
Copies of the database, kept for the days you choose.
Code
import { Field, FormSection, Input, NativeSelect, Switch } from '@sypnia/ui/react';
// A long form in parts: each section says what its fields are for. On tablets and phones the title goes on top.
export default function Settings() {
return (
<div className="sy-form">
<FormSection title="General" description="How the project is called and where its data lives.">
<Field label="Project name"><Input defaultValue="Storefront" /></Field>
<Field label="Region" hint="It cannot be changed after the project is created.">
<NativeSelect defaultValue="eu" disabled><option value="eu">Frankfurt</option></NativeSelect>
</Field>
</FormSection>
<FormSection title="Backups" description="Copies of the database, kept for the days you choose.">
<Switch label="Daily backup" description="Runs at 03:00 in the project's time zone." defaultChecked />
<Field label="Keep for (days)"><Input defaultValue="7" inputMode="numeric" /></Field>
</FormSection>
</div>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
General
How the project is called.
Backups
Copies of the database, kept for the days you choose.
Code
import { Field, FormSection, FormSectionSkeleton, Input } from '@sypnia/ui/react';
// With `loading` the title stays and the fields wait; FormSectionSkeleton is for when nothing is known yet.
export default function Skeleton() {
return (
<div className="sy-form">
<FormSection title="General" description="How the project is called."><Field label="Project name"><Input defaultValue="Storefront" /></Field></FormSection>
<FormSection title="Backups" description="Copies of the database, kept for the days you choose." loading fields={1} />
<FormSectionSkeleton fields={1} />
</div>
);
} When to use it
Use it when
- Settings pages and long forms with groups of fields that belong together.
- Write the description as what the person gets, not as what the fields are: «Copies of the database, kept for the days you choose».
Do not use it when
- Forms of three or four fields: a title per field is noise.
- Grouping choices that answer one question: that is a Fieldset with a legend.
For everyone
- Each section is a region named by its title, so it can be reached from the landmarks list.
- The title is a level-2 heading; put the page title in a PageHeader above.
Props
| FormSection | Type | Default |
|---|---|---|
titlerequired | ReactNode | |
className | string | |
description | ReactNode | |
fieldsHow many field skeletons to show while loading. | number | 2 |
loadingThe values are on their way: the title stays and the fields are skeletons. | boolean |
| Field | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
className | string | |
errorWhat is wrong and how to fix it. Its presence marks the control as invalid. | ReactNode | |
hintHelp that is always visible: what to write, in what format. | ReactNode | |
optionalAdds «optional» beside the label. Required is the default and is not marked. | boolean | |
wideSpans both columns of a FormGrid. | boolean |