Ir al contenido

NotificationBell

La campana de la barra superior: cuántas notificaciones hay sin leer, y la lista en una ventana emergente.

import { NotificationBell } from '@sypnia/ui/react'

En esta página
  1. Dos sin leer
  2. Cuándo usarlo
  3. Para todos
  4. Props

Dos sin leer

Ábrela y pulsa «Mark all as read».

Código
import { useState } from 'react';
import { NotificationBell, type NotificationEntry } from '@sypnia/ui/react';

// The count of unread ones on the bell; the list in a popover. «Mark all as read» empties the count.
const start: NotificationEntry[] = [
  { id: '1', title: 'Deploy failed', body: 'The build ran out of memory. Open the log to see where.', at: new Date(Date.now() - 4 * 60_000), unread: true, icon: 'deploy', tone: 'fail' },
  { id: '2', title: 'Backup finished', at: new Date(Date.now() - 50 * 60_000), unread: true, icon: 'backup', tone: 'ok' },
  { id: '3', title: 'Ana invited Luis to shop', at: new Date(Date.now() - 26 * 3_600_000), icon: 'user-plus' },
];
export default function Bell() {
  const [items, setItems] = useState(start);
  return <NotificationBell items={items} onReadAll={() => setItems(items.map((i) => ({ ...i, unread: false })))} onOpen={(id) => setItems(items.map((i) => (i.id === id ? { ...i, unread: false } : i)))} />;
}

Cuándo usarlo

Úsalo cuando

  • Apps que le cuentan a la gente lo que pasó mientras no estaba.

No lo uses cuando

  • Resultados de lo que la persona acaba de hacer: usa un toast.

Para todos

  • El botón dice el número: «Notificaciones, 2 sin leer».
  • La lista se abre en un diálogo; Escape lo cierra.

Props

NotificationBellTipoPor defecto
itemsobligatorio NotificationEntry[]
label

Defaults to «Notifications».

string
onOpen ((id: string) => void)
onReadAll (() => void)
  1. Dos sin leer
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos