# Settings page

> Account settings shell with Profile, Notifications, Security and Billing navigation rail plus a contextual Save/Discard bar on edit.

- Kind: block · Category: Settings · Interactivity: script
- Install: `npx shadcn@latest add @haze/settings-page`
- File: `src/components/haze/blocks/settings-page.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/settings-page

## Use when
- Organizing user account settings into a clean left rail with a dirty-state save bar
- Letting users edit profile and notification preferences with explicit Save and Discard actions

## Avoid when
- Providing instant command-search across dozens of workspace settings; use settings-command

## Alternatives
- [tabs](https://hazeui.com/ui/tabs.md)
- [settings-command](https://hazeui.com/blocks/settings-command.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-settings-page" | no | Unique prefix for form labels and heading IDs. |
| heading | `string` | "Account settings" | no | Rail heading. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- The active rail tab provides keyboard access to its panel. Each field has an explicit label.
- Save records edits for the current preview. Discard restores the last saved values across all sections. Both announce confirmation and return focus to the active tab.
- Key Tab: Move across the active rail tab, settings fields, and Save and Discard buttons
- Key Arrow keys: Switch settings sections using Up / Down in the vertical rail or Left / Right in the horizontal rail
- Key Home / End: Move to the first or last settings section
- Key Enter / Space: Activate the focused tab or button

## Agent prompts

### Install and use

Install the Haze UI block "Settings page" with `npx shadcn@latest add @haze/settings-page`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import SettingsPage from "@/components/haze/blocks/settings-page.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/settings-page.md

### Customize with real content

Adapt the Haze settings-page block for our product. Replace the demo values of these props with our real content: id, heading, class. Keep the layout, the heading level rules and these accessibility details: The active rail tab provides keyboard access to its panel. Each field has an explicit label. Save records edits for the current preview. Discard restores the last saved values across all sections. Both announce confirmation and return focus to the active tab. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using settings-page, check it fits: use it when organizing user account settings into a clean left rail with a dirty-state save bar; letting users edit profile and notification preferences with explicit save and discard actions. Avoid it when providing instant command-search across dozens of workspace settings; use settings-command. Alternatives: @haze/tabs, @haze/settings-command.

## Example requests that should lead here
- Add an account settings page with Profile, Notifications, Security and Billing rail and an unsaved-changes Save bar

## Source

```astro
---
import { Bell, Check, CreditCard, Shield, User } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  heading?: string;
  class?: string;
}

const { id = "haze-settings-page", heading = "Account settings", class: className } = Astro.props;

const nav = [
  { id: "profile", label: "Profile" },
  { id: "notifications", label: "Notifications" },
  { id: "security", label: "Security" },
  { id: "billing", label: "Billing" },
] as const;
---

<section aria-labelledby={`${id}-title`} data-haze-settings-page class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-4xl space-y-4">
    <div class="grid overflow-hidden rounded-2xl border border-border bg-card md:grid-cols-[13.5rem_minmax(0,1fr)]">
      <aside aria-label="Settings sections" class="min-w-0 border-b border-border bg-muted/40 p-3 md:border-r md:border-b-0">
        <h2 id={`${id}-title`} class="px-2.5 pb-2 text-xs/4 font-semibold tracking-wider text-muted-foreground uppercase">{heading}</h2>
        <nav data-spg-tabs aria-label="Account sections" class="flex gap-1 overflow-x-auto md:flex-col">
          {
            nav.map((item) => (
              <a
                id={`${id}-${item.id}-tab`}
                href={`#${id}-${item.id}-panel`}
                data-spg-tab={item.id}
                class="inline-flex h-9 shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2.5 text-left text-xs font-medium text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground aria-selected:bg-accent aria-selected:text-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring md:w-full"
              >
                {item.id === "profile" ? <User class="size-3.5 shrink-0" aria-hidden="true" /> : item.id === "notifications" ? <Bell class="size-3.5 shrink-0" aria-hidden="true" /> : item.id === "security" ? <Shield class="size-3.5 shrink-0" aria-hidden="true" /> : <CreditCard class="size-3.5 shrink-0" aria-hidden="true" />}
                <span>{item.label}</span>
              </a>
            ))
          }
        </nav>
      </aside>

      <div class="min-w-0 p-5 sm:p-6 [[data-haze-settings-page]:not([data-enhanced])_&>*:not(:first-child):not(:target)]:hidden [[data-haze-settings-page]:not([data-enhanced])_&:has(>:not(:first-child):target)>*:first-child]:hidden">
        <div id={`${id}-profile-panel`} data-spg-pane="profile" class="space-y-4">
          <h3 class="text-base/6 font-semibold text-foreground">Profile</h3>
          <div class="grid gap-3 sm:grid-cols-2">
            <div class="grid gap-1.5">
              <label for={`${id}-name`} class="text-xs font-medium text-muted-foreground">Display name</label>
              <input id={`${id}-name`} data-spg-dirty type="text" value="Nina Patel" class="h-9 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
            </div>
            <div class="grid gap-1.5">
              <label for={`${id}-handle`} class="text-xs font-medium text-muted-foreground">Handle</label>
              <input id={`${id}-handle`} data-spg-dirty type="text" value="@ninapatel" class="h-9 rounded-lg border border-frame-input bg-field px-3 font-mono text-xs text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
            </div>
          </div>
          <div class="grid gap-1.5">
            <label for={`${id}-bio`} class="text-xs font-medium text-muted-foreground">Bio</label>
            <textarea id={`${id}-bio`} data-spg-dirty rows="2" class="rounded-lg border border-frame-input bg-field p-2.5 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground">Design systems engineer working on dark UI tokens and accessibility.</textarea>
          </div>
        </div>

        <div id={`${id}-notifications-panel`} data-spg-pane="notifications" class="space-y-3">
          <h3 class="text-base/6 font-semibold text-foreground">Notifications</h3>
          <label class="flex cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-3.5 py-3 text-xs text-foreground">
            <span>Product changelog &amp; release notes</span>
            <span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked data-spg-dirty class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
          </label>
          <label class="flex cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-3.5 py-3 text-xs text-foreground">
            <span>Weekly summary digest email</span>
            <span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" data-spg-dirty class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
          </label>
        </div>

        <div id={`${id}-security-panel`} data-spg-pane="security" class="space-y-3">
          <h3 class="text-base/6 font-semibold text-foreground">Security</h3>
          <p class="text-xs/5 text-muted-foreground">Two-factor authentication is enabled via authenticator app. 2 active browser sessions.</p>
          <label class="flex cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-3.5 py-3 text-xs text-foreground">
            <span>Require passkey or 2FA for billing changes</span>
            <span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked data-spg-dirty class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
          </label>
        </div>

        <div id={`${id}-billing-panel`} data-spg-pane="billing" class="space-y-3 focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ring">
          <h3 class="text-base/6 font-semibold text-foreground">Billing</h3>
          <div class="rounded-xl border border-border bg-muted/40 p-4 text-xs/5">
            <p class="font-semibold text-foreground">Haze Core · $0 / month</p>
            <p class="mt-1 text-muted-foreground">Unlimited projects and full shadcn registry installs.</p>
          </div>
        </div>
      </div>
    </div>

    <div data-spg-bar hidden class="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border bg-popover px-4 py-3 shadow-float">
      <span class="text-xs font-medium text-foreground">You have unsaved changes.</span>
      <div class="flex items-center gap-2">
        <button type="button" data-spg-discard class="inline-flex h-8 cursor-pointer items-center rounded-lg border border-frame bg-field px-3 text-xs font-medium text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Discard</button>
        <button type="button" data-spg-save class="inline-flex h-8 cursor-pointer items-center rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Save changes</button>
      </div>
    </div>

    <p data-spg-status role="status" class="min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  const settingsRail = matchMedia("(min-width: 48rem)");

  function updateSettingsTabOrientation() {
    document.querySelectorAll("[data-spg-tabs][role='tablist']").forEach((list) =>
      list.setAttribute("aria-orientation", settingsRail.matches ? "vertical" : "horizontal"),
    );
  }

  function initSettingsPages() {
    document.querySelectorAll<HTMLElement>("[data-haze-settings-page]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      const list = root.querySelector<HTMLElement>("[data-spg-tabs]");
      const tabs = Array.from(root.querySelectorAll<HTMLAnchorElement>("[data-spg-tab]"));
      const panes = Array.from(root.querySelectorAll<HTMLElement>("[data-spg-pane]"));
      const fields = Array.from(root.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>("[data-spg-dirty]"));
      const bar = root.querySelector<HTMLElement>("[data-spg-bar]");
      const status = root.querySelector<HTMLElement>("[data-spg-status]");
      if (!list || !bar || !status) return;
      root.setAttribute("data-enhanced", "");

      let activeTab = tabs.find((tab) => tab.hash === location.hash) ?? tabs[0];
      const select = (tab: HTMLAnchorElement) => {
        activeTab = tab;
        tabs.forEach((item) => {
          item.setAttribute("aria-selected", String(item === tab));
          item.tabIndex = item === tab ? 0 : -1;
        });
        panes.forEach((pane) => { pane.hidden = pane.dataset.spgPane !== tab.dataset.spgTab; });
      };

      list.setAttribute("role", "tablist");
      tabs.forEach((tab, index) => {
        const pane = panes.find((item) => item.dataset.spgPane === tab.dataset.spgTab);
        if (!pane) return;
        tab.setAttribute("role", "tab");
        tab.setAttribute("aria-controls", pane.id);
        pane.setAttribute("role", "tabpanel");
        pane.setAttribute("aria-labelledby", tab.id);
        if (!pane.querySelector("input, textarea")) pane.tabIndex = 0;

        tab.addEventListener("click", (event) => {
          event.preventDefault();
          select(tab);
        });
        tab.addEventListener("keydown", (event) => {
          const backward = settingsRail.matches ? "ArrowUp" : "ArrowLeft";
          const forward = settingsRail.matches ? "ArrowDown" : "ArrowRight";
          const last = tabs.length - 1;
          const target = event.key === backward ? tabs[(index + last) % tabs.length]
            : event.key === forward ? tabs[(index + 1) % tabs.length]
            : event.key === "Home" ? tabs[0]
            : event.key === "End" ? tabs[last]
            : event.key === " " ? tab
            : undefined;
          if (!target) return;
          event.preventDefault();
          select(target);
          target.focus();
          target.scrollIntoView({ block: "nearest", inline: "nearest" });
        });
      });
      if (activeTab) select(activeTab);

      const read = (field: HTMLInputElement | HTMLTextAreaElement) =>
        field instanceof HTMLInputElement && field.type === "checkbox" ? field.checked : field.value;
      let saved = fields.map(read);

      const onEdit = () => {
        bar.hidden = fields.every((field, index) => read(field) === saved[index]);
        status.textContent = "";
      };
      fields.forEach((field) => {
        field.addEventListener("input", onEdit);
        field.addEventListener("change", onEdit);
      });

      const closeBar = (message: string) => {
        if (bar.contains(document.activeElement)) activeTab?.focus();
        bar.hidden = true;
        status.textContent = message;
      };
      root.querySelector<HTMLButtonElement>("[data-spg-save]")?.addEventListener("click", () => {
        saved = fields.map(read);
        closeBar("Changes saved for this preview.");
      });
      root.querySelector<HTMLButtonElement>("[data-spg-discard]")?.addEventListener("click", () => {
        fields.forEach((field, index) => {
          const value = saved[index];
          if (typeof value === "boolean" && field instanceof HTMLInputElement) field.checked = value;
          if (typeof value === "string") field.value = value;
        });
        closeBar("Restored the last saved settings.");
      });
    });
    updateSettingsTabOrientation();
  }
  initSettingsPages();
  if (!document.documentElement.hasAttribute("data-haze-settings-page-listener")) {
    document.documentElement.setAttribute("data-haze-settings-page-listener", "");
    document.addEventListener("astro:page-load", initSettingsPages);
    settingsRail.addEventListener("change", updateSettingsTabOrientation);
  }
</script>
```
