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:
14
libs/components/src/toast/utils.ts
Normal file
14
libs/components/src/toast/utils.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user