GithubHelp home page GithubHelp logo

philipp-winterle / bs-toaster Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 3.0 136 KB

A Bootstrap 5 Toast Framework - Easy to use. No other dependencies than Bootstrap itself.

License: MIT License

JavaScript 100.00%

bs-toaster's People

Contributors

philipp-winterle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bs-toaster's Issues

Couldn’t for the life of me get it to work on a hosting provider (no nodejs)

I ended up adapting your code to the Below. Don’t laugh. But it works like a charm for a no module approach

function bsToaster(bsToasterTitle, bsToasterText, bsToasterIcon) {

const TOAST_CONTAINER_TEMLATE = `
  <div data-bs-toaster="" class="toast-container position-fixed p-3"></div>  
`;

const TOAST_TEMPLATE = `
  <div class="toast align-items-center text-bg-dark border-0 bg-opacity-100" role="alert" aria-live="assertive" aria-atomic="true">
	<div class="toast-header text-bg-dark">
	 <span class="bs-toaster-icon d-flex">%ICON%</span>
	  <strong class="bs-toaster-title me-auto"></strong>
	  <small class="text-white">Just Now</small>
	  <button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
	</div>
	<div class="bs-toaster-text toast-body"></div>
  </div>
`;

const DEFAULT_ICON_MARKUP = `
  <i class="p-2 me-2 rounded %TYPE%"></i>
`;

iconMarkup = DEFAULT_ICON_MARKUP;

const position = "top-0 end-0";

const base64Position = btoa(position);

const existingToastContainer = document.querySelector(
    `[data-bs-toaster="${base64Position}"]`
);

let containerNode = null;

if (
    existingToastContainer === null ||
    existingToastContainer instanceof HTMLDivElement === false
) {
    containerNode = new DOMParser().parseFromString(
        TOAST_CONTAINER_TEMLATE,
        "text/html"
    ).body.childNodes[0];

    containerNode.classList.add(...position.split(" "));

    containerNode.dataset.bsToaster = base64Position;
} else {
    containerNode = existingToastContainer;
}

templateNode = null;
toastContainer = null;

this.toastContainer = containerNode;
this.templateNode = new DOMParser().parseFromString(TOAST_TEMPLATE, "text/html").body.childNodes[0];

document.body.appendChild(this.toastContainer);

const toastNode = this.templateNode.cloneNode(true);

toastNode.dataset.bsAutohide = "true"
toastNode.dataset.bsDelay = "3000";
toastNode.dataset.bsAnimation = "true";

const iconNode = toastNode.querySelector(".bs-toaster-icon");
if (iconMarkup) {
    iconMarkup = iconMarkup.replace("%TYPE%", bsToasterIcon);
    iconNode.innerHTML = iconMarkup;
} else {
    iconNode.remove();
}

toastNode.querySelector(".bs-toaster-title").innerHTML = bsToasterTitle;
toastNode.querySelector(".bs-toaster-text").innerHTML = bsToasterText;

this.toastContainer.appendChild(toastNode);

const toast = new bootstrap.Toast(toastNode);
toast.show();

`}```

Conflict with Boostrap Modals

Many thanks for the work on this project. Its exactly what I needed, exactly when I needed it...

When using the "shown.bs.modal" functionality described on the Boostrap Instruction page, bs-toaster creates a non-breaking error in the console. Using a pure JS or Jquery call to open the modal does not cause the error, just when using the "data-bs-toggle" built into bootstrap.

Example: test.html.zip

Error text: vt.getInstance(...) is null

To Reproduce

  1. Open the attached file in a browser
  2. Click on the "Launch Modal" button with your console open.

Screen Shot 2023-04-19 at 2 15 12 PM

bs-toaster is throwing exception for defaultIconMarkup

Hello,

I was experimenting the bs-toaster npm package in codepen to customize it a little-bit as per the my requirements, like adding custom icon, but when I used

defaultIconMarkup: '<i class=""></i>

then it's throwing any error, even I tried by removing the i tag but still it's throwing an error.

please help me @hummal

Implementation to Completely Remove Title Bar, Add Class and Color Schemes

The current implementation of bs-toaster does not allow for the complete removal of the title bar in the toast notifications. This can be limiting in cases where a more minimalist design is desired.

I would like to have an option to completely remove the title bar from the toast notifications. This could be implemented as a configuration option when creating a new toast or probably when the first argument of create is set to null. Additionally, it would be beneficial to have the ability to add custom classes or color schemes to the toasts for better customization and integration with the rest of the application’s design.

https://getbootstrap.com/docs/5.3/components/toasts/#color-schemes

If these features are already implemented, please update the documentation for clarity

Console error "Uncaught SyntaxError: export declarations may only appear at top level of a module"

Describe the bug
Simple import of the "Toaster.bundle.js" as outlined in the readme causes an error in the console.

To Reproduce
Steps to reproduce the behavior:

  1. Downloaded package from github
  2. Unzipped
  3. Took the "Toaster.bundle.js" file and copied it to my static folder (flask project)
  4. imported with <script src="{{ url_for('static', filename='base/Toaster.bundle.js') }}"></script>
  5. Got this error in the firefox console: "Uncaught SyntaxError: export declarations may only appear at top level of a module"

Expected behavior
Clean load

Screenshots
https://imgur.com/a/6tQTgNe

Desktop (please complete the following information):

  • OS: Linux mint
  • Browser: Firefox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.