dao-game / peerjs-browser-bug / files / src / snackbar.ts
Branch peerjs-browser-bug · default branch · all branches
snackbar.ts
e46456c2 2022-03-22 Pavel Safronov | 1 | import { poly_animate } from "./animate"; |
5648264d 2022-03-22 Pavel Safronov | 2 | import { delay } from "./utils"; |
| 3 | ||
| 4 | export async function showSnackbar( | |
| 5 | text: string, | |
| 6 | fadeDurationMs: number = 500, | |
| 7 | showDurationMs: number = 3000) { | |
| 8 | ||
| 9 | const div = document.createElement('div'); | |
| 10 | div.id = 'snackbar'; | |
| 11 | div.classList.add('info'); | |
| 12 | div.classList.add('show'); | |
| 13 | div.innerText = text; | |
| 14 | document.body.appendChild(div); | |
| 15 | ||
| 16 | const invisibleKeyframe = { | |
| 17 | opacity: 0, | |
| 18 | bottom: '0px' | |
| 19 | }; | |
| 20 | const visibleKeyframe = { | |
| 21 | opacity: 1, | |
| 22 | bottom: '30px' | |
| 23 | }; | |
| 24 | const options = { duration: fadeDurationMs, iterations: 1 }; | |
e46456c2 2022-03-22 Pavel Safronov | 25 | await poly_animate(div, [invisibleKeyframe, visibleKeyframe], options); |
5648264d 2022-03-22 Pavel Safronov | 26 | await delay(showDurationMs); |
e46456c2 2022-03-22 Pavel Safronov | 27 | await poly_animate(div, [visibleKeyframe, invisibleKeyframe], options); |
5648264d 2022-03-22 Pavel Safronov | 28 | div.parentNode.removeChild(div); |
| 29 | } |