diff --git a/scss/_toasts.scss b/scss/_toasts.scss new file mode 100644 index 0000000000..248a212989 --- /dev/null +++ b/scss/_toasts.scss @@ -0,0 +1,29 @@ +.toast { + max-width: $toast-max-width; + overflow: hidden; // cheap rounded corners on nested items + font-size: $toast-font-size; // knock it down to 14px + background-color: $toast-background-color; + background-clip: padding-box; + border: $toast-border-width solid $toast-border-color; + border-radius: $toast-border-radius; + box-shadow: $toast-box-shadow; + backdrop-filter: blur(10px); + + + .toast { + margin-top: $toast-padding-x; + } +} + +.toast-header { + display: flex; + align-items: center; + padding: $toast-padding-y $toast-padding-x; + color: $toast-header-color; + background-color: $toast-header-background-color; + background-clip: padding-box; + border-bottom: $toast-border-width solid $toast-header-border-color; +} + +.toast-body { + padding: $toast-padding-x; // apply to both vertical and horizontal +} diff --git a/scss/_variables.scss b/scss/_variables.scss index c636860bda..ce958b3c42 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -3,7 +3,6 @@ // Variables should follow the `$component-state-property-size` formula for // consistent naming. Ex: $nav-link-disabled-color and $modal-content-box-shadow-xs. - // Color system $white: #fff !default; @@ -860,6 +859,22 @@ $popover-arrow-color: $popover-bg !default; $popover-arrow-outer-color: fade-in($popover-border-color, .05) !default; +// Toasts +$toast-max-width: 350px !default; +$toast-padding-x: .75rem !default; +$toast-padding-y: .25rem !default; +$toast-font-size: .875rem !default; +$toast-background-color: rgba($white, .85) !default; +$toast-border-width: 1px !default; +$toast-border-color: rgba(0,0,0,.1) !default; +$toast-border-radius: .25rem !default; +$toast-box-shadow: 0 .25rem .75rem rgba($black, .1) !default; + +$toast-header-color: $gray-600 !default; +$toast-header-background-color: rgba($white, .85) !default; +$toast-header-border-color: rgba(0, 0, 0, .05) !default; + + // Badges $badge-font-size: 75% !default; diff --git a/scss/bootstrap.scss b/scss/bootstrap.scss index 6f7e4eef15..c9795108c6 100644 --- a/scss/bootstrap.scss +++ b/scss/bootstrap.scss @@ -34,6 +34,7 @@ @import "media"; @import "list-group"; @import "close"; +@import "toasts"; @import "modal"; @import "tooltip"; @import "popover"; diff --git a/site/_data/nav.yml b/site/_data/nav.yml index cb0defd890..7b6ff7cd97 100644 --- a/site/_data/nav.yml +++ b/site/_data/nav.yml @@ -50,6 +50,7 @@ - title: Progress - title: Scrollspy - title: Spinners + - title: Toasts - title: Tooltips - title: Utilities diff --git a/site/docs/4.1/components/toasts.md b/site/docs/4.1/components/toasts.md new file mode 100644 index 0000000000..df5d2e827e --- /dev/null +++ b/site/docs/4.1/components/toasts.md @@ -0,0 +1,169 @@ +--- +layout: docs +title: Toasts +description: Push notifications to your visitors with a toast, a lightweight and easily customizable alert message. +group: components +toc: true +--- + +Toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They're built with flexbox, so they're easy to align and position. + +## Examples + +A basic toast can include a header (though it doesn't strictly need one) with whatever contents you like. The header is also `display: flex`, so `.mr-auto` and `.ml-auto` can be used for easy pushing of content, as well as all our flexbox utilities. + +<div class="bg-light"> +{% capture example %} +<div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small>11 mins ago</small> + </div> + <div class="toast-body"> + Hello, world! This is a toast message. + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div> + +They're slightly translucent, too, so they blend over whatever they might appear over. For browsers that support `backdrop-filter`, we'll also attempt to blur the elements under a toast. + +<div class="bg-dark"> +{% capture example %} +<div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small class="text-muted">11 mins ago</small> + </div> + <div class="toast-body"> + Hello, world! This is a toast message. + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div> + +Plus, they'll easily stack. + +<div class="bg-light"> +{% capture example %} +<div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small class="text-muted">just now</small> + </div> + <div class="toast-body"> + See? Just like this. + </div> +</div> + +<div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small class="text-muted">2 seconds ago</small> + </div> + <div class="toast-body"> + Heads up, toasts will stack automatically + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div> + +## Accessibility + +Toasts are intended to be small interruptions to your visitors or users, so to help those on screen readers, you should wrap your toasts in an [`aria-live` region](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions). This allows screen readers the ability to see suggested interruptions without any visual cues. + +{% highlight html %} +<div role="region" aria-live="polite"> + <div class="toast">...</div> +</div> +{% endhighlight %} + +## Placement + +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.` + +<div class="bg-dark"> +{% capture example %} +<div style="position: relative; min-height: 200px;"> + <div class="toast" style="position: absolute; top: 0; right: 0;"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small>11 mins ago</small> + </div> + <div class="toast-body"> + Hello, world! This is a toast message. + </div> + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div> + +For systems that generate more notifications, consider using a wrapping element so they can easily stack. + +<div class="bg-dark"> +{% capture example %} +<div style="position: relative; min-height: 200px;"> + <!-- Position it --> + <div style="position: absolute; top: 0; right: 0;"> + + <!-- Then put toasts within --> + <div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small class="text-muted">just now</small> + </div> + <div class="toast-body"> + See? Just like this. + </div> + </div> + + <div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small class="text-muted">2 seconds ago</small> + </div> + <div class="toast-body"> + Heads up, toasts will stack automatically + </div> + </div> + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div> + +You can also get fancy with flexbox utilities. + +<div class="bg-dark"> +{% capture example html %} +<div style="position: relative; min-height: 200px;"> + <!-- Position it --> + <div class="d-flex justify-content-center" style="position: absolute; top: 0; right: 0; left: 0;"> + + <!-- Then put toasts within --> + <div class="toast"> + <div class="toast-header"> + <img class="rounded mr-2" data-src="holder.js/20x20?size=1&text=.&bg=#007aff" alt=""> + <strong class="mr-auto">Bootstrap</strong> + <small>11 mins ago</small> + </div> + <div class="toast-body"> + Hello, world! This is a toast message. + </div> + </div> + </div> +</div> +{% endcapture %} +{% include example.html content=example %} +</div>