aboutsummaryrefslogtreecommitdiff
path: root/site/content/docs/5.0/components/toasts.md
diff options
context:
space:
mode:
authorPatrick H. Lauke <[email protected]>2021-05-04 12:46:06 +0100
committerGitHub <[email protected]>2021-05-04 12:46:06 +0100
commit8865a8ab1c7157ab81bf49afa62b75f36daee46d (patch)
tree97ef78f2ea8e07aab50014176d061fe3c1d49134 /site/content/docs/5.0/components/toasts.md
parent018ee6a3b50b958ddb49657086cd9168abf5a485 (diff)
parent7ea6578773cb1b7f5cfb8fb41321b3fa10349daf (diff)
downloadbootstrap-jo-docs-thanks-page.tar.xz
bootstrap-jo-docs-thanks-page.zip
Merge branch 'main' into jo-docs-thanks-pagejo-docs-thanks-page
Diffstat (limited to 'site/content/docs/5.0/components/toasts.md')
-rw-r--r--site/content/docs/5.0/components/toasts.md168
1 files changed, 119 insertions, 49 deletions
diff --git a/site/content/docs/5.0/components/toasts.md b/site/content/docs/5.0/components/toasts.md
index be368c76e..57bcd319b 100644
--- a/site/content/docs/5.0/components/toasts.md
+++ b/site/content/docs/5.0/components/toasts.md
@@ -13,7 +13,6 @@ Toasts are lightweight notifications designed to mimic the push notifications th
Things to know when using the toast plugin:
- Toasts are opt-in for performance reasons, so **you must initialize them yourself**.
-- **Please note that you are responsible for positioning toasts.**
- Toasts will automatically hide if you do not specify `autohide: false`.
{{< callout info >}}
@@ -42,9 +41,49 @@ 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. For browsers that support the `backdrop-filter` CSS property, we'll also attempt to blur the elements under a toast.
+Toasts are slightly translucent, too, so they blend over whatever they might appear over.
{{< example class="bg-dark" >}}
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
@@ -62,30 +101,32 @@ Toasts are slightly translucent, too, so they blend over whatever they might app
### Stacking
-When you have multiple toasts, we default to vertically stacking them in a readable manner.
+You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.
{{< example class="bg-light" >}}
-<div class="toast" 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 class="text-muted">just now</small>
- <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
- </div>
- <div class="toast-body">
- See? Just like this.
+<div class="toast-container">
+ <div class="toast" 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 class="text-muted">just now</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ See? Just like this.
+ </div>
</div>
-</div>
-<div class="toast" 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 class="text-muted">2 seconds ago</small>
- <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
- </div>
- <div class="toast-body">
- Heads up, toasts will stack automatically
+ <div class="toast" 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 class="text-muted">2 seconds ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Heads up, toasts will stack automatically
+ </div>
</div>
</div>
{{< /example >}}
@@ -95,11 +136,13 @@ When you have multiple toasts, we default to vertically stacking them in a reada
Customize your toasts by removing sub-components, tweaking with [utilities]({{< docsref "/utilities/api" >}}), or adding your own markup. Here we've created a simpler toast by removing the default `.toast-header`, adding a custom hide icon from [Bootstrap Icons]({{< param icons >}}), and using some [flexbox utilities]({{< docsref "/utilities/flex" >}}) to adjust the layout.
{{< example class="bg-light" >}}
-<div class="toast d-flex align-items-center" role="alert" aria-live="assertive" aria-atomic="true">
- <div class="toast-body">
+<div class="toast align-items-center" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="d-flex">
+ <div class="toast-body">
Hello, world! This is a toast message.
+ </div>
+ <button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
- <button type="button" class="btn-close ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
{{< /example >}}
@@ -119,14 +162,16 @@ Alternatively, you can also add additional controls and components to toasts.
### Color schemes
-Building on the above example, you can create different toast color schemes with our [color utilities]({{< docsref "/utilities/colors" >}}). Here we've added `.bg-primary` and `.text-white` to the `.toast`, and then added `.text-white` to our close button. For a crisp edge, we remove the default border with `.border-0`.
+Building on the above example, you can create different toast color schemes with our [color]({{< docsref "/utilities/colors" >}}) and [background]({{< docsref "/utilities/background" >}}) utilities. Here we've added `.bg-primary` and `.text-white` to the `.toast`, and then added `.btn-close-white` to our close button. For a crisp edge, we remove the default border with `.border-0`.
{{< example class="bg-light" >}}
-<div class="toast d-flex align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
- <div class="toast-body">
- Hello, world! This is a toast message.
+<div class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="d-flex">
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+ <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
- <button type="button" class="btn-close btn-close-white ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
{{< /example >}}
@@ -134,17 +179,35 @@ Building on the above example, you can create different toast color schemes with
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.
-{{< example class="bg-dark" >}}
-<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;">
- <div class="toast" style="position: absolute; top: 0; right: 0;">
- <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.
+{{< example >}}
+<form>
+ <div class="mb-3">
+ <label for="selectToastPlacement">Toast placement</label>
+ <select class="form-select mt-2" id="selectToastPlacement">
+ <option value="" selected>Select a position...</option>
+ <option value="top-0 start-0">Top left</option>
+ <option value="top-0 start-50 translate-middle-x">Top center</option>
+ <option value="top-0 end-0">Top right</option>
+ <option value="top-50 start-0 translate-middle-y">Middle left</option>
+ <option value="top-50 start-50 translate-middle">Middle center</option>
+ <option value="top-50 end-0 translate-middle-y">Middle right</option>
+ <option value="bottom-0 start-0">Bottom left</option>
+ <option value="bottom-0 start-50 translate-middle-x">Bottom center</option>
+ <option value="bottom-0 end-0">Bottom right</option>
+ </select>
+ </div>
+</form>
+<div aria-live="polite" aria-atomic="true" class="bg-dark position-relative bd-example-toasts">
+ <div class="toast-container position-absolute p-3" id="toastPlacement">
+ <div class="toast">
+ <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>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
</div>
</div>
</div>
@@ -152,10 +215,13 @@ Place toasts with custom CSS as you need them. The top right is often used for n
For systems that generate more notifications, consider using a wrapping element so they can easily stack.
-{{< example class="bg-dark" >}}
-<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;">
- <!-- Position it -->
- <div style="position: absolute; top: 0; right: 0;">
+{{< example class="bg-dark bd-example-toasts p-0" >}}
+<div aria-live="polite" aria-atomic="true" class="position-relative">
+ <!-- Position it: -->
+ <!-- - `.toast-container` for spacing between toasts -->
+ <!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner -->
+ <!-- - `.p-3` to prevent the toasts from sticking to the edge of the container -->
+ <div class="toast-container position-absolute top-0 end-0 p-3">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
@@ -187,9 +253,9 @@ For systems that generate more notifications, consider using a wrapping element
You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.
-{{< example class="bg-dark" >}}
+{{< example class="bg-dark bd-example-toasts d-flex" >}}
<!-- Flexbox container for aligning the toasts -->
-<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center" style="min-height: 200px;">
+<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center w-100">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
@@ -238,9 +304,13 @@ When using `autohide: false`, you must add a close button to allow users to dism
</div>
{{< /example >}}
-## JavaScript behavior
+## Sass
+
+### Variables
+
+{{< scss-docs name="toast-variables" file="scss/_variables.scss" >}}
-### Usage
+## Usage
Initialize toasts via JavaScript: