FormRow
One setting per row: what it is called and what it does on one side, its control on the other. The rows make a list with lines between them; on phones the control goes below the text.
import { FormRow, Switch, NativeSelect, Input } from '@sypnia/ui/react'
Account settings
On a phone, each control takes the full width under its text.
Public sign-ups
Anyone with the link can create an account. Turn it off to invite people one by one.
How long someone stays signed in without using the app.
Only emails at this domain can join.
Delete project
Removes the database, the files and the logs. This cannot be undone.
Code
import { Button, FormRow, Input, NativeSelect, Panel, Switch } from '@sypnia/ui/react';
// One setting per row: what it does on the left, the control on the right. On a phone the control goes below.
export default function SettingsList() {
return (
<Panel>
<FormRow label="Public sign-ups" description="Anyone with the link can create an account. Turn it off to invite people one by one.">
<Switch label="Allow" defaultChecked />
</FormRow>
<FormRow label="Session length" description="How long someone stays signed in without using the app." htmlFor="session">
<NativeSelect id="session" defaultValue="7d"><option value="1d">1 day</option><option value="7d">7 days</option><option value="30d">30 days</option></NativeSelect>
</FormRow>
<FormRow label="Allowed domain" description="Only emails at this domain can join." htmlFor="domain">
<Input id="domain" machine defaultValue="northwind.io" />
</FormRow>
<FormRow label="Delete project" description="Removes the database, the files and the logs. This cannot be undone." danger>
<Button variant="danger" icon="trash">Delete project</Button>
</FormRow>
</Panel>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
How long someone stays signed in without using the app.
Session length
How long someone stays signed in without using the app.
Code
import { FormRow, FormRowSkeleton, NativeSelect, Panel } from '@sypnia/ui/react';
// The real row, the row with `loading` (its words are known, its value is not) and the skeleton.
export default function Skeleton() {
return (
<Panel>
<FormRow label="Session length" description="How long someone stays signed in without using the app." htmlFor="len">
<NativeSelect id="len" defaultValue="7d"><option value="7d">7 days</option></NativeSelect>
</FormRow>
<FormRow label="Session length" description="How long someone stays signed in without using the app." loading />
<FormRowSkeleton />
</Panel>
);
} When to use it
Use it when
- Settings that apply as soon as they change, or a list of settings saved with a SaveBar.
- Say what changes for the person in the description, in a sentence: «Anyone with the link can create an account».
Do not use it when
- Forms someone fills in from top to bottom: use Field so the label sits above the control.
- Long controls such as a Textarea: they need the full width.
For everyone
- Give the control an
idand the rowhtmlForso the setting's name is its label. - Without
htmlFor, the control area is a group named by the setting, for switches and buttons that already name themselves. - Rows marked
dangeruse colour and words: the description says what is lost.
Props
| FormRow | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
danger | boolean | |
description | ReactNode | |
htmlFor | string | |
loadingThe setting's value is on its way: the text stays and the control (`children`, when given) is drawn as a skeleton of its own box; without children, a skeleton of a control's height. | boolean |
| Switch | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
description | ReactNode |
| NativeSelect | Type | Default |
|---|---|---|
size | "sm" | "md" | "lg" |
| Input | Type | Default |
|---|---|---|
machineMachine text (ids, keys, code): set in the mono face. | boolean | |
size | "sm" | "md" | "lg" |