{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "install-prompt",
  "title": "InstallPrompt",
  "description": "A quiet offer to install the web app, shown only where the browser can install it (Chromium on Android and desktops), never while it already runs installed, and not again for two weeks after Not now.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/card",
    "@ouro/lib-class-name-check",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-install-prompt"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/install-prompt/install-prompt.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useLayoutEffect, useRef, type ComponentProps, type FocusEvent, type JSX, type ReactNode } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { useInstallPrompt } from \"@/registry/ouro/lib/ouro/use-install-prompt\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { Card } from \"@/registry/ouro/components/ouro/card/card\";\n\n/** Props for {@link InstallPrompt}. */\nexport interface InstallPromptProps {\n  /** The offer's title. @default \"Install the app\" */\n  title?: string | undefined;\n  /** What installing gives the person. @default \"Add it to your home screen or dock and open it like any other app.\" */\n  description?: ReactNode;\n  /** A picture across the top, such as the app on a phone. */\n  media?: ReactNode;\n  /** The label of the button that opens the browser's install dialog. @default \"Install\" */\n  installLabel?: string | undefined;\n  /** The label of the button that puts the offer away. @default \"Not now\" */\n  dismissLabel?: string | undefined;\n  /** Days before offering again after Not now. @default 14 */\n  remindAfterDays?: number | undefined;\n  /** The `localStorage` key that keeps when the person said Not now. @default \"ouro-install-dismissed\" */\n  storageKey?: string | undefined;\n  /** Called with how the person answered the browser's install dialog. */\n  onInstall?: ((outcome: \"accepted\" | \"dismissed\") => void) | undefined;\n  /** The title's heading level. @default 2 */\n  headingLevel?: ComponentProps<typeof Card>[\"headingLevel\"];\n  /** Layout only: margins, width (`mt-6`, `max-w-md`). Appearance classes warn in development. */\n  className?: string | undefined;\n\n  /** Not a prop. The offer shows itself when the browser can install the app; there is nothing to open. */\n  open?: { 'InstallPrompt shows itself when the app can be installed': never };\n  /** Not a prop. Ouro UI says `onInstall`: `<InstallPrompt onInstall={(outcome) => …} />`. */\n  onAccept?: { 'Use onInstall={(outcome) => ...}': never };\n}\n\nconst tabbable =\n  'a[href], button:not(:disabled), input:not(:disabled):not([type=\"hidden\"]), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])';\n\n/** Where focus goes when the card leaves with it: back where it came from, else the next control, else the one before. */\nfunction returnTarget(card: HTMLElement, cameFrom: HTMLElement | null): HTMLElement | null {\n  if (cameFrom?.isConnected) return cameFrom;\n  const outside = [...document.querySelectorAll<HTMLElement>(tabbable)].filter((element) => !card.contains(element) && element.checkVisibility());\n  return outside.find((element) => card.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_FOLLOWING) ?? outside.at(-1) ?? null;\n}\n\n/**\n * A quiet offer to install the web app, shown only where the browser can install it (Chromium\n * on Android and desktops), never while it already runs installed, and not again for two weeks\n * after Not now. Install opens the browser's own install dialog. It renders nothing otherwise,\n * so it can sit in a layout unconditionally. The browser's install event is caught as soon as\n * the module loads, so an offer is never missed because the page mounted late. When Install or\n * Not now takes the card away while it has focus, focus goes back where it was before the card,\n * or to the next control on the page when that is gone.\n *\n * Use `useInstallPrompt` instead to offer installing from a control of your own, such as a menu item.\n *\n * @group Feedback\n * @see https://ui.ouroboros.bot/docs/install-prompt\n *\n * @example\n * <InstallPrompt className=\"mt-6\" />\n * @claim \"A quiet offer to install the\" registry/ouro/lib/ouro/use-install-prompt.test.tsx verify:testExists(registry/ouro/lib/ouro/use-install-prompt.test.tsx::useInstallPrompt > is installed, and offers nothing, while the app runs standalone)\n * @claim \"A quiet offer to install the\" registry/ouro/lib/ouro/use-install-prompt.test.tsx verify:testExists(registry/ouro/lib/ouro/use-install-prompt.test.tsx::useInstallPrompt > puts the offer away on dismiss(), and keeps it away for remindAfterDays)\n * @claim \"A quiet offer to install the\" registry/ouro/lib/ouro/use-install-prompt.ts verify:fileLine(registry/ouro/lib/ouro/use-install-prompt.ts, /remindAfterDays\\s=\\s14/)\n * @claim \"A quiet offer to install the\" registry/ouro/components/ouro/install-prompt/install-prompt.test.tsx verify:testExists(registry/ouro/components/ouro/install-prompt/install-prompt.test.tsx::InstallPrompt > shows a card with the offer, Not now and Install once the browser offers)\n * @claim \"The browser's install event is caught\" registry/ouro/lib/ouro/use-install-prompt.test.tsx verify:testExists(registry/ouro/lib/ouro/use-install-prompt.test.tsx::useInstallPrompt > is available to a component that mounts after the offer)\n */\nexport function InstallPrompt(props: InstallPromptProps): JSX.Element | null {\n  const {\n    title = \"Install the app\",\n    description = \"Add it to your home screen or dock and open it like any other app.\",\n    media,\n    installLabel = \"Install\",\n    dismissLabel = \"Not now\",\n    remindAfterDays,\n    storageKey,\n    onInstall,\n    headingLevel = 2,\n    className,\n    open,\n    onAccept,\n  } = props;\n  useAppearanceClassNameCheck(\n    \"InstallPrompt\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; InstallPrompt sets its own look from the theme`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"InstallPrompt\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          open !== undefined && [\"open is not a prop; the offer shows itself when the app can be installed\", \"<InstallPrompt />\"],\n          onAccept !== undefined && [\"onAccept is not a prop\", \"<InstallPrompt onInstall={(outcome) => {}} />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const { available, install, dismiss } = useInstallPrompt({ remindAfterDays, storageKey });\n  // The card leaves on its own answer. React detaches its ref before it removes the card, so\n  // focus is still inside then; once the commit is done, focus goes to the target picked there.\n  const cameFrom = useRef<HTMLElement | null>(null);\n  const returnTo = useRef<HTMLElement | null>(null);\n  // A ref that returns a cleanup is only ever called with the element.\n  const cardRef = useCallback(\n    (node: HTMLDivElement | null) => () => {\n      returnTo.current = node!.contains(document.activeElement) ? returnTarget(node!, cameFrom.current) : null;\n    },\n    [],\n  );\n  useLayoutEffect(() => {\n    const target = returnTo.current;\n    returnTo.current = null;\n    target?.focus();\n  });\n  const enter = (event: FocusEvent<HTMLDivElement>) => {\n    const from = event.relatedTarget;\n    if (!event.currentTarget.contains(from)) cameFrom.current = from instanceof HTMLElement ? from : null;\n  };\n  if (!available) return null;\n  const accept = async () => {\n    const outcome = await install();\n    if (outcome !== \"unavailable\") onInstall?.(outcome);\n  };\n  return (\n    <div ref={cardRef} data-ouro=\"install-prompt\" className={className} onFocus={enter}>\n      <Card\n        title={title}\n        description={description}\n        media={media}\n        headingLevel={headingLevel}\n        size=\"sm\"\n        footer={\n          <div className=\"flex flex-wrap justify-end gap-2\">\n            <Button data-ouro-control=\"install-prompt\" data-ouro-part=\"dismiss\" variant=\"plain\" tone=\"secondary\" onClick={dismiss}>\n              {dismissLabel}\n            </Button>\n            <Button data-ouro-control=\"install-prompt\" data-ouro-part=\"install\" onClick={accept}>\n              {installLabel}\n            </Button>\n          </div>\n        }\n      />\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/install-prompt/install-prompt.tsx"
    }
  ],
  "docs": "A quiet offer to install the web app, shown only where the browser can install it (Chromium on Android and desktops), never while it already runs installed, and not again for two weeks after Not now. Import: import { InstallPrompt } from \"@/components/ouro/install-prompt/install-prompt\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, card, heading, text, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/install-prompt.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}