{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-page",
  "title": "Settings page",
  "author": "Tori Bryan",
  "description": "A settings screen in tabs for profile, notifications and account, with a save bar that appears on change and a confirmed danger zone.",
  "dependencies": [],
  "registryDependencies": [
    "https://fibo.toribryan.com/r/alert-dialog.json",
    "https://fibo.toribryan.com/r/avatar.json",
    "https://fibo.toribryan.com/r/button.json",
    "https://fibo.toribryan.com/r/field.json",
    "https://fibo.toribryan.com/r/input.json",
    "https://fibo.toribryan.com/r/radio-group.json",
    "https://fibo.toribryan.com/r/select.json",
    "https://fibo.toribryan.com/r/switch.json",
    "https://fibo.toribryan.com/r/textarea.json",
    "https://fibo.toribryan.com/r/kbd.json",
    "https://fibo.toribryan.com/r/tabs.json",
    "https://fibo.toribryan.com/r/toast.json",
    "utils"
  ],
  "files": [
    {
      "path": "registry/blocks/settings-page/data.ts",
      "content": "// Placeholder settings for the Settings page block. Swap `initialSettings`\n// for what your app loads, and save where `onSave` is called.\n\ntype PushSetting = \"all\" | \"mentions\" | \"none\"\n\ntype Settings = {\n  name: string\n  username: string\n  bio: string\n  email: string\n  language: string\n  mentionEmails: boolean\n  weeklyDigest: boolean\n  productUpdates: boolean\n  push: PushSetting\n}\n\nconst initialSettings: Settings = {\n  name: \"Ada Lovelace\",\n  username: \"ada\",\n  bio: \"Writes the first programs for engines that don't exist yet.\",\n  email: \"ada@northwind.dev\",\n  language: \"en\",\n  mentionEmails: true,\n  weeklyDigest: false,\n  productUpdates: true,\n  push: \"mentions\",\n}\n\nconst languages = [\n  { value: \"en\", label: \"English\" },\n  { value: \"es\", label: \"Español\" },\n  { value: \"fr\", label: \"Français\" },\n  { value: \"de\", label: \"Deutsch\" },\n  { value: \"ja\", label: \"日本語\" },\n]\n\nconst pushOptions: {\n  value: PushSetting\n  label: string\n  description: string\n}[] = [\n  {\n    value: \"all\",\n    label: \"Everything\",\n    description: \"Comments, mentions and updates.\",\n  },\n  {\n    value: \"mentions\",\n    label: \"Mentions only\",\n    description: \"When someone mentions you or replies.\",\n  },\n  {\n    value: \"none\",\n    label: \"Nothing\",\n    description: \"Turn push notifications off.\",\n  },\n]\n\nexport { initialSettings, languages, pushOptions }\nexport type { PushSetting, Settings }\n",
      "type": "registry:component",
      "target": "components/blocks/settings-page/data.ts"
    },
    {
      "path": "registry/blocks/settings-page/sections.tsx",
      "content": "import * as React from \"react\"\n\nimport {\n  AlertDialog,\n  AlertDialogAction,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n} from \"@/components/ui/alert-dialog\"\nimport { Avatar, AvatarFallback } from \"@/components/ui/avatar\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  Field,\n  FieldContent,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldItem,\n  FieldLabel,\n} from \"@/components/ui/field\"\nimport { Input } from \"@/components/ui/input\"\nimport {\n  RadioGroup,\n  RadioGroupItem,\n} from \"@/components/ui/radio-group\"\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from \"@/components/ui/select\"\nimport { Switch } from \"@/components/ui/switch\"\nimport { Textarea } from \"@/components/ui/textarea\"\n\nimport {\n  languages,\n  pushOptions,\n  type PushSetting,\n  type Settings,\n} from \"./data\"\n\ntype SectionProps = {\n  settings: Settings\n  update: <Key extends keyof Settings>(key: Key, value: Settings[Key]) => void\n}\n\n/** A titled group of settings, with a rule between groups. */\nfunction SettingsGroup({\n  title,\n  description,\n  children,\n}: {\n  title: string\n  description: string\n  children: React.ReactNode\n}) {\n  return (\n    <section className=\"grid gap-6 border-b border-border py-8 first:pt-0 last:border-b-0 @3xl/settings:grid-cols-[16rem_1fr] @3xl/settings:gap-12\">\n      <div className=\"flex flex-col gap-1\">\n        <h2 className=\"m-0 text-base font-semibold text-foreground\">{title}</h2>\n        <p className=\"m-0 text-sm text-muted-foreground\">{description}</p>\n      </div>\n      <div className=\"flex min-w-0 flex-col gap-6\">{children}</div>\n    </section>\n  )\n}\n\nfunction ProfileSection({\n  settings,\n  update,\n  nameMissing,\n}: SectionProps & { nameMissing: boolean }) {\n  const initials = settings.name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .map((word) => word[0])\n    .join(\"\")\n    .slice(0, 2)\n    .toUpperCase()\n  return (\n    <SettingsGroup\n      title=\"Profile\"\n      description=\"How you appear to the people in your workspace.\"\n    >\n      <div className=\"flex items-center gap-4\">\n        <Avatar size=\"lg\">\n          <AvatarFallback>{initials || \"?\"}</AvatarFallback>\n        </Avatar>\n        <p className=\"m-0 text-sm text-muted-foreground\">\n          Your initials stand in until you add a photo.\n        </p>\n      </div>\n      <FieldGroup>\n        <Field invalid={nameMissing}>\n          <FieldLabel>Name</FieldLabel>\n          <Input\n            value={settings.name}\n            onChange={(event) => update(\"name\", event.target.value)}\n            autoComplete=\"name\"\n          />\n          <FieldError>Enter your name.</FieldError>\n        </Field>\n        <Field>\n          <FieldLabel>Username</FieldLabel>\n          <Input\n            value={settings.username}\n            onChange={(event) => update(\"username\", event.target.value)}\n            autoComplete=\"username\"\n          />\n          <FieldDescription>\n            People mention you with @{settings.username || \"username\"}.\n          </FieldDescription>\n        </Field>\n        <Field>\n          <FieldLabel>Bio</FieldLabel>\n          <Textarea\n            value={settings.bio}\n            onChange={(event) => update(\"bio\", event.target.value)}\n            maxLength={160}\n          />\n          <FieldDescription>\n            {160 - settings.bio.length} characters left.\n          </FieldDescription>\n        </Field>\n      </FieldGroup>\n    </SettingsGroup>\n  )\n}\n\nfunction NotificationsSection({ settings, update }: SectionProps) {\n  const toggles = [\n    {\n      key: \"mentionEmails\",\n      label: \"Mentions and replies\",\n      description: \"An email when someone mentions you or replies to you.\",\n    },\n    {\n      key: \"weeklyDigest\",\n      label: \"Weekly digest\",\n      description: \"A Monday summary of what changed in your projects.\",\n    },\n    {\n      key: \"productUpdates\",\n      label: \"Product updates\",\n      description: \"New features, at most once a month.\",\n    },\n  ] as const\n  return (\n    <>\n      <SettingsGroup title=\"Email\" description=\"What lands in your inbox.\">\n        <FieldGroup>\n          {toggles.map((toggle) => (\n            <Field key={toggle.key} orientation=\"horizontal\">\n              <FieldContent>\n                <FieldLabel>{toggle.label}</FieldLabel>\n                <FieldDescription>{toggle.description}</FieldDescription>\n              </FieldContent>\n              <Switch\n                checked={settings[toggle.key]}\n                onCheckedChange={(checked) => update(toggle.key, checked)}\n              />\n            </Field>\n          ))}\n        </FieldGroup>\n      </SettingsGroup>\n      <SettingsGroup\n        title=\"Push\"\n        description=\"What reaches your phone and desktop.\"\n      >\n        <Field>\n          <RadioGroup\n            aria-label=\"Push notifications\"\n            value={settings.push}\n            onValueChange={(value) => update(\"push\", value as PushSetting)}\n            className=\"gap-4\"\n          >\n            {pushOptions.map((option) => (\n              <FieldItem key={option.value}>\n                <RadioGroupItem value={option.value} className=\"mt-0.5\" />\n                <FieldContent>\n                  <FieldLabel>{option.label}</FieldLabel>\n                  <FieldDescription>{option.description}</FieldDescription>\n                </FieldContent>\n              </FieldItem>\n            ))}\n          </RadioGroup>\n        </Field>\n      </SettingsGroup>\n    </>\n  )\n}\n\nfunction AccountSection({\n  settings,\n  update,\n  container,\n  onDelete,\n}: SectionProps & {\n  /** Where the confirmation portals to. Defaults to the body. */\n  container?: HTMLElement | null\n  onDelete: () => void\n}) {\n  return (\n    <>\n      <SettingsGroup\n        title=\"Account\"\n        description=\"Where we reach you, and the language you read in.\"\n      >\n        <FieldGroup>\n          <Field>\n            <FieldLabel>Email</FieldLabel>\n            <Input\n              type=\"email\"\n              value={settings.email}\n              onChange={(event) => update(\"email\", event.target.value)}\n              autoComplete=\"email\"\n            />\n          </Field>\n          <Field>\n            <FieldLabel>Language</FieldLabel>\n            <Select\n              items={languages}\n              value={settings.language}\n              onValueChange={(value) => update(\"language\", value as string)}\n            >\n              <SelectTrigger className=\"w-full @lg/settings:w-64\">\n                <SelectValue />\n              </SelectTrigger>\n              <SelectContent>\n                {languages.map((language) => (\n                  <SelectItem key={language.value} value={language.value}>\n                    {language.label}\n                  </SelectItem>\n                ))}\n              </SelectContent>\n            </Select>\n          </Field>\n        </FieldGroup>\n      </SettingsGroup>\n      <SettingsGroup\n        title=\"Danger zone\"\n        description=\"Changes here can't be undone.\"\n      >\n        <div className=\"flex flex-col gap-4 rounded-xl border border-destructive-ring p-4 @lg/settings:flex-row @lg/settings:items-center\">\n          <div className=\"flex min-w-0 flex-1 flex-col gap-1\">\n            <span className=\"text-sm font-medium text-foreground\">\n              Delete account\n            </span>\n            <span className=\"text-sm text-muted-foreground\">\n              Removes your profile and every project you own, for everyone.\n            </span>\n          </div>\n          <AlertDialog>\n            <AlertDialogTrigger\n              render={<Button variant=\"destructive\" type=\"button\" />}\n            >\n              Delete account\n            </AlertDialogTrigger>\n            <AlertDialogContent container={container}>\n              <AlertDialogHeader>\n                <AlertDialogTitle>Delete your account?</AlertDialogTitle>\n                <AlertDialogDescription>\n                  Your profile and the projects you own are deleted for everyone\n                  in the workspace. This can&apos;t be undone.\n                </AlertDialogDescription>\n              </AlertDialogHeader>\n              <AlertDialogFooter>\n                <AlertDialogCancel>Cancel</AlertDialogCancel>\n                <AlertDialogAction variant=\"destructive\" onClick={onDelete}>\n                  Delete account\n                </AlertDialogAction>\n              </AlertDialogFooter>\n            </AlertDialogContent>\n          </AlertDialog>\n        </div>\n      </SettingsGroup>\n    </>\n  )\n}\n\nexport { AccountSection, NotificationsSection, ProfileSection }\nexport type { SectionProps }\n",
      "type": "registry:component",
      "target": "components/blocks/settings-page/sections.tsx"
    },
    {
      "path": "registry/blocks/settings-page/settings-page.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport { Kbd, KbdGroup } from \"@/components/ui/kbd\"\nimport {\n  Tabs,\n  TabsContent,\n  TabsList,\n  TabsTrigger,\n} from \"@/components/ui/tabs\"\nimport { toast, Toaster } from \"@/components/ui/toast\"\nimport { cn } from \"@/lib/utils\"\n\nimport { initialSettings, type Settings } from \"./data\"\nimport {\n  AccountSection,\n  NotificationsSection,\n  ProfileSection,\n} from \"./sections\"\n\ntype Tab = \"profile\" | \"notifications\" | \"account\"\n\ntype SettingsPageProps = Omit<\n  React.ComponentProps<\"form\">,\n  \"children\" | \"onSubmit\"\n> & {\n  /** The settings the page opens with. Defaults to the placeholder in `data.ts`. */\n  initialValues?: Settings\n  /** Called with every setting when they're saved. Persist them here. */\n  onSave?: (settings: Settings) => void\n  /** Where the delete confirmation portals to. Defaults to the body. */\n  container?: HTMLElement | null\n}\n\nconst noSubscription = () => () => {}\n\n// Matches the key the shortcut listens for: Cmd on Apple devices, Ctrl\n// elsewhere. The server snapshot keeps the first render hydration-safe.\nfunction useIsMac() {\n  return React.useSyncExternalStore(\n    noSubscription,\n    () => /mac|iphone|ipad/i.test(navigator.platform || navigator.userAgent),\n    () => false\n  )\n}\n\nconst changed = (a: Settings, b: Settings) =>\n  (Object.keys(a) as (keyof Settings)[]).some((key) => a[key] !== b[key])\n\n/**\n * A settings screen in three tabs. Edits collect in one form, a save bar\n * appears once anything differs from what was last saved, and Cmd+S or\n * Ctrl+S saves from any field.\n */\nfunction SettingsPage({\n  initialValues = initialSettings,\n  onSave,\n  container,\n  className,\n  ...props\n}: SettingsPageProps) {\n  const [saved, setSaved] = React.useState(initialValues)\n  const [settings, setSettings] = React.useState(initialValues)\n  const [tab, setTab] = React.useState<Tab>(\"profile\")\n  const [nameMissing, setNameMissing] = React.useState(false)\n  const mac = useIsMac()\n  const dirty = changed(settings, saved)\n\n  const update = <Key extends keyof Settings>(\n    key: Key,\n    value: Settings[Key]\n  ) => {\n    setSettings((current) => ({ ...current, [key]: value }))\n    if (key === \"name\" && String(value).trim()) setNameMissing(false)\n  }\n\n  const save = () => {\n    if (!settings.name.trim()) {\n      setNameMissing(true)\n      setTab(\"profile\")\n      return\n    }\n    // onSave first: if it throws, the values stay unsaved and the bar stays.\n    onSave?.(settings)\n    setSaved(settings)\n    toast.add({ title: \"Settings saved\" })\n  }\n\n  return (\n    <form\n      data-slot=\"settings-page\"\n      noValidate\n      onSubmit={(event) => {\n        event.preventDefault()\n        save()\n      }}\n      onKeyDown={(event) => {\n        if (event.key === \"s\" && (event.metaKey || event.ctrlKey)) {\n          event.preventDefault()\n          if (dirty) event.currentTarget.requestSubmit()\n        }\n      }}\n      className={cn(\n        \"@container/settings flex min-h-svh flex-col bg-background text-foreground\",\n        className\n      )}\n      {...props}\n    >\n      <div className=\"mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 px-4 pt-10 pb-28 @2xl/settings:px-8\">\n        <div className=\"flex flex-col gap-1\">\n          <h1 className=\"m-0 text-2xl font-semibold tracking-tight\">\n            Settings\n          </h1>\n          <p className=\"m-0 text-sm text-muted-foreground\">\n            Manage your profile, what you hear about and your account.\n          </p>\n        </div>\n\n        <Tabs value={tab} onValueChange={(value) => setTab(value as Tab)}>\n          <TabsList variant=\"line\">\n            <TabsTrigger value=\"profile\">Profile</TabsTrigger>\n            <TabsTrigger value=\"notifications\">Notifications</TabsTrigger>\n            <TabsTrigger value=\"account\">Account</TabsTrigger>\n          </TabsList>\n          <TabsContent value=\"profile\" className=\"pt-8\">\n            <ProfileSection\n              settings={settings}\n              update={update}\n              nameMissing={nameMissing}\n            />\n          </TabsContent>\n          <TabsContent value=\"notifications\" className=\"pt-8\">\n            <NotificationsSection settings={settings} update={update} />\n          </TabsContent>\n          <TabsContent value=\"account\" className=\"pt-8\">\n            <AccountSection\n              settings={settings}\n              update={update}\n              container={container}\n              onDelete={() =>\n                toast.add({\n                  title: \"Account scheduled for deletion\",\n                  description: \"We'll email you a link to confirm.\",\n                })\n              }\n            />\n          </TabsContent>\n        </Tabs>\n      </div>\n\n      {/* Mounted while clean too, so the change is announced when it comes. */}\n      <p role=\"status\" className=\"sr-only\">\n        {dirty ? \"You have unsaved changes.\" : \"\"}\n      </p>\n      {dirty ? (\n        <div className=\"sticky bottom-4 z-10 animate-in px-4 duration-150 fade-in-0 slide-in-from-bottom-2 motion-reduce:animate-none\">\n          <div className=\"mx-auto flex max-w-4xl flex-col gap-3 rounded-xl border border-border bg-popover p-3 shadow-lg @lg/settings:flex-row @lg/settings:items-center\">\n            <span className=\"flex flex-1 items-center gap-2 px-1 text-sm\">\n              Unsaved changes\n              <KbdGroup className=\"hidden @lg/settings:inline-flex\">\n                <Kbd>{mac ? \"⌘\" : \"Ctrl\"}</Kbd>\n                <Kbd>S</Kbd>\n              </KbdGroup>\n            </span>\n            <div className=\"flex gap-2\">\n              <Button\n                type=\"button\"\n                variant=\"outline\"\n                className=\"flex-1 @lg/settings:flex-none\"\n                onClick={() => {\n                  setSettings(saved)\n                  setNameMissing(false)\n                }}\n              >\n                Discard\n              </Button>\n              <Button type=\"submit\" className=\"flex-1 @lg/settings:flex-none\">\n                Save changes\n              </Button>\n            </div>\n          </div>\n        </div>\n      ) : null}\n\n      {/* Remove this if your app already mounts a Toaster near its root. */}\n      <Toaster />\n    </form>\n  )\n}\n\nexport { SettingsPage }\nexport type { SettingsPageProps }\n",
      "type": "registry:component",
      "target": "components/blocks/settings-page/settings-page.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-destructive-ring": "var(--destructive-ring)"
    },
    "light": {
      "destructive-ring": "color-mix(in oklch, var(--color-red-700) 20%, transparent)"
    },
    "dark": {
      "destructive-ring": "color-mix(in oklch, var(--color-red-400) 40%, transparent)"
    }
  },
  "meta": {
    "tier": "blocks",
    "group": "Pages",
    "docs": "https://fibo.toribryan.com/?path=/docs/blocks-settings-page--docs"
  },
  "docs": "Installed into components/blocks/settings-page. Render <SettingsPage /> where the screen goes, then edit it: it's yours. Docs: https://fibo.toribryan.com/?path=/docs/blocks-settings-page--docs",
  "categories": [
    "blocks",
    "pages"
  ],
  "type": "registry:block"
}