1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[CL-18] toast component and service (#6490)

Update toast styles and new service to CL.
This commit is contained in:
Will Martin
2024-04-18 13:23:35 -04:00
committed by GitHub
parent 9277465951
commit d5f503a0d6
32 changed files with 440 additions and 534 deletions

View File

@@ -0,0 +1,14 @@
/**
* Given a toast message, calculate the ideal timeout length following:
* a minimum of 5 seconds + 1 extra second per 120 additional words
*
* @param message the toast message to be displayed
* @returns the timeout length in milliseconds
*/
export const calculateToastTimeout = (message: string | string[]): number => {
const paragraphs = Array.isArray(message) ? message : [message];
const numWords = paragraphs
.map((paragraph) => paragraph.split(/\s+/).filter((word) => word !== ""))
.flat().length;
return 5000 + Math.floor(numWords / 120) * 1000;
};