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 dynamic, live alerts example to docs #33866

Merged
merged 3 commits into from Jun 29, 2021
Merged

Add dynamic, live alerts example to docs #33866

merged 3 commits into from Jun 29, 2021

Conversation

mdo
Copy link
Member

@mdo mdo commented May 7, 2021

Spiking out an option for #31330 to add some live examples of alerts (toasts are already there). Ideally we could include more JS folks could copy-pasta to use in their own environments, so hoping to get some help cleaning up the additions in application.js because right now it's not the best and doesn't scale beyond this one demo.

/cc @patrickhlauke as issue author
/cc @planetoftheweb since he mentioned better snippets in our docs

Preview:

Fixes #31330

@planetoftheweb
Copy link
Contributor

Sorry to sound like a newbie, but I'm not too sure how to help. I don't know what a spike is and where to add examples other than here. The alerts look real good, my main problem was with the toasts, which require some addtiional Javascript Activation.

Basic Toast

<h1>Basic Toast</h1>

<button type="button" class="btn btn-danger" id="basicToastBtn">Join us</button>

<div class="toast-container position-fixed top-0 end-0 p-3">
  <div id="basicToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast-header bg-primary text-light">
      <h5 class="my-0">Join Our Company</h5>
    </div>
    <div class="toast-body">
      <strong>Mind Numbing Products</strong> is a force in the manufacturing and production market. Our motto is If it’s not Mind Numbing, it’s not worth it.
    </div>
  </div>  
</div>

And the JavaScript to activate it

document.querySelector("#basicToastBtn").onclick = function() {
 new bootstrap.Toast(document.querySelector('#basicToast')).show();
}

@planetoftheweb
Copy link
Contributor

Here's a sample of a Multiple Toast Element with different options.

<h1>Toast Options</h1>

<h4 class="text-secondary">Basic Toast</h4>

<button type="button" class="btn btn-primary" id="basicToastBtn">Join us</button>
<button type="button" class="btn btn-info text-white" id="infoToastBtn">Info</button>

<div class="toast-container position-fixed top-0 end-0 p-3">
  <div id="basicToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-bs-autohide="false">
    <div class="toast-header bg-primary text-light d-flex justify-content-between">
      <h5 class="my-0">Join Our Company</h5>
      <button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
    </div>
    <div class="toast-body">
      <strong>Mind Numbing Products</strong> is a force in the manufacturing and production market. Our motto is If it’s not Mind Numbing, it’s not worth it.
    </div>
  </div>  

  <div id="infoToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-bs-animation="false" data-bs-delay="2000">
    <div class="toast-body bg-info text-light d-flex justify-content-between">
      <p class="mb-0">As experts in lifting, moving, and nuts-and-bolting, the robotic population is an ideal match for industry and repetitive tasks.</p>
      <button type="button" class="btn-close btn-close-white ms-3" data-bs-dismiss="toast" aria-label="Close"></button>
    </div>
  </div>  

</div>

and the corresponding JavaScript

document.querySelector("#basicToastBtn").onclick = function() {
 new bootstrap.Toast(document.querySelector('#basicToast')).show();
}

document.querySelector("#infoToastBtn").onclick = function() {
 new bootstrap.Toast(document.querySelector('#infoToast')).show();
}

@XhmikosR XhmikosR added the v5 label May 11, 2021
@mdo mdo added this to In progress in v5.1.0 via automation May 13, 2021
@patrickhlauke
Copy link
Member

sorry, very late to the party here, but I checked those examples, and they look good to me - work as expected with screen readers etc

@mdo mdo marked this pull request as ready for review June 24, 2021 00:41
@mdo mdo requested a review from a team as a code owner June 24, 2021 00:41
@mdo mdo moved this from Inbox to Review in v5.1.0 Jun 24, 2021
v5.1.0 automation moved this from Review to Approved Jun 24, 2021
@XhmikosR XhmikosR changed the title Spike for adding dynamic, live alerts example to docs Add dynamic, live alerts example to docs Jun 29, 2021
@XhmikosR
Copy link
Member

@GeoSot should we close the previous alert if it's still open? Just wondering.

@GeoSot
Copy link
Member

GeoSot commented Jun 29, 2021

@XhmikosR I don't find any reason to complicate it more 😖

@XhmikosR
Copy link
Member

Yeah, sounds good to me. I was just wondering :)

@XhmikosR XhmikosR merged commit 696996d into main Jun 29, 2021
v5.1.0 automation moved this from Approved to Done Jun 29, 2021
@XhmikosR XhmikosR deleted the live-alerts branch June 29, 2021 15:46
marvin-hinkley-vortx pushed a commit to Vortx-Inc/bootstrap that referenced this pull request Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v5.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

Docs: live examples of alerts and toasts
5 participants