Settings form block
Settings sections of switches and selects, each in a fieldset.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsbeta
- Built on native elements
- Each section is a fieldset with a legend, so grouped controls are announced with it.
- Switches have role=switch with visible labels; hints are linked with aria-describedby.
- Selects are native and labelled.
- Styles in one file:
form.css
Import
import '@monoline/css';
import {BlockSettingsForm} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add block-settings-form
Usage
import {BlockSettingsForm} from '@monoline/react';
<BlockSettingsForm
title="Settings"
description="Changes apply to your account."
sections={[
{legend: 'Notifications', description: 'Choose what we email you.', items: [
{kind: 'switch', name: 'product', label: 'Product updates', hint: 'About once a month.', defaultChecked: true},
{kind: 'switch', name: 'digest', label: 'Weekly digest'},
]},
{legend: 'Display', items: [
{kind: 'select', name: 'theme', label: 'Theme', options: [{value: 'warm', label: 'Warm'}, {value: 'dark', label: 'Dark'}, {value: 'midnight', label: 'Midnight'}], defaultValue: 'warm'},
{kind: 'select', name: 'density', label: 'Density', hint: 'Compact fits more rows.', options: [{value: 'comfortable', label: 'Comfortable'}, {value: 'compact', label: 'Compact'}]},
]},
]}
/>
Examples
Account settings
Props
BlockSettingsFormProps
| Prop | Type | Default | Description |
|---|---|---|---|
title required | ReactNode | – | Heading of the settings page. |
description | ReactNode | – | Optional muted line under the heading. |
sections required | SettingsSection[] | – | The groups of settings; each has a `legend`, optional `description` and a list of switch or select `items`. |
saveLabel | ReactNode | 'Save changes' | Text of the submit button. Default "Save changes". |
resetLabel | ReactNode | 'Reset' | Text of the button that restores the initial values. Default "Reset". |
onSubmit | ((values: Record<string, string | boolean>) => void) | – | Called with every control's value: switches are `true` or `false`, selects their value. |
loading | boolean | – | Shows a spinner on the save button while you save. |
headingLevel | 1 | 2 | 3 | 1 | Outline level of the title, 1 to 3. Default 1. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-invalid="true"] | checkbox.css |
[data-orientation="horizontal"] | checkbox.css |
[data-state="checked"] | checkbox.css |
[data-state="indeterminate"] | checkbox.css |
[aria-checked="true"] | 03-form-fields.css |
[aria-invalid="true"] | 03-form-fields.css |
[aria-pressed="true"] | 03-form-fields.css |
[data-valid="true"] | 11-field-states.css |
CSS classes
| Class | Stylesheet |
|---|---|
.form | form.css |
.form-actions | form.css |
.form-errors | form.css |
.form-errors-title | form.css |
.fieldset | fieldset.css |
.fieldset-legend | fieldset.css |
.checkbox | checkbox.css |
.checkbox-mark | checkbox.css |
.radio | checkbox.css |
.radio-dot | checkbox.css |
.radio-group | checkbox.css |
.sw | checkbox.css |
.sw-thumb | checkbox.css |
.choice | 10-choices.css |
.choice-group | 10-choices.css |
.field | 03-form-fields.css |
.field-hint | 03-form-fields.css |
.input | 03-form-fields.css |
.input-bare | 03-form-fields.css |
.input-end | 03-form-fields.css |
.input-lg | 03-form-fields.css |
.input-sm | 03-form-fields.css |
.input-wrap | 03-form-fields.css |
.muted | 03-form-fields.css |
.seg | 03-form-fields.css |
.seg-opt | 03-form-fields.css |
.select | 03-form-fields.css |
.setting | 03-form-fields.css |
.switch | 03-form-fields.css |
.textarea | 03-form-fields.css |
.field-error | 11-field-states.css |
.field-ok | 11-field-states.css |
.field-required | 11-field-states.css |
.form-row | 11-field-states.css |
.input | 11-field-states.css |
.input-affix | 11-field-states.css |
.input-group | 11-field-states.css |
.select | 11-field-states.css |
.textarea | 11-field-states.css |
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.skeleton | 13-loading.css |
.skeleton-block | 13-loading.css |
.skeleton-hatch | 13-loading.css |
.spinner | 13-loading.css |
.heading | heading.css |
.heading-display | heading.css |
.heading-lg | heading.css |
.heading-md | heading.css |
.heading-sm | heading.css |
.heading-xl | heading.css |
.text | text.css |
.text-accent | text.css |
.text-danger | text.css |
.text-full | text.css |
.text-lg | text.css |
.text-md | text.css |
.text-muted | text.css |
.text-ok | text.css |
.text-sm | text.css |
.text-success | text.css |
.text-truncate | text.css |
.text-warning | text.css |
.text-xs | text.css |
.block-settings | block-settings-form.css |
.block-settings-head | block-settings-form.css |
.block-settings-row | block-settings-form.css |
.field-hint | block-settings-form.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.form {
border-color: var(--accent);
}
.form[aria-invalid="true"] {
background: var(--wash);
}
Accessibility
- Each section is a fieldset with a legend, so grouped controls are announced with it.
- Switches have role=switch with visible labels; hints are linked with aria-describedby.
- Selects are native and labelled.