(
children: string,
variant: SpectrumToastValue['variant'],
options: ToastOptions = {}
)
| 116 | } |
| 117 | |
| 118 | function addToast( |
| 119 | children: string, |
| 120 | variant: SpectrumToastValue['variant'], |
| 121 | options: ToastOptions = {} |
| 122 | ) { |
| 123 | let value = { |
| 124 | children, |
| 125 | variant, |
| 126 | actionLabel: options.actionLabel, |
| 127 | onAction: options.onAction, |
| 128 | shouldCloseOnAction: options.shouldCloseOnAction, |
| 129 | ...filterDOMProps(options) |
| 130 | }; |
| 131 | |
| 132 | // Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible |
| 133 | // Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1. |
| 134 | // It is debatable whether non-actionable toasts would also fail. |
| 135 | let timeout = |
| 136 | options.timeout && !options.actionLabel ? Math.max(options.timeout, 5000) : undefined; |
| 137 | let queue = getGlobalToastQueue(); |
| 138 | let key = queue.add(value, {timeout, onClose: options.onClose}); |
| 139 | return () => queue.close(key); |
| 140 | } |
| 141 | |
| 142 | type CloseFunction = () => void; |
| 143 |
no test coverage detected