{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-settings-profile",
  "type": "registry:block",
  "title": "App, profile settings",
  "description": "A profile form: photo, labelled fields with hints and autofill hints, save and cancel, and four states (idle; saving, which disables every field; saved; error, which marks and describes the flagged field). Never submits.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/avatar.json",
    "https://ui.klarhimmel.com/r/banner.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-app.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-settings-profile/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-settings-profile/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t, req } from '../_shared/schema';\n\nconst field = z.object({\n  label: req(40),\n  kind: z.enum(['text', 'email', 'textarea']),\n  /** What the field is filled with. Not editable copy: it is the sample content of the input. */\n  sample: t(300),\n  hint: t(120).optional(),\n  /** The browser's autofill hint for this field. */\n  autocomplete: z.enum(['name', 'given-name', 'family-name', 'email', 'tel', 'organization', 'organization-title', 'url', 'off']),\n  /** The field the error state marks (the first one with this set). */\n  invalid: z.boolean(),\n});\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  avatar: z.object({ name: t(40), change: req(30) }),\n  fields: z.array(field).min(2).max(6),\n  actions: z.object({ save: req(30), saving: t(30), cancel: req(30) }),\n  /** idle: nothing to say. saving: the button waits. saved: a confirmation. error: a banner and the email field marked. */\n  state: z.enum(['idle', 'saving', 'saved', 'error']),\n  messages: z.object({ saved: t(120), error: t(120), fieldError: t(120) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-settings-profile',\n  aliases: ['app/settings-profile'],\n  name: 'App, profile settings',\n  category: 'app',\n  role: 'body',\n  description: 'A profile form: photo, labelled fields with hints and autofill hints, save and cancel, and four states (idle; saving, which disables every field; saved; error, which marks and describes the flagged field). Never submits.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Settings\",\n    \"title\": \"Your profile\",\n    \"description\": \"Say who sees this information and where it appears.\",\n    \"avatar\": {\n      \"name\": \"Name a person\",\n      \"change\": \"Change photo\"\n    },\n    \"fields\": [\n      {\n        \"label\": \"Full name\",\n        \"kind\": \"text\",\n        \"sample\": \"Name a person\",\n        \"autocomplete\": \"name\",\n        \"invalid\": false\n      },\n      {\n        \"label\": \"Email\",\n        \"kind\": \"email\",\n        \"sample\": \"name@example.com\",\n        \"hint\": \"Say what is sent to this address.\",\n        \"autocomplete\": \"email\",\n        \"invalid\": true\n      },\n      {\n        \"label\": \"Role\",\n        \"kind\": \"text\",\n        \"sample\": \"Name their role\",\n        \"autocomplete\": \"organization-title\",\n        \"invalid\": false\n      },\n      {\n        \"label\": \"About you\",\n        \"kind\": \"textarea\",\n        \"sample\": \"Say in a sentence or two what they do and who they help.\",\n        \"hint\": \"Say how long it may be.\",\n        \"autocomplete\": \"off\",\n        \"invalid\": false\n      }\n    ],\n    \"actions\": {\n      \"save\": \"Save changes\",\n      \"saving\": \"Saving…\",\n      \"cancel\": \"Cancel\"\n    },\n    \"state\": \"idle\",\n    \"messages\": {\n      \"saved\": \"Say the changes are saved.\",\n      \"error\": \"Say it was not saved and which field to fix, then retry.\",\n      \"fieldError\": \"Say what is wrong with that field.\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-settings-profile/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-settings-profile/index.tsx",
      "content": "import { useId } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Avatar } from '../../ui/avatar';\nimport { Banner } from '../../ui/banner';\nimport { Button } from '../../ui/button';\nimport { Input, Textarea } from '../../ui/input';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { AppPanel, StateSlot } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppSettingsProfile({ props }: BlockProps<Props>) {\n  const id = useId();\n  const { state } = props;\n  const bad = Math.max(0, props.fields.findIndex((f) => f.invalid));\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-10\">\n          <form key={JSON.stringify(props.fields.map((f) => f.sample))} onSubmit={(e) => e.preventDefault()} aria-busy={state === 'saving' || undefined} className=\"flex flex-col gap-6 p-6 @xl:p-8\">\n            <StateSlot show={state === 'saved'}>\n              <Banner tone=\"info\"><Text path={['messages', 'saved']} value={props.messages.saved} as=\"span\" /></Banner>\n            </StateSlot>\n            <StateSlot show={state === 'error'}>\n              <Banner tone=\"error\"><Text path={['messages', 'error']} value={props.messages.error} as=\"span\" /></Banner>\n            </StateSlot>\n            <fieldset disabled={state === 'saving'} className=\"m-0 flex min-w-0 flex-col gap-6 border-0 p-0\">\n            <div className=\"flex items-center gap-4\">\n              <Avatar name={props.avatar.name} size=\"lg\" decorative />\n              <div className=\"flex min-w-0 flex-col items-start gap-1\">\n                <Text path={['avatar', 'name']} value={props.avatar.name} as=\"p\" className=\"truncate text-kh-body font-medium\" />\n                <Button variant=\"secondary\">\n                  <Text path={['avatar', 'change']} value={props.avatar.change} as=\"span\" />\n                </Button>\n              </div>\n            </div>\n            {props.fields.map((f, i) => {\n              const fid = `${id}-f${i}`;\n              const invalid = state === 'error' && i === bad;\n              const describedBy = [f.hint && `${fid}-h`, invalid && `${fid}-e`].filter(Boolean).join(' ') || undefined;\n              const common = { id: fid, name: `field-${i}`, defaultValue: f.sample, autoComplete: f.autocomplete, 'aria-invalid': invalid || undefined, 'aria-describedby': describedBy };\n              return (\n                <div key={i} className=\"flex flex-col gap-1.5\">\n                  <label htmlFor={fid} className=\"text-kh-small font-medium text-kh-ink\">\n                    <Text path={['fields', i, 'label']} value={f.label} as=\"span\" />\n                  </label>\n                  {f.kind === 'textarea' ? <Textarea rows={4} {...common} /> : <Input type={f.kind} {...common} />}\n                  {f.hint && (\n                    <p id={`${fid}-h`} className=\"text-kh-small text-kh-muted\">\n                      <Text path={['fields', i, 'hint']} value={f.hint} as=\"span\" />\n                    </p>\n                  )}\n                  {i === bad && (\n                    <StateSlot show={invalid}>\n                      <p id={`${fid}-e`} className=\"text-kh-small text-kh-danger\">\n                        <Text path={['messages', 'fieldError']} value={props.messages.fieldError} as=\"span\" />\n                      </p>\n                    </StateSlot>\n                  )}\n                </div>\n              );\n            })}\n            <div className=\"flex flex-wrap justify-end gap-3 border-t border-kh-line pt-6\">\n              <Button variant=\"ghost\">\n                <Text path={['actions', 'cancel']} value={props.actions.cancel} as=\"span\" />\n              </Button>\n              <Button type=\"submit\" disabled={state === 'saving'}>\n                <Text path={['actions', state === 'saving' ? 'saving' : 'save']} value={state === 'saving' ? props.actions.saving : props.actions.save} as=\"span\" />\n              </Button>\n            </div>\n            </fieldset>\n            <StateSlot show={false} className=\"text-kh-small text-kh-muted\">\n              <Text path={['actions', state === 'saving' ? 'save' : 'saving']} value={state === 'saving' ? props.actions.save : props.actions.saving} as=\"p\" />\n            </StateSlot>\n          </form>\n        </AppPanel>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppSettingsProfile);\n"
    }
  ]
}
