Toast
Toast Notify Service
Description
A toast notification is a user interface element that typically appears as a small popup with text, an image, or a button. They are suitable for conveying information that doesn't demand much user attention.
toastSuccess(messages, position?)
- 🧱 Purpose: Displays a styled success toast with dynamic duration based on message length.
- 📌 Parameters:
messages(Array or Object): A list of success messages to show.position(String, optional): Location on screen where the toast will appear (default:"top-center").
- ⚙️ Behavior:
- Formats the message using
getMessageHtml. - Calculates how long the toast should stay visible using
getMessageDuration. - Renders HTML-based toast using
vue3-toastifywith a "success" type.
- Formats the message using
toastErrors(errors, position?)
- 🧱 Purpose: Displays an
error toastwith multiple error messages andlogsthe error. - 📌 Parameters:
errors (Array or Object): Error messages to be shown.position (String, optional): Position of the toast (default:"top-center").
- ⚙️ Behavior:
- Converts messages to formatted HTML via
getMessageHtml. - Duration dynamically calculated through
getMessageDuration. - Displays an
"error"typetoast. - Logs the error using
trackError.
- Converts messages to formatted HTML via
getMessageHtml(messages)
- 🧱 Purpose: Converts a list of messages into a single HTML-formatted string for toast rendering.
- 📌 Parameters:
messages (Array or Object): Collection of messages to be displayed.
- ⚙️ Behavior:
- If multiple messages exist, they are rendered as a numbered list with
<br/>separators. - If a single message exists, it is returned without formatting.
getMessageDuration(message_html)
- 🧱 Purpose: Dynamically determines how long the toast should remain visible.
- 📌 Parameters:
messages (String): The final formatted message string.
- ⚙️ Behavior:
- Counts total characters in the message.
- Uses the formula:
(message length / 10 readable chars/sec) * 3000msto set duration. - Ensures longer messages have sufficient reading time.