Playground

Settings form block

Settings sections of switches and selects, each in a fieldset.

  • 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

PropTypeDefaultDescription
title requiredReactNode–Heading of the settings page.
descriptionReactNode–Optional muted line under the heading.
sections requiredSettingsSection[]–The groups of settings; each has a `legend`, optional `description` and a list of switch or select `items`.
saveLabelReactNode'Save changes'Text of the submit button. Default "Save changes".
resetLabelReactNode'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.
loadingboolean–Shows a spinner on the save button while you save.
headingLevel1 | 2 | 31Outline 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.

AttributeStylesheet
[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

ClassStylesheet
.formform.css
.form-actionsform.css
.form-errorsform.css
.form-errors-titleform.css
.fieldsetfieldset.css
.fieldset-legendfieldset.css
.checkboxcheckbox.css
.checkbox-markcheckbox.css
.radiocheckbox.css
.radio-dotcheckbox.css
.radio-groupcheckbox.css
.swcheckbox.css
.sw-thumbcheckbox.css
.choice10-choices.css
.choice-group10-choices.css
.field03-form-fields.css
.field-hint03-form-fields.css
.input03-form-fields.css
.input-bare03-form-fields.css
.input-end03-form-fields.css
.input-lg03-form-fields.css
.input-sm03-form-fields.css
.input-wrap03-form-fields.css
.muted03-form-fields.css
.seg03-form-fields.css
.seg-opt03-form-fields.css
.select03-form-fields.css
.setting03-form-fields.css
.switch03-form-fields.css
.textarea03-form-fields.css
.field-error11-field-states.css
.field-ok11-field-states.css
.field-required11-field-states.css
.form-row11-field-states.css
.input11-field-states.css
.input-affix11-field-states.css
.input-group11-field-states.css
.select11-field-states.css
.textarea11-field-states.css
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.skeleton13-loading.css
.skeleton-block13-loading.css
.skeleton-hatch13-loading.css
.spinner13-loading.css
.headingheading.css
.heading-displayheading.css
.heading-lgheading.css
.heading-mdheading.css
.heading-smheading.css
.heading-xlheading.css
.texttext.css
.text-accenttext.css
.text-dangertext.css
.text-fulltext.css
.text-lgtext.css
.text-mdtext.css
.text-mutedtext.css
.text-oktext.css
.text-smtext.css
.text-successtext.css
.text-truncatetext.css
.text-warningtext.css
.text-xstext.css
.block-settingsblock-settings-form.css
.block-settings-headblock-settings-form.css
.block-settings-rowblock-settings-form.css
.field-hintblock-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.