{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings",
  "type": "registry:block",
  "title": "Settings block",
  "description": "An account's settings as one screen: the profile, the notifications and the appearance, Save and Cancel, and deleting the studio apart behind a slide to confirm. A failed save puts a summary on top that takes focus, and a good one ends in a toast.",
  "registryDependencies": [
    "https://littmd.vercel.app/r/litt.json",
    "https://littmd.vercel.app/r/button.json",
    "https://littmd.vercel.app/r/form.json",
    "https://littmd.vercel.app/r/framed.json",
    "https://littmd.vercel.app/r/input.json",
    "https://littmd.vercel.app/r/segmented.json",
    "https://littmd.vercel.app/r/select.json",
    "https://littmd.vercel.app/r/slide-confirm.json",
    "https://littmd.vercel.app/r/slider.json",
    "https://littmd.vercel.app/r/switch.json",
    "https://littmd.vercel.app/r/toast.json"
  ],
  "files": [
    {
      "path": "registry/litt/components/litt-blocks/settings.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n// @litt/settings 2026.11.03. What changed: https://littmd.vercel.app/changelog.md\n\n/**\n * Settings: an account's settings page. A block: a whole screen built from the litt parts, to copy and make your own.\n * Swap the saved values at the top for your user's, and `save` for your request; the sections and their words stay.\n *\n * One left-aligned column of sections: the profile, what we email you about, and how the app looks to you, then Save\n * and Cancel. From 1024 up each section's title takes the left third. A failed save puts a summary on top that takes\n * focus, and a good one ends in a toast. Deleting the studio sits apart, after a hairline, behind a slide to confirm.\n * Save is the one accent fill. Render it inside your app's shell (the dashboard block's AppShell, for one), and mount\n * the Toaster once near your root so the saved toast shows.\n */\nimport { useEffect, useId, useRef, useState, type ChangeEvent } from \"react\";\nimport { Button } from \"../litt/button\";\nimport { ErrorSummary, Fieldset, FormActions, FormSection, type FormError } from \"../litt/form\";\nimport { TextField } from \"../litt/input\";\nimport { Segmented } from \"../litt/segmented\";\nimport { SelectField } from \"../litt/select\";\nimport { SlideConfirm } from \"../litt/slide-confirm\";\nimport { Slider } from \"../litt/slider\";\nimport { Switch } from \"../litt/switch\";\nimport { toast } from \"../litt/toast\";\nimport { Heading } from \"../litt/framed\";\n\n/* ----------------------------------------------------------------- data */\n\ntype Values = {\n  name: string;\n  email: string;\n  role: string;\n  builds: boolean;\n  digest: boolean;\n  theme: string;\n  speed: number;\n};\n\n/** What is saved now. Load yours from your user. */\nconst SAVED: Values = {\n  name: \"Ines Ortega\",\n  email: \"ines@halo.studio\",\n  role: \"designer\",\n  builds: true,\n  digest: false,\n  theme: \"system\",\n  speed: 1,\n};\n\nconst ROLES = [\n  { value: \"designer\", label: \"Designer\" },\n  { value: \"developer\", label: \"Developer\" },\n  { value: \"producer\", label: \"Producer\" },\n  { value: \"lead\", label: \"Studio lead\" },\n];\n\nconst STUDIO = \"Halo Studio\";\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\ntype Ids = { name: string; email: string };\n\n/** What is wrong with the fields, in the order they appear, linked to the ids the summary moves focus to. */\nfunction check(v: Values, ids: Ids): FormError[] {\n  const errors: FormError[] = [];\n  if (!v.name.trim()) errors.push({ id: ids.name, message: \"Enter your name.\" });\n  if (!EMAIL.test(v.email.trim())) errors.push({ id: ids.email, message: \"Use a full address, like ines@halo.studio.\" });\n  return errors;\n}\n\n/**\n * Pretends to save for a moment, then runs onSaved. Await your request here instead.\n */\nfunction useSave(onSaved: () => void) {\n  const [saving, setSaving] = useState(false);\n  const timer = useRef(0);\n\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const save = () => {\n    setSaving(true);\n    timer.current = window.setTimeout(() => {\n      setSaving(false);\n      onSaved();\n    }, 1200);\n  };\n  return { saving, save };\n}\n\n/* ----------------------------------------------------------------- the screen */\n\nexport function Settings() {\n  /* Ids of its own, so two of these on a page never send the summary's links to the other one. */\n  const uid = useId();\n  const ids: Ids = { name: `${uid}-name`, email: `${uid}-email` };\n  const [saved, setSaved] = useState(SAVED);\n  const [values, setValues] = useState(SAVED);\n  const [errors, setErrors] = useState<FormError[]>([]);\n  const [failedSaves, setFailedSaves] = useState(0);\n  const { saving, save } = useSave(() => {\n    setSaved(values);\n    toast({ title: \"Settings saved\", description: \"Your profile is up to date.\", tone: \"success\" });\n  });\n\n  /* A change to one setting that keeps the rest. A field that was wrong is checked again as you type. */\n  const set =\n    <K extends keyof Values>(key: K) =>\n    (value: Values[K]) => {\n      const next = { ...values, [key]: value };\n      setValues(next);\n      if (errors.length) setErrors(check(next, ids));\n    };\n  const text = (key: \"name\" | \"email\") => ({\n    id: ids[key],\n    value: values[key],\n    error: errors.find((e) => e.id === ids[key])?.message,\n    onChange: (e: ChangeEvent<HTMLInputElement>) => set(key)(e.target.value),\n  });\n\n  return (\n    <div className=\"@container grid w-full max-w-3xl grid-cols-1 gap-12\">\n      <header className=\"grid gap-1\">\n        <Heading level={1} className=\"text-litt-h1 text-litt-fg\">Settings</Heading>\n        <p className=\"text-litt-body text-litt-fg-muted\">Your profile, your email and how {STUDIO} looks to you.</p>\n      </header>\n\n      <form\n        noValidate\n        aria-label=\"Account settings\"\n        onSubmit={(e) => {\n          e.preventDefault();\n          if (saving) return;\n          const found = check(values, ids);\n          setErrors(found);\n          if (found.length) return setFailedSaves((n) => n + 1);\n          save();\n        }}\n      >\n        {/* With errors, the summary comes first, and Profile takes the 48px and the hairline every later section has. */}\n        <ErrorSummary errors={errors} focusKey={failedSaves} />\n\n        <FormSection title=\"Profile\" description=\"Shown to the clients you invite to a project.\">\n          <TextField label=\"Name\" autoComplete=\"name\" {...text(\"name\")} />\n          <TextField label=\"Email\" type=\"email\" inputMode=\"email\" autoComplete=\"email\" {...text(\"email\")} />\n          <SelectField label=\"Role\" name=\"role\" value={values.role} onValueChange={set(\"role\")} options={ROLES} />\n        </FormSection>\n\n        <FormSection title=\"Notifications\" description=\"What we email you about. Each switch takes effect when you save.\">\n          {/* rows: the switches sit flush as one list, with hairlines between them. */}\n          <Fieldset legend=\"Email\" rows>\n            <Switch align=\"end\" name=\"builds\" label=\"Email me when a build finishes\" checked={values.builds} onCheckedChange={set(\"builds\")} />\n            <Switch\n              align=\"end\"\n              name=\"digest\"\n              label=\"Weekly digest\"\n              description=\"A Monday email with visits and deploys.\"\n              checked={values.digest}\n              onCheckedChange={set(\"digest\")}\n            />\n          </Fieldset>\n        </FormSection>\n\n        <FormSection title=\"Appearance\" description=\"How the app looks to you. It does not change what clients see.\">\n          <Segmented\n            legend=\"Theme\"\n            showLegend\n            value={values.theme}\n            onValueChange={set(\"theme\")}\n            options={[\n              { value: \"system\", label: \"System\" },\n              { value: \"light\", label: \"Light\" },\n              { value: \"dark\", label: \"Dark\" },\n            ]}\n          />\n          <Slider\n            label=\"Animation speed\"\n            name=\"speed\"\n            min={0.5}\n            max={2}\n            step={0.1}\n            value={values.speed}\n            onValueChange={set(\"speed\")}\n            minLabel=\"Slower\"\n            maxLabel=\"Faster\"\n            showValue\n            formatValue={(v) => `${v.toFixed(1)}x`}\n          />\n        </FormSection>\n\n        <FormActions align=\"fields\" className=\"mt-12\">\n          <Button type=\"submit\" variant=\"primary\" loading={saving}>\n            Save changes\n          </Button>\n          <Button\n            variant=\"ghost\"\n            disabled={saving}\n            onClick={() => {\n              setValues(saved);\n              setErrors([]);\n            }}\n          >\n            Cancel\n          </Button>\n        </FormActions>\n      </form>\n\n      {/* Apart from the form: it is not saved with it, and a slide is harder to do by accident than a press. */}\n      <div className=\"border-t border-litt-line pt-12\">\n        <FormSection title=\"Delete studio\" description={`Removes ${STUDIO}, its projects and every deploy. This cannot be undone.`}>\n          <SlideConfirm\n            label={`Slide to delete ${STUDIO}`}\n            confirmedLabel=\"Studio deleted\"\n            confirmText={STUDIO}\n            onConfirm={() => toast({ title: `${STUDIO} deleted`, description: \"Its projects and deploys are gone.\", tone: \"neutral\" })}\n          />\n        </FormSection>\n      </div>\n    </div>\n  );\n}\n",
      "target": "components/litt-blocks/settings.tsx"
    }
  ],
  "docs": "Import Settings from components/litt-blocks/settings and render it inside your app's shell, with the Toaster mounted once near your root. The saved values sit at the top of the file, and useSave stands in for your request. See it live at https://littmd.vercel.app/#settings.",
  "meta": {
    "version": "2026.11.03",
    "released": "2026-11-03",
    "changelog": "https://littmd.vercel.app/changelog.md"
  }
}
