1.0.1 • Published 1 year ago

@chcodes-hamza/notifications-toast v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Toast notification library & Custom element

GitHub package.json version (branch)
npm

This is a library which a class or a custom web component to display toast notifications in the positions that you configure.

npm.io

Usage

With npm

Install the package using npm or yarn

npm i  @chcodes-hamza/notifications-toast
# or
yarn add  @chcodes-hamza/notifications-toast

Then import it in your script

import "./node_modules/@chcodes-hamza/notifications-toast/dist/Toast.js"

With unpkg.com

<script type="module" src="https://unpkg.com/@chcodes-hamza/notifications-toast"></script>

Then use the custom element in your html <toast-notifications> </toast-notifications>.

<toast-notifications options='{
      "text": "Custom element",
      "position": "top-right",
      "pauseOnHover": true,
      "pauseOnFocusLoss": true,
      "autoClose": 5000,
      "type":"sucess"
    }'></toast-notifications>

Customization

Attributes

AttributeTypeDescription
optionsJSONa JSON object that contains many properties

Options Object:

OptionDefaultDescription
textemptythe text displayed in the toast
positiontop-rightthe postion where the toast will be displayed (top-right, top-left, top-center ,bottom-center, bottom-left , bottom-right)
pauseOnHovertruethe toast progress bar stops when it s hovred
pauseOnFocusLosstruethe toast progress bar stops when you leave the current window
autoClose5000 msthe toast will be closed automaticly after the 5000ms if you wnat to make it disappear manually put it false
typedefault templatecustomize the type of the toast (danger, info , success, warning)
showProgresstrueenable the progress bar in the toast bottom
canClosetruegive ability to close the toast
onClose()=>{}customize the action after the toast is closed, callback as input

CSS Custom Properties

Property
--text-color-default
--chcodes-notif-default
--chcodes-notif-default-progress
--chcodes-notif-info
--chcodes-notif-info-progress
--chcodes-notif-danger
--chcodes-notif-danger-progress
--chcodes-notif-warning
--chcodes-notif-warning-progress
--chcodes-notif-sucess
--chcodes-notif-sucess-progress