blob: 2424b17ff76f7027d5eb76b64f334bac4a4abfce (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import { Fragment, VNode, h } from "preact"
import { Attention, GLOBAL_NOTIFICATION_TIMEOUT as GLOBAL_TOAST_TIMEOUT, useNotifications } from "../index.browser.js"
/**
* Toasts should be considered when displaying these types of information to the user:
*
* Low attention messages that do not require user action
* Singular status updates
* Confirmations
* Information that does not need to be followed up
*
* Do not use toasts if the information contains the following:
*
* High attention and crtitical information
* Time-sensitive information
* Requires user action or input
* Batch updates
*
* @returns
*/
export function ToastBanner(): 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_TOAST_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_TOAST_TIMEOUT} />
}
})}
</Fragment>
}
|