xref: /openbmc/webui-vue/docs/guide/components/toasts/index.md (revision 7385e139b0c9efca7430458cee982e63e282f4ae)
1f6df801bSDerick Montague# Toasts
2*7385e139SPatrick Williams
349287562SDerick MontagueUse a toast message to indicate the status of a user action. For example, a user
449287562SDerick Montaguesaves a form successfully, a toast message with the `success` variant is
549287562SDerick Montaguedisplayed. If the user action was not successful, a toast message with the
649287562SDerick Montague`danger` variant is displayed.
7f6df801bSDerick Montague
849287562SDerick MontagueThere are different transitions for the toast messages. The `success` toast
949287562SDerick Montaguemessage will auto-hide after 10 seconds. The user must manually dismiss the
1049287562SDerick Montague`informational`, `warning`, and `error` toast messages. The `BVToastMixin`
1149287562SDerick Montagueprovides a simple API that generates a toast message that meets the transition
1249287562SDerick Montagueguidelines.
13f6df801bSDerick Montague
14f6df801bSDerick Montague<img src="./toast.png" alt="Toast message examples" style="max-width:350px">
15f6df801bSDerick Montague
16f6df801bSDerick Montague```js{5}
17f6df801bSDerick Montague// Sample method from Reboot BMC page
18f6df801bSDerick MontaguerebootBmc() {
19f6df801bSDerick Montague  this.$store
20f6df801bSDerick Montague  .dispatch('controls/rebootBmc')
21f6df801bSDerick Montague  .then(message => this.successToast(message))
22f6df801bSDerick Montague  .catch(({ message }) => this.errorToast(message));
23f6df801bSDerick Montague}
24f6df801bSDerick Montague
25f6df801bSDerick Montague// Methods used in this example
26f6df801bSDerick Montaguemethods: {
27f6df801bSDerick Montague  makeSuccessToast() {
28f6df801bSDerick Montague    this.successToast('This is a success toast and will be dismissed after 10 seconds.');
29f6df801bSDerick Montague  },
30f6df801bSDerick Montague  makeErrorToast() {
31f6df801bSDerick Montague    this.errorToast('This is an error toast and must be dismissed by the user.');
32f6df801bSDerick Montague  },
33f6df801bSDerick Montague  makeWarningToast() {
34f6df801bSDerick Montague    this.warningToast('This is a warning toast and must be dismissed by the user.');
35f6df801bSDerick Montague  },
36f6df801bSDerick Montague  makeInfoToast() {
37f6df801bSDerick Montague    this.infoToast('This is an info toast and must be dismissed by the user.');
38f6df801bSDerick Montague  },
39f6df801bSDerick Montague}
40f6df801bSDerick Montague```
41b607152cSYoshie Muranaka
42b607152cSYoshie Muranaka## Additional options
43b607152cSYoshie Muranaka
4449287562SDerick MontagueThe first argument for each method will be the toast body content. It accepts a
4549287562SDerick Montaguestring value or an array of strings for toasts needing to display multiple lines
4649287562SDerick Montagueof content.
47b607152cSYoshie Muranaka
4849287562SDerick MontagueThe BVToastMixin also accepts additional options as a second argument. Pass an
4949287562SDerick Montagueobject with a `title` property to change the default toast title. Include a
5049287562SDerick Montague`refreshAction` property, set to true, to include a link that refreshes the
5149287562SDerick Montagueapplication. Include a `timestamp` property, set to true, to include a timestamp
5249287562SDerick Montaguein the toast.
53b607152cSYoshie Muranaka
5449287562SDerick Montague<img src="./toast-options.png" alt="Toast message options example"
5549287562SDerick Montaguestyle="max-width:350px">
56b607152cSYoshie Muranaka
57b607152cSYoshie Muranaka```js
58b607152cSYoshie Muranaka
59b607152cSYoshie Muranakamethods: {
60b607152cSYoshie Muranaka  makeInfoToast() {
61b607152cSYoshie Muranaka    this.infoToast([
62b607152cSYoshie Muranaka      'This is a toast with multi-lined body content.',
63b607152cSYoshie Muranaka      'Just pass an array of strings!'
64b607152cSYoshie Muranaka      ], {
65b607152cSYoshie Muranaka      title: 'This is an example',
66b607152cSYoshie Muranaka      refreshAction: true,
67b607152cSYoshie Muranaka      timestamp: true
68b607152cSYoshie Muranaka    })
69b607152cSYoshie Muranaka  }
70b607152cSYoshie Muranaka}
71b607152cSYoshie Muranaka```
72