From d0652a1be9744ac433d26c960a4253074bd40639 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Mon, 3 Jul 2017 16:09:28 -0700 Subject: [PATCH] Add new toasts component --- scss/_toasts.scss | 29 +++++ scss/_variables.scss | 17 ++- scss/bootstrap.scss | 1 + site/_data/nav.yml | 1 + site/docs/4.1/components/toasts.md | 169 +++++++++++++++++++++++++++++ 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 scss/_toasts.scss create mode 100644 site/docs/4.1/components/toasts.md 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. + +
+{% capture example %} +
+
+ + Bootstrap + 11 mins ago +
+
+ Hello, world! This is a toast message. +
+
+{% endcapture %} +{% include example.html content=example %} +
+ +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. + +
+{% capture example %} +
+
+ + Bootstrap + 11 mins ago +
+
+ Hello, world! This is a toast message. +
+
+{% endcapture %} +{% include example.html content=example %} +
+ +Plus, they'll easily stack. + +
+{% capture example %} +
+
+ + Bootstrap + just now +
+
+ See? Just like this. +
+
+ +
+
+ + Bootstrap + 2 seconds ago +
+
+ Heads up, toasts will stack automatically +
+
+{% endcapture %} +{% include example.html content=example %} +
+ +## 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 %} +
+
...
+
+{% 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.` + +
+{% capture example %} +
+
+
+ + Bootstrap + 11 mins ago +
+
+ Hello, world! This is a toast message. +
+
+
+{% endcapture %} +{% include example.html content=example %} +
+ +For systems that generate more notifications, consider using a wrapping element so they can easily stack. + +
+{% capture example %} +
+ +
+ + +
+
+ + Bootstrap + just now +
+
+ See? Just like this. +
+
+ +
+
+ + Bootstrap + 2 seconds ago +
+
+ Heads up, toasts will stack automatically +
+
+
+
+{% endcapture %} +{% include example.html content=example %} +
+ +You can also get fancy with flexbox utilities. + +
+{% capture example html %} +
+ +
+ + +
+
+ + Bootstrap + 11 mins ago +
+
+ Hello, world! This is a toast message. +
+
+
+
+{% endcapture %} +{% include example.html content=example %} +