Alert
Alerts display short-lived important information to the user, usually at the top or bottom of the screen.
<script setup lang="ts">import { VAlert } from '@vonage/vivid-api-vue';</script>
<template> <VAlert text="Some important information for you" open /></template>import { registerAlert } from '@vonage/vivid-api';
registerAlert('your-prefix');<script type="module"> import { registerAlert } from '@vonage/vivid-api'; registerAlert('your-prefix');</script>
<your-prefix-alert text="Some important information for you" open></your-prefix-alert>Use the open attribute to toggle the Alert open state.
<script setup lang="ts">import { VAlert, VButton } from '@vonage/vivid-api-vue';import { ref } from 'vue';
const open = ref(false);</script>
<template> <VAlert text="An important information for you" :open="open" /> <VButton appearance="outlined" label="Show/Hide alert" @click="open = !open" /></template><vwc-alert text="Some important information for you"></vwc-alert>
<vwc-button appearance="outlined" label="Show/Hide Alert" onclick="toggleAlert()"></vwc-button>
<script> alert = document.querySelector('vwc-alert'); function toggleAlert() { alert.open = !alert.open; }</script>Use the timeoutms attribute to set the time in milliseconds after which the Alert will automatically close.
The default value is 0, which means the Alert will not close automatically.
<script setup lang="ts">import { VAlert, VButton } from '@vonage/vivid-api-vue';import { ref } from 'vue';
const open = ref(false);</script>
<template> <VAlert text="An important information for you" :open="open" timeoutms="2000" /> <VButton appearance="outlined" label="Show an Alert for 2 seconds" @click="open = true" /></template><vwc-alert text="Some important information for you" timeoutms="2000"></vwc-alert>
<vwc-button appearance="outlined" label="Show an Alert for 2 seconds" onclick="openAlert()"></vwc-button>
<script> alert = document.querySelector('vwc-alert'); function openAlert() { alert.open = true; }</script>The strategy attribute controls the position strategy of the Alert. The default is fixed, which will position the Alert relative to the viewport.
When set to static, placement will have no effect, and the Alert will behave as an element in page flow.
<script setup lang="ts">import { VAlert } from '@vonage/vivid-api-vue';</script>
<template> <p>Content above</p> <VAlert strategy="static" text="This Alert has position set to static" open /> <p>Content below</p></template><p>Content above</p><vwc-alert strategy="static" text="This Alert has position set to static" open></vwc-alert><p>Content below</p>If you want to add rich content to an Alert, you can use the main slot.
<script setup lang="ts">import { VAlert, VSwitch } from '@vonage/vivid-api-vue';</script>
<template> <VAlert open> <template #main> <VSwitch label="Do not show more Alerts" /> </template> </VAlert></template><vwc-alert open> <vwc-switch slot="main" label="Do not show more Alerts"></vwc-switch></vwc-alert>You can add action items elements using the action-items slot. They will be displayed at the inline-end of the Alert.
<script setup lang="ts">import { VAlert, VButton } from '@vonage/vivid-api-vue';</script>
<template> <VAlert text="Some important information for you" open> <template #action-items> <VButton label="Action" appearance="outlined" shape="pill" /> </template> </VAlert></template><vwc-alert text="Some important information for you" open> <vwc-button slot="action-items" appearance="outlined" shape="pill" label="Action"></vwc-button></vwc-alert>Set the icon slot to add an icon to the Alert. If set, the icon attribute (deprecated) is ignored.
<script setup lang="ts">import { VAlert, VIcon } from '@vonage/vivid-api-vue';</script>
<template> <VAlert text="Some important information for you" open> <template #icon> <VIcon name="megaphone-solid" connotation="cta" label="Announcement:" /> </template> </VAlert></template><vwc-alert text="Some important information for you" open> <vwc-icon slot="icon" name="megaphone-solid" connotation="cta" label="Announcement:"></vwc-icon></vwc-alert>Use the --alert-min-inline-size variable to set the Alert’s minimum inline size. The default value is 420px.
<script setup lang="ts">import { VAlert } from '@vonage/vivid-api-vue';</script>
<template> <VAlert style="--alert-min-inline-size: auto" text="Very fitting!" open /></template><vwc-alert style="--alert-min-inline-size: auto" text="Very fitting!" open></vwc-alert>Use the --alert-max-inline-size variable to set the Alert’s maximum inline size.
This is helpful to prevent the Alert from becoming too wide when displaying a long message.
The default value is fit-content, which allows the Alert to grow as needed.
<script setup lang="ts">import { VAlert } from '@vonage/vivid-api-vue';</script>
<template> <VAlert style="--alert-max-inline-size: 300px;" text="This text is very long and will wrap to the next line." open /></template><vwc-alert style="--alert-max-inline-size: 300px;" text="This text is very long and will wrap to the next line." open></vwc-alert>| Property | Type | Default | Description |
|---|---|---|---|
| connotation | 'accent' | 'success' | 'alert' | 'warning' | 'information' | 'announcement' | Sets an appropriate icon / icon color for the connotation. | |
| dismissButtonAriaLabel | string | Allows setting a custom aria-label for the dismiss button. | |
| headline | string | Adds a headline to the Alert. | |
| open | boolean | Open state of the Alert. | |
| placement | 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | The placement of the Alert on the screen. | |
| removable | boolean | Adds a close button to the Alert. | |
| strategy | 'fixed' | 'static' | Controls the `position` of the Alert. | |
| text | string | The main text of the Alert. | |
| timeoutms | number | Timeout after which the Alert will close. |
| Property | Type | Default | Description |
|---|---|---|---|
| connotation | 'accent' | 'success' | 'alert' | 'warning' | 'information' | 'announcement' | Sets an appropriate icon / icon color for the connotation. | |
| dismiss-button-aria-label | string | Allows setting a custom aria-label for the dismiss button. | |
| headline | string | Adds a headline to the Alert. | |
| open | boolean | Open state of the Alert. | |
| placement | 'top' | 'bottom' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | The placement of the Alert on the screen. | |
| removable | boolean | Adds a close button to the Alert. | |
| strategy | 'fixed' | 'static' | Controls the `position` of the Alert. | |
| text | string | The main text of the Alert. | |
| timeoutms | number | Timeout after which the Alert will close. |
| Name | Description |
|---|---|
| action-items | Add action items to the Alert using this slot. |
| icon | The preferred way to add an icon to the component. |
| main | The main content of the Alert. |
| Name | Description |
|---|---|
| action-items | Add action items to the Alert using this slot. |
| icon | The preferred way to add an icon to the component. |
| main | The main content of the Alert. |
| Name | Type | Description |
|---|---|---|
| close | CustomEvent<undefined> | Fired when the Alert is closed |
| open | CustomEvent<undefined> | Fired when the Alert is opened |
| Name | Type | Description |
|---|---|---|
| close | CustomEvent<undefined> | Fired when the Alert is closed |
| open | CustomEvent<undefined> | Fired when the Alert is opened |