This alert will automatically hide itself after three seconds, unless you interact with it.
</OdsAlert>
</div>
<style>{css}</style>
</>
)
}
exportdefaultExample;
Toast Notifications
To display an alert as a toast notification, or “toast”, create the alert and call its toast() method. This will move the alert out of its position in the DOM and into the toast stack where it will be shown. Once dismissed, it will be removed from the DOM completely. To reuse a toast, store a reference to it and call toast() again later on.
You should always use the closable attribute so users can dismiss the notification. It’s also common to set a reasonable duration when the notification doesn’t require acknowledgement.
InfoSuccessWarningErrorThis is super informative
You can tell by how pretty the alert is.
Your changes have been saved
You can safely exit the app now.
Your session has ended
Please login again to continue.
An error occured while updating
Update your details and try again!
For convenience, you can create a utility that emits toast notifications with a function call rather than composing them in your HTML. To do this, generate the alert with JavaScript, append it to the body, and call the toast() method as shown in the example below.
The toast stack is a fixed position singleton element created and managed internally by the alert component. It will be added and removed from the DOM as needed when toasts are shown. When more than one toast is visible, they will stack vertically in the toast stack.
By default, the toast stack is positioned at the bottom-right of the viewport. You can change its position by targeting .ods-toast-stack in your stylesheet. To make toasts appear at the top-left of the viewport, for example, use the following styles.
Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.
This component is still in development and cannot be imported at this time.
Slots
Name
Description
(default)
The alert's main content.
icon
An icon to show in the alert. Works best with `<ods-icon>`.
Properties
Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.
Emitted after the alert opens and all animations are complete.
--
ods-hide
Emitted when the alert closes.
--
ods-after-hide
Emitted after the alert closes and all animations are complete.
--
Methods
Name
Description
Arguments
show()
Shows the alert.
--
hide()
Hides the alert
--
toast()
Displays the alert as a toast notification. This will move the alert out of its position in the DOM and, when
dismissed, it will be removed from the DOM completely. By storing a reference to the alert, you can reuse it by
calling this method again. The returned promise will resolve after the alert is hidden.
--
Parts
Name
Description
base
The component's base wrapper.
icon
The container that wraps the optional icon.
message
The container that wraps the alert's main content.
close-button
The close button, an `<ods-icon-button>`.
close-button__base
The close button's exported `base` part.
Dependencies
This component automatically imports the following dependencies.
ods-icon
ods-icon-button
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
Trigger an alert when a user takes an action and needs a confirmation that the action succeeded or didn’t, and why.
Consider placement of the Alert - the default stack position is bottom right, but they can also be placed within the interface, like above a form or within a card.
Add an Alert Title if needed but it is not necessary to add one if the message itself is easily understood and scannable
Dont
Use Alerts to notify user of a new message or other low-priority background information, unless customization options allow for this.
Place an alert within the interface in a position that causes baseline shifts to other elements - i.e., place the alert at the top or bottom of a form, not in between inputs.
Add actions into the Alert other than the close action. If the alert requires an action from the user, consider a dialog instead.
Replace the standard status-based icons with custom alternatives
Use an alert as an alternative to inline error messaging on inputs
Content Guidelines
Alerts communicate important information to the user and should be as clear and concise as possible to convey the information with little ambiguity or confusion.
Get to the point, don’t pad the message with too much fluff
Do
Changes saved successfully!
Dont
Hey there Doctor Smith, just wanted to let you know that the changes you made were successful. Have a nice day!