Settings

A settings page with sections, fields and a save bar.

Workspace

Changes here apply to everyone once you save them.

Profile

northwind.example/… Try “acme” to see a refusal.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/settings

Usage

import { SettingsBody, type SettingsSaveState, SettingsSaveBar, SettingsSection } from "./ui/uicontext/components/kit/Settings.ts"
export const ProfileSettings = <M, C extends View.Children<M>>(	h: Html.H<M>,	fields: C,	save: { readonly state: SettingsSaveState; readonly changes: number; readonly onSave: M; readonly onDiscard: M },) =>	SettingsBody(h, {		title: "Profile",		children: [			SettingsSection(h, { title: "About you", card: "padded", children: fields }),			SettingsSaveBar(h, save),		],	})

API reference

SettingsBodyView function

Options

SettingsBody options
NameTypeDescription
titlerequiredstringThe page's title: "Notifications"
leadstringA sentence under the title about what the page sets
widebooleanA wider column, for tables of members or keys
childrenrequiredView.ChildrenThe page's sections

SettingsSectionView function

Options

SettingsSection options
NameTypeDefaultDescription
titlerequiredstring—The section's heading, which also names it for screen readers
descriptionstring—A sentence under the heading
asideView.Children—Content beside the heading, such as a button
card"plain" | "padded" | "flush" | falseplainThe frame around the children: plain by default; false leaves them unframed
styleStyle—Extra StyleX styles for the section
childrenrequiredView.Children—The section's rows or fields

SettingsSaveBarView function

Options

SettingsSaveBar options
NameTypeDescription
staterequired"clean" | "dirty" | "saving" | "saved" | "failed"—
changesnumberHow many settings changed, to say so: "3 unsaved changes"
errorstringWhy the save was refused, with what to do: "The name is taken. Choose another."
onSaverequiredMessage—
onDiscardrequiredMessage—
saveLabelstring"Save changes" by default

Accessibility

  • The page title is the page's h1, and each section is a region named by its heading.
  • Sections hold native controls, so they keep the browser's keyboard and form behavior.

Source