import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks'; import useAlertContent from './usealert.html' # useAlert **useAlert** is accessible through `window.Theme.components.useAlert`. ## Concept The alert container is the default notifications container of the theme, you can use another one specifying the selector option. The toast markup is generated on the fly by the javascript, based on bootstrap. ## Parameters **text** (Optional): string; **options** (Optional): Options; ## Options **type**: 'light' | 'dark' | 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger' **icon** (Optional): string; **title** (Optional): string; **dismissible** (Optional): boolean; **classlist** (Optional): string; **selector** (Optional): string; ## Return useAlert return an Object, here is the definition: ```ts interface Instance { instance: Alert | null; element: HTMLElement | null; show: () => boolean; hide: () => boolean; dispose: () => boolean; remove: () => boolean; title: (markup?: string) => string | boolean; message: (markup?: string) => string | boolean; } ``` ### Examples (only testable inside the Canvas tab) Overall destructuring is a good practice, if you can, use it! Without any options: { const btn = document.querySelector('.btn'); btn.addEventListener('click', () => { const {show} = window.Theme.components.useAlert('Lorem ipsum sit dolor amet'); show(); }); }} > {() => useAlertContent} Without a different colorscheme: ```js const {show} = window.Theme.components.useAlert('Lorem ipsum sit dolor amet', {type: 'primary'}); show(); ``` { const btn = document.querySelector('.btn'); btn.addEventListener('click', () => { const {show} = window.Theme.components.useAlert('Lorem ipsum sit dolor amet', {type: 'primary'}); show(); }); }} > {() => useAlertContent}