# Notification preferences

A controlled notification preference form with grouped channel switches, local feedback and native submission semantics.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs a controlled notification preference form with grouped channel switches, local feedback and native submission semantics.
- Choose it for a settings workflow where saved state, validation, and side effects remain in the host application.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than notification preferences.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Notification preferences

```sh
npx shadcn@latest add @tidal-pro/notification-preferences
```

Stylesheets: `components/ui/tidal.css`, `components/ui/notification-preferences.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/notification-preferences.css";
import{TidalNotificationPreferences}from"./components/ui/notification-preferences";
export default(p:Parameters<typeof TidalNotificationPreferences>[0])=><div className="tidal-scope"><TidalNotificationPreferences {...p}/></div>;
```

## Structured props

- `TidalNotificationPreferences.channels: ReadonlyArray<TidalNotificationChannel>`: Required channels value accepted by this exported component.
- `TidalNotificationPreferences.groups: ReadonlyArray<TidalNotificationPreferenceGroup>`: Required groups value accepted by this exported component.
- `TidalNotificationPreferences.onPreferenceChange: (preference: TidalNotificationPreference, channel: TidalNotificationChannel, checked: boolean, event: ChangeEvent<HTMLInputElement>) => void`: Callback invoked when the preference change interaction is proposed.
- `TidalNotificationPreferences.title: ReactNode`: Required title value accepted by this exported component.
- `TidalNotificationPreferences.busy?: boolean | undefined` (default false): Optional busy value accepted by this exported component.
- `TidalNotificationPreferences.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalNotificationPreferences.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalNotificationPreferences.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalNotificationPreferences.eyebrow?: ReactNode`: Optional eyebrow value accepted by this exported component.
- `TidalNotificationPreferences.footer?: ReactNode`: Optional footer value accepted by this exported component.
- `TidalNotificationPreferences.headingLevel?: "h2" | "h3" | "h4" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalNotificationPreferences.labels?: Partial<TidalNotificationPreferenceLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalNotificationPreferences.onSave?: ((event: FormEvent<HTMLFormElement>) => void) | undefined`: Callback invoked when the save interaction is proposed.
- `TidalNotificationPreferences.resetAction?: TidalNotificationResetAction | undefined`: Optional reset action value accepted by this exported component.
- `TidalNotificationPreferences.saveButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> | undefined`: Optional save button props value accepted by this exported component.
- `TidalNotificationPreferences.saveButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional save button ref value accepted by this exported component.
- `TidalNotificationPreferences.status?: ReactNode`: Optional status value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/notification-preferences.tsx) | [Manifest](https://tidalui.com/examples/notification-preferences.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useEffect, useMemo, useRef, useState } from "react";

import { TidalNotificationPreferences, type TidalNotificationChannel, type TidalNotificationPreferenceGroup } from "./components/ui/notification-preferences";

import "./components/ui/notification-preferences.css";



const tidalExampleStyles = ".tidal-scope .notification-preferences-demo,\n.tidal-scope .notification-preferences-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .notification-preferences-demo {\n  display: grid;\n  width: min(100%, 1180px);\n  min-width: 0;\n  gap: 22px;\n  margin-inline: auto;\n  padding: clamp(16px, 4vw, 42px);\n}\n\n@container tidal-preview (max-width: 390px) {\n  .tidal-scope .notification-preferences-demo {\n    gap: 16px;\n    padding: 12px;\n  }\n}";

const CHANNELS: readonly TidalNotificationChannel[] = [
  {
    id: "in-app",
    label: "In app",
    accessibleLabel: "In app",
  },
  { id: "email", label: "Email", accessibleLabel: "Email" },
  { id: "mobile", label: "Mobile", accessibleLabel: "Mobile" },
];

const INITIAL_VALUES: Readonly<Record<string, boolean>> = {
  "assignment:in-app": true,
  "assignment:email": true,
  "assignment:mobile": false,
  "comment:in-app": true,
  "comment:email": false,
  "comment:mobile": true,
  "approval:in-app": true,
  "approval:email": true,
  "approval:mobile": true,
  "weekly:in-app": false,
  "weekly:email": true,
};

export function NotificationPreferencesDemo() {
  const [values, setValues] = useState<Record<string, boolean>>({
    ...INITIAL_VALUES,
  });
  const [savedValues, setSavedValues] = useState<Record<string, boolean>>({
    ...INITIAL_VALUES,
  });
  const [busy, setBusy] = useState(false);
  const [status, setStatus] = useState("No unsaved changes.");
  const timerRef = useRef<number | null>(null);

  useEffect(
    () => () => {
      if (timerRef.current !== null) window.clearTimeout(timerRef.current);
    },
    [],
  );

  function cancelPendingSave() {
    if (timerRef.current !== null) {
      window.clearTimeout(timerRef.current);
      timerRef.current = null;
    }
    setBusy(false);
  }

  function updateValue(key: string, checked: boolean) {
    cancelPendingSave();
    setValues((current) => ({ ...current, [key]: checked }));
    setStatus("Unsaved changes.");
  }

  const groups = useMemo<readonly TidalNotificationPreferenceGroup[]>(
    () => [
      {
        id: "project",
        title: "Project activity",
        description: "Updates about your work.",
        preferences: [
          {
            id: "assignment",
            label: "Task assigned",
            accessibleLabel: "Task assigned",
            description: "When someone assigns you a task.",
            controls: CHANNELS.map((channel) => ({
              channelId: channel.id,
              checked: values[`assignment:${channel.id}`] ?? false,
              inputProps: { name: `assignment-${channel.id}` },
            })),
          },
          {
            id: "comment",
            label: "New comment",
            accessibleLabel: "New comment",
            description: "When a teammate replies to your work.",
            controls: CHANNELS.map((channel) => ({
              channelId: channel.id,
              checked: values[`comment:${channel.id}`] ?? false,
              inputProps: { name: `comment-${channel.id}` },
            })),
          },
          {
            id: "approval",
            label: "Review requested",
            accessibleLabel: "Review requested",
            description: "When something needs your approval.",
            controls: CHANNELS.map((channel) => ({
              channelId: channel.id,
              checked: values[`approval:${channel.id}`] ?? false,
              inputProps: { name: `approval-${channel.id}` },
            })),
          },
        ],
      },
      {
        id: "summary",
        title: "Workspace summary",
        description: "A recap of the week.",
        preferences: [
          {
            id: "weekly",
            label: "Weekly activity summary",
            accessibleLabel: "Weekly activity summary",
            description: "Your activity, delivered every Monday.",
            controls: CHANNELS.filter((channel) => channel.id !== "mobile").map(
              (channel) => ({
                channelId: channel.id,
                checked: values[`weekly:${channel.id}`] ?? false,
                inputProps: { name: `weekly-${channel.id}` },
              }),
            ),
          },
        ],
      },
    ],
    [values],
  );

  const dirty = Object.keys(INITIAL_VALUES).some(
    (key) => values[key] !== savedValues[key],
  );

  return (
    <section
      className="notification-preferences-demo"
      aria-label="Notification preferences preview"
    >
      <TidalNotificationPreferences
        title="Workspace updates"
        description="Choose where workspace updates appear."
        channels={CHANNELS}
        groups={groups}
        busy={busy}
        onPreferenceChange={(preference, channel, checked) =>
          updateValue(`${preference.id}:${channel.id}`, checked)
        }
        onSave={(event) => {
          event.preventDefault();
          if (busy) return;
          const nextValues = { ...values };
          setBusy(true);
          setStatus("Saving preferences…");
          timerRef.current = window.setTimeout(() => {
            timerRef.current = null;
            setSavedValues(nextValues);
            setBusy(false);
            setStatus("Preferences updated in this preview.");
          }, 600);
        }}
        action="/local-notification-preferences-preview"
        method="post"
        status={
          <span role="status" aria-live="polite">
            {status}
          </span>
        }
        resetAction={{
          label: "Reset",
          disabled: busy,
          onAction: () => {
            cancelPendingSave();
            setValues({ ...INITIAL_VALUES });
            setSavedValues({ ...INITIAL_VALUES });
            setStatus("Preferences reset.");
          },
        }}
        saveButtonProps={{
          "aria-disabled": !dirty,
          formAction: "/local-notification-preferences-preview",
          formMethod: "post",
        }}
        footer="Sample data. Changes stay in this preview."
      />
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <NotificationPreferencesDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

title, channels, groups and onPreferenceChange are required. Channels and grouped preferences are consumer-owned; every preference supplies controlled channel controls with checked state, native checkbox attributes and refs. Native disabled or aria-disabled true resolves a disabled switch; explicit aria-disabled false is preserved. Optional description, eyebrow, heading level, labels, error, status, footer and empty content are consumer-owned ReactNode values. The native form preserves action, method, attributes and ref. Optional onSave composes with native submit behavior, so a consumer may prevent submission or allow the form action. Save and reset actions preserve native button attributes, submitter overrides, refs, caller prevention, explicit aria-disabled false and 44px targets. Busy leaves Save focusable with aria-disabled and suppresses submission. The component makes no request, stores no preference, sends no notification and claims no delivery outcome.
