GooseUI

Components

Notification Prompt

New

A quiet banner that offers to turn on notifications. The browser dialog opens only after a click on “Allow”, because browsers ignore or block a request without a user gesture. “Not now” hides the banner for 7 days. When the permission is already granted, or the browser has no Notification API (iPhone Safari outside an installed app, for example), nothing is shown. JavaScript here only reads the permission and remembers the dismissal; the banner slides in with @starting-style and slides out with a discrete display transition.

Browser Support

Notifications

Shows the permission dialog and system messages

Your browser:
@starting-style

Animates the initial appearance

Your browser:
transition-behavior

Animates closing

Your browser:

Preview

The demo uses forceShow, so the banner is visible even when this browser has already answered. The button asks the browser for real, and a granted permission sends a test message.

Browser permission: unsupported

Installation

npx shadcn@latest add @gooseui/notification-prompt
pnpm dlx shadcn@latest add @gooseui/notification-prompt
yarn dlx shadcn@latest add @gooseui/notification-prompt
bunx --bun shadcn@latest add @gooseui/notification-prompt

The banner is built on the useNotificationPermission hook, which is installed along with it.

Usage

The banner decides on its own. It shows up after a second, only while the permission is undecided and the user has not declined recently. To show it on an event instead of a timer, render it conditionally.

import { NotificationPrompt } from "@/components/ui/notification-prompt"

export default function Layout({ children }: { children: React.ReactNode }) {
  return (
    <>
      {children}
      <NotificationPrompt
        floating
        onGranted={() => new Notification("Notifications are on")}
      />
    </>
  )
}

Examples

Hint when blocked

By default a blocked permission hides the banner, since the page cannot ask again. With whenDenied=“hint” the banner explains where to change it.

// forceShow="denied" is only for the demo; in a real app the banner
// switches to the hint on its own once the permission is blocked
<NotificationPrompt whenDenied="hint" forceShow="denied" />

Compact

compact turns the banner into one row. For toolbars, sidebars and narrow places.

<NotificationPrompt
  compact
  delay={3000}
  dismissDays={30}
  labels={{ title: "Get a ping when your build finishes" }}
/>

Props

PropTypeDefaultDescription
delaynumber1000Milliseconds to wait before the banner appears
whenDenied"hide" | "hint""hide"What to do when the permission is already blocked
compactbooleanfalseOne row, no description
floatingbooleanfalsePin to the bottom of the viewport
iconReactNodebell iconIcon on the left
labelsPartial<NotificationPromptLabels>-All texts, including the hint for a blocked permission
dismissDaysnumber7Days to stay hidden after “Not now”
storageKeystring"notification-prompt-dismissed-at"localStorage key for the dismissal time
forceShow"default" | "denied"-Show the banner whatever the permission is. For demos and design reviews, nothing is saved
onGranted() => void-Called when the user allows notifications
onDenied() => void-Called when the user blocks notifications
onDismiss() => void-Called when the user closes the banner
classNamestring-Additional CSS classes