]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add new toasts component
authorMark Otto <markdotto@gmail.com>
Mon, 3 Jul 2017 23:09:28 +0000 (16:09 -0700)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 13 Nov 2018 06:47:32 +0000 (08:47 +0200)
scss/_toasts.scss [new file with mode: 0644]
scss/_variables.scss
scss/bootstrap.scss
site/_data/nav.yml
site/docs/4.1/components/toasts.md [new file with mode: 0644]

diff --git a/scss/_toasts.scss b/scss/_toasts.scss
new file mode 100644 (file)
index 0000000..248a212
--- /dev/null
@@ -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
+}
index c636860bdadcf72b049a5cbc02e499402fbb90d6..ce958b3c42bc3ad7cf8991b30483baf5a0d12116 100644 (file)
@@ -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;
index 6f7e4eef15bfbcabad949ec7156d635d992ba9aa..c9795108c695c3d9bc30c99412ffe367de57ee51 100644 (file)
@@ -34,6 +34,7 @@
 @import "media";
 @import "list-group";
 @import "close";
+@import "toasts";
 @import "modal";
 @import "tooltip";
 @import "popover";
index cb0defd890f4977cda0282106a6c4fd32cff5fc6..7b6ff7cd977effeb683aa23abcd1289bd0a0c7f0 100644 (file)
@@ -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 (file)
index 0000000..df5d2e8
--- /dev/null
@@ -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>