From 696996dd4f5b7319413655b9134ca2f3768c2549 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Tue, 29 Jun 2021 08:46:25 -0700 Subject: Add dynamic, live alerts example to docs (#33866) --- site/content/docs/5.0/components/alerts.md | 39 ++++++++++++++++++++++++++++++ site/content/docs/5.0/components/toasts.md | 16 +++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'site/content/docs') diff --git a/site/content/docs/5.0/components/alerts.md b/site/content/docs/5.0/components/alerts.md index 51feb966ed..e3862de483 100644 --- a/site/content/docs/5.0/components/alerts.md +++ b/site/content/docs/5.0/components/alerts.md @@ -23,6 +23,45 @@ Alerts are available for any length of text, as well as an optional close button {{< partial "callout-warning-color-assistive-technologies.md" >}} {{< /callout >}} +### Live example + +Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button. + +
+ +
+ +
+ +```html + + + +``` + +We use the following JavaScript to trigger our live alert demo: + +```js +var alertPlaceholder = document.getElementById('liveAlertPlaceholder') +var alertTrigger = document.getElementById('liveAlertBtn') + +function alert(message, type) { + var wrapper = document.createElement('div') + wrapper.innerHTML = '' + + alertPlaceholder.append(wrapper) +} + +if (alertTrigger) { + alertTrigger.addEventListener('click', function () { + alert('Nice, you triggered this alert message!', 'success') + }) +} +``` + ### Link color Use the `.alert-link` utility class to quickly provide matching colored links within any alert. diff --git a/site/content/docs/5.0/components/toasts.md b/site/content/docs/5.0/components/toasts.md index 2dde09f5ba..8017ecdcd4 100644 --- a/site/content/docs/5.0/components/toasts.md +++ b/site/content/docs/5.0/components/toasts.md @@ -41,7 +41,7 @@ Toasts are as flexible as you need and have very little required markup. At a mi {{< /example >}} -### Live +### Live example Click the button below to show a toast (positioned with our utilities in the lower right corner) that has been hidden by default with `.hide`. @@ -81,6 +81,20 @@ Click the button below to show a toast (positioned with our utilities in the low ``` +We use the following JavaScript to trigger our live toast demo: + +```js +var toastTrigger = document.getElementById('liveToastBtn') +var toastLiveExample = document.getElementById('liveToast') +if (toastTrigger) { + toastTrigger.addEventListener('click', function () { + var toast = new bootstrap.Toast(toastLiveExample) + + toast.show() + }) +} +``` + ### Translucent Toasts are slightly translucent to blend in with what's below them. -- cgit v1.2.3