Descripción general de Web Components Toast
El Web Components Toast es un componente emergente súper ligero y pequeño que se utiliza para mostrar el contenido de un mensaje, notificando a los usuarios finales sobre el estado de un registro modificado. Puede colocar y mostrar fácilmente Web Components notificaciones del sistema en la parte inferior o en cualquier otra área especificada de la pantalla. O también puedes descartarlos de una manera sencilla y fácil.
El componente Web Components Toast se utiliza principalmente para la mensajería del sistema, las notificaciones push, los mensajes de advertencia y la información. No puede ser descartado por el usuario. Este control tiene diferentes características como efectos de animación, propiedad de tiempo de visualización para configurar cuánto tiempo está visible el componente de notificación del sistema, estilo y otros.
Web Components Toast Example
Echa un vistazo al ejemplo sencillo de Ignite UI for Web Components Toast a continuación. El mensaje de notificación animado aparece después de hacer clic en el botón.
How To Use Ignite UI for Web Components Toast Notification
En primer lugar, debe instalar el Ignite UI for Web Components ejecutando el siguiente comando:
npm install igniteui-webcomponents
import { defineComponents, IgcToastComponent } from 'igniteui-webcomponents';
defineComponents(IgcToastComponent);
Para una introducción completa al Ignite UI for Web Components, lee el tema Empezar.
The simplest way to display the toast component is to use its show method and call it on a button click.
<igc-button onclick="toast.show()" variant="contained">Show Toast</igc-button>
<igc-toast id="toast">Toast Message</igc-toast>
Examples
Properties
Use the displayTime property to configure how long the toast component is visible. By default, it's set to 4000 milliseconds.
By default, the toast component is hidden automatically after a period specified by the displayTime. You can use keepOpen property to change this behavior. In this way, the toast will remain visible.
<igc-button onclick="toast.toggle()" variant="contained">Toggle Toast</igc-button>
<igc-button onclick="toast.keepOpen = !toast.keepOpen" variant="contained">Toggle keepOpen property</igc-button>
<igc-button onclick="toast.displayTime = 8000" variant="contained">Set DisplayTime to 8000</igc-button>
<igc-toast id="toast">Toast Message</igc-toast>
Styling
You can style the Web Components IgcToastComponent notifications directly using its tag selector:
igc-toast {
background-color: var(--ig-primary-500);
color: var(--ig-primary-500-contrast);
}