1.0.0 • Published 2 years ago

bs5-toast v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

bs5-toast

Bootstrap 5 toasts generator

https://bs5-toast.vercel.app

Features

  • Customizable content
  • Smooth animation
  • Typed safe

Installation

Install bs5-toast with npm

npm install bs5-toast

Install from cdn

<script src="https://unpkg.com/bs5-toast/dist/bs5-toast.js"></script>

Usage/Examples

import bs5 from 'bs5-toast'

new bs5.Toast({
    body: 'Hello world',
}).show()

or use directly in script tag

<script src="https://unpkg.com/bs5-toast/dist/bs5-toast.js"></script>
<script>
    new bs5.Toast({
        body: 'Hello world',
    }).show()
</script>

Options

NameTypeDefaultDescription
bodystring''Body content. Can also be filled with html tags. example: Hello <b>World</b>
headerstring''Header content. Can also be filled with html tags. example: <h6 class="mb-0">Success</h6>
animationbooleantrueApply transition to the toast
autohidebooleantrueAuto hide the toast
btnClosebooleantrueShow close button
btnCloseWhitebooleanfalseSet close button as white variant
classNamestring''Class attribute to be added in class '.toast'
delaynumber5000Delay hiding the toast (ms)
gapnumber16Gap between toasts (px)
marginstring1remMargin of corner. Can also be filled with a css variable. example: var(--toast-margin)
placementstringtop-rightCorner position of toast. Available values: top-right, top-left, bottom-right, bottom-left

Methods

show

Reveals an element’s toast.

const toast = new bs5.Toast({
    body: 'Hello world',
})
toast.show()

hide

Hides an element’s toast.

toast.hide()

element

Get the toast element.

toast.element.addEventListener('shown.bs.toast', function () {
  console.log('toast shown!')
})
toast.show()