Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a live toast example to the docs #32760

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion site/assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
})
}

document.querySelectorAll('.toast')
document.querySelectorAll('.bd-example .toast')
XhmikosR marked this conversation as resolved.
Show resolved Hide resolved
.forEach(function (toastNode) {
var toast = new bootstrap.Toast(toastNode, {
autohide: false
Expand All @@ -48,6 +48,16 @@
toast.show()
})

var toastTrigger = document.getElementById('liveToastBtn')
var toastLiveExample = document.getElementById('liveToast')
if (toastTrigger) {
toastTrigger.addEventListener('click', function () {
var toast = new bootstrap.Toast(toastLiveExample)

toast.show()
})
}

// Demos within modals
document.querySelectorAll('.tooltip-test')
.forEach(function (tooltip) {
Expand Down
40 changes: 40 additions & 0 deletions site/content/docs/5.0/components/toasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,46 @@ Toasts are as flexible as you need and have very little required markup. At a mi
</div>
{{< /example >}}

### Live

Click the button the below to show as toast (positioning with our utilities in the lower right corner) that has been hidden by default with `.hide`.

<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 5">
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
{{< placeholder width="20" height="20" background="#007aff" class="rounded me-2" text="false" title="false" >}}
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>

<div class="bd-example">
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
</div>

```html
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>

<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 5">
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
```

### Translucent

Toasts are slightly translucent, too, so they blend over whatever they might appear over.
Expand Down