aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src/components/GlobalNotificationBanner.tsx
blob: b0a06f7e1def7e5ca21532005dac4126a4f795a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Fragment, VNode, h } from "preact"
import { Attention, GLOBAL_NOTIFICATION_TIMEOUT, useNotifications } from "../index.browser.js"

export function GlobalNotificationsBanner(): VNode {
  const notifs = useNotifications()
  if (notifs.length === 0) return <Fragment />
  return <Fragment> {
    notifs.map(n => {
      switch (n.message.type) {
        case "error":
          return <Attention type="danger" title={n.message.title} onClose={() => {
            n.remove()
          }} timeout={GLOBAL_NOTIFICATION_TIMEOUT}>
            {n.message.description &&
              <div class="mt-2 text-sm text-red-700">
                {n.message.description}
              </div>
            }
          </Attention>
        case "info":
          return <Attention type="success" title={n.message.title} onClose={() => {
            n.remove();
          }} timeout={GLOBAL_NOTIFICATION_TIMEOUT} />
      }
    })}
  </Fragment>
}