mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-21 12:51:52 +02:00
Add dynamic, live alerts example to docs (#33866)
This commit is contained in:
@@ -58,6 +58,22 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var alertPlaceholder = document.getElementById('liveAlertPlaceholder')
|
||||||
|
var alertTrigger = document.getElementById('liveAlertBtn')
|
||||||
|
|
||||||
|
function alert(message, type) {
|
||||||
|
var wrapper = document.createElement('div')
|
||||||
|
wrapper.innerHTML = '<div class="alert alert-' + type + ' alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'
|
||||||
|
|
||||||
|
alertPlaceholder.append(wrapper)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alertTrigger) {
|
||||||
|
alertTrigger.addEventListener('click', function () {
|
||||||
|
alert('Nice, you triggered this alert message!', 'success')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Demos within modals
|
// Demos within modals
|
||||||
document.querySelectorAll('.tooltip-test')
|
document.querySelectorAll('.tooltip-test')
|
||||||
.forEach(function (tooltip) {
|
.forEach(function (tooltip) {
|
||||||
|
@@ -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" >}}
|
{{< partial "callout-warning-color-assistive-technologies.md" >}}
|
||||||
{{< /callout >}}
|
{{< /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.
|
||||||
|
|
||||||
|
<div id="liveAlertPlaceholder"></div>
|
||||||
|
|
||||||
|
<div class="bd-example">
|
||||||
|
<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
```html
|
||||||
|
<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
|
||||||
|
|
||||||
|
<div class="alert alert-primary alert-dismissible" role="alert" id="liveAlert">
|
||||||
|
<strong>Nice!</strong> You've triggered this alert.
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
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 = '<div class="alert alert-' + type + ' alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'
|
||||||
|
|
||||||
|
alertPlaceholder.append(wrapper)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alertTrigger) {
|
||||||
|
alertTrigger.addEventListener('click', function () {
|
||||||
|
alert('Nice, you triggered this alert message!', 'success')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Link color
|
### Link color
|
||||||
|
|
||||||
Use the `.alert-link` utility class to quickly provide matching colored links within any alert.
|
Use the `.alert-link` utility class to quickly provide matching colored links within any alert.
|
||||||
|
@@ -41,7 +41,7 @@ Toasts are as flexible as you need and have very little required markup. At a mi
|
|||||||
</div>
|
</div>
|
||||||
{{< /example >}}
|
{{< /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`.
|
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
|
|||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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
|
### Translucent
|
||||||
|
|
||||||
Toasts are slightly translucent to blend in with what's below them.
|
Toasts are slightly translucent to blend in with what's below them.
|
||||||
|
Reference in New Issue
Block a user