The <message-card>
element provides the notify()
and prepare()
functions for dynamically managing messages. These functions automatically handle establishing a timeout for the message, showing progress for that timeout, and removing the element from the DOM when the timeout has completed.
Timeouts are managed by the <message-card>
element's duration
attribute. Any value above zero will be used as the milliseconds for the notification to be displayed before being removed. This may be done directly in the HTML, but the prepare()
and notify()
functions manage those timeouts, directly.
Timeout progress is tracked by the progress bar along the bottom of th <message-card>
element. When the element has focus, or is being hovered over, the progress will be paused.
The prepare()
function is used to add a <message-card>
element to a parent element. It requires a message parameter and the parent element that it will append the message to as a parameter. It can also accept an options parameter for defining things like the <message-card>
element's duration, heading, and type.
The notify()
function provides a convenient way to prepare a <message-card>
element and open it at the same time.
To make it easier to use customized <message-card>
elements, the notify()
and prepare()
functions can accept a <message-card>
element as their first parameter, rather than a message string
. The same events and functionality will apply to the provided <message-card>
element. The only difference will be that the custom-defined <message-card>
element will be used, rather than simply injecting a message into the default <message-card>
element structure.
In this example, each button will add a new <message-card>
element to the DOM.