├── .gitignore ├── .gitattributes ├── package.json ├── LICENSE ├── README.md ├── index.html └── src └── bootstrap-show-toast.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | src/bootstrap-show-toast.js linguist-vendored=false 2 | index.html linguist-documentation 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap-show-toast", 3 | "version": "1.2.2", 4 | "description": "A Bootstrap 5 plugin to show toasts with pure JavaScript", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/shaack/bootstrap-show-toast.git" 12 | }, 13 | "keywords": [ 14 | "Bootstrap", 15 | "HTML" 16 | ], 17 | "author": "shaack.com", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/shaack/bootstrap-show-toast/issues" 21 | }, 22 | "homepage": "https://github.com/shaack/bootstrap-show-toast#readme" 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Stefan Haack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bootstrap-show-toast 2 | 3 | A Bootstrap 5 plugin for [Bootstrap Toasts](https://getbootstrap.com/docs/5.3/components/toasts/), to show them with pure JS, no HTML needed. 4 | 5 | ## References 6 | 7 | - [Demo page](https://shaack.com/projekte/bootstrap-show-toast) 8 | - [GitHub repository](https://github.com/shaack/bootstrap-show-toast) 9 | - [npm package](https://www.npmjs.com/package/bootstrap-show-toast) 10 | 11 | ## Installation 12 | 13 | ```sh 14 | npm install bootstrap-show-toast 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```js 20 | // simple example 21 | bootstrap.showToast({body: "Hello Toast!"}) 22 | 23 | // type danger 24 | bootstrap.showToast({ 25 | header: "Alert", 26 | body: "Red Alert!", 27 | toastClass: "text-bg-danger" 28 | }) 29 | 30 | // more complex toast with header and buttons 31 | const toast = bootstrap.showToast({ 32 | header: "Information", 33 | headerSmall: "just now", 34 | body: "
This notification has a headline and more text than the previous one.
", 35 | delay: 20000 36 | }) 37 | toast.element.querySelector(".btn-primary").addEventListener("click", () => { 38 | bootstrap.showToast({ 39 | body: "Thank you for clicking", direction: "append", 40 | toastClass: "text-bg-success", closeButtonClass: "btn-close-white" 41 | }) 42 | }) 43 | 44 | // type secondary and sticky 45 | bootstrap.showToast({ 46 | body: "This notification will stay", 47 | toastClass: "text-bg-secondary", closeButtonClass: "btn-close-white", 48 | delay: Infinity // delay of `Infinity` to make it sticky 49 | }) 50 | ``` 51 | 52 | ## Props (defaults) 53 | 54 | ```js 55 | this.props = { 56 | header: "", // the header text 57 | headerSmall: "", // additional text in the header, aligns right 58 | body: "", // the body text of the toast 59 | closeButton: true, // show a close button 60 | closeButtonLabel: "close", // the label of the close button 61 | closeButtonClass: "", // set to "btn-close-white" for dark backgrounds 62 | toastClass: "", // the appearance 63 | animation: true, // apply a CSS fade transition to the toast 64 | delay: 5000, // delay in milliseconds before hiding the toast, set delay to `Infinity` to make it sticky 65 | position: "top-0 end-0", // top right 66 | direction: "append", // or "prepend", the stack direction 67 | ariaLive: "assertive" 68 | } 69 | ``` 70 | 71 | --- 72 | 73 | Find more high quality modules from [shaack.com](https://shaack.com) 74 | on [our projects page](https://shaack.com/works). 75 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |13 | A Bootstrap plugin, to create toasts (also called notifications) dynamically in JavaScript. 14 |
15 |17 | 18 |
19 |20 | 22 |
23 |24 | 25 |
26 |27 | 28 |
29 |