All Projects → caroso1222 → Notyf

caroso1222 / Notyf

Licence: mit
👻 A minimalistic, responsive, vanilla JavaScript library to show toast notifications.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
SCSS
7915 projects

Projects that are alternatives of or similar to Notyf

php-flasher
🔔 Flasher is a powerful and flexible flash notifications system for PHP, Laravel, Symfony
Stars: ✭ 68 (-96.75%)
Mutual labels:  notifications, toastr, toast
Cogo Toast
Beautiful, Zero Configuration, Toast Messages for React. Only ~ 4kb gzip, with styles and icons
Stars: ✭ 557 (-73.39%)
Mutual labels:  notifications, toast
Ng Snotify
Angular 2+ Notification Center
Stars: ✭ 304 (-85.48%)
Mutual labels:  notifications, toast
Vue Toastification
Vue notifications made easy!
Stars: ✭ 747 (-64.31%)
Mutual labels:  notifications, toast
ngx-toasta
Simple and clean Toast notification library for AngularX (Angular2 and beyond)
Stars: ✭ 20 (-99.04%)
Mutual labels:  notifications, toast
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (-95.32%)
Mutual labels:  notifications, toast
Gsmessages
A simple style messages/notifications, in Swift.
Stars: ✭ 595 (-71.57%)
Mutual labels:  notifications, toast
SteamAchievementNotifier
Steam Achievement Notifier is an Electron application that shows a customisable notification when you unlock any Steam Achievement! It uses the Steam Web API to track achievement stats in real time, and displays an achievement summary within the notification.
Stars: ✭ 77 (-96.32%)
Mutual labels:  notifications, toast
Notie
🔔 a clean and simple notification, input, and selection suite for javascript, with no dependencies
Stars: ✭ 6,170 (+194.79%)
Mutual labels:  notifications, toast
Laravel Notify
Flexible Flash notifications for Laravel
Stars: ✭ 787 (-62.4%)
Mutual labels:  notifications, toast
Svelte Notifications
Svelte toast notifications component that can be used in any JS application
Stars: ✭ 146 (-93.02%)
Mutual labels:  notifications, toast
flasher
A powerful and flexible flash notifications system for PHP
Stars: ✭ 46 (-97.8%)
Mutual labels:  notifications, toastr
Reapop
📮 A simple and customizable React notifications system
Stars: ✭ 1,155 (-44.82%)
Mutual labels:  notifications, toast
Ftindicator
A light wight UI package contains local notification, progress HUD, toast, with blur effect, elegant API and themes support.
Stars: ✭ 292 (-86.05%)
Mutual labels:  notifications, toast
tall-toasts
A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS 🔥🚀
Stars: ✭ 296 (-85.86%)
Mutual labels:  notifications, toast
Toastify Js
Pure JavaScript library for better notification messages
Stars: ✭ 570 (-72.77%)
Mutual labels:  notifications, toast
vue-dk-toast
Lightweight toast-notification plugin for Vue 3 🍞
Stars: ✭ 23 (-98.9%)
Mutual labels:  notifications, toast
Sentinel
👀 Native notifications for League of Legends
Stars: ✭ 38 (-98.18%)
Mutual labels:  notifications, toast
Vue Snotify
Vuejs 2 Notification Center
Stars: ✭ 755 (-63.93%)
Mutual labels:  notifications, toast
Burnttoast
Module for creating and displaying Toast Notifications on Microsoft Windows 10.
Stars: ✭ 796 (-61.97%)
Mutual labels:  notifications, toast

Notyf

npm version Cypress.io tests npm downloads size jsdelivr

Notyf is a minimalistic JavaScript library for toast notifications. It's responsive, A11Y compatible, dependency-free and tiny (~3KB). Easy integration with React, Angular, Aurelia, Vue, and Svelte.

demo gif

Features

  • 📱 Responsive
  • 👓 A11Y compatible
  • 🔥 Strongly typed codebase (TypeScript Typings readily available)
  • ⚡️ 4 types of bundles exposed: ES6, CommonJS, UMD, and IIFE (for vanilla, framework-free usage).
  • 🎯 End-to-end testing with Cypress
  • 🎸 Easily plugable to modern frameworks. Recipes available to integrate with React, Angular, Aurelia, Vue, and Svelte.
  • Optional ripple-like fancy revealing effect
  • 😈 Simple but highly extensible API. Create your own toast types and customize them.
  • 🎃 Support to render custom HTML content within the toasts
  • 🐣 Tiny footprint (<3K gzipped)
  • 👴🏽 Works on IE11

Demo: carlosroso.com/notyf

Installation

npm i notyf

Usage

This section explains the base case using the minified bundle. See the quick recipes section for instructions to plug Notyf into Angular, React, Aurelia, Vue, or Svelte.

Add the css and js files to your main document:

<html>
  <head>
    ...
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css">
  </head>
  <body>
    ...
    <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
  </body>
</html>

Files are delivered via CDN by jsdeliver

Basic

// Create an instance of Notyf
var notyf = new Notyf();

// Display an error notification
notyf.error('You must fill out the form before moving forward');

// Display a success notification
notyf.success('Your changes have been successfully saved!');

With module bundlers

Notyf ships with an ES6 bundle referenced from the module key of its package.json. This is the file that module bundlers like Webpack will use when using the package. Notyf is exported as a class under the notyf namespace. Typings are also available.

import { Notyf } from 'notyf';
import 'notyf/notyf.min.css'; // for React, Vue and Svelte

// Create an instance of Notyf
const notyf = new Notyf();

// Display an error notification 
notyf.error('Please fill out the form');

API

You can set some options when creating a Notyf instance.

new Notyf(options: INotyfOptions)

Param Type Default Details
duration number 2000 Number of miliseconds before hiding the notification. Use 0 for infinite duration.
ripple boolean true Whether to show the notification with a ripple effect
position INotyfPosition {x:'right',y:'bottom'} Viewport location where notifications are rendered
dismissible boolean  false Whether to allow users to dismiss the notification with a button
types INotyfNotificationOptions[] Success and error toasts Array with individual configurations for each type of toast

dismiss(notification: NotyfNotification)

Dismiss a specific notification.

const notyf = new Notyf();
const notification = notyf.success('Address updated');
notyf.dismiss(notification);

dismissAll()

Dismiss all the active notifications.

const notyf = new Notyf();
notyf.success('Address updated');
notyf.error('Please fill out the form');
notyf.dismissAll();

Events

Every individual notification emits events. You can register listeners using the on method.

'click'

Triggers when the notification is clicked

const notyf = new Notyf();
const notification = notyf.success('Address updated. Click here to continue');
notification.on('click', ({target, event}) => {
  // target: the notification being clicked
  // event: the mouseevent
  window.location.href = '/';
});

'dismiss'

Triggers when the notification is manually (not programatically) dismissed.

const notyf = new Notyf();
notyf
  .error({
    message: 'There has been an error. Dismiss to retry.',
    dismissible: true
  })
  .on('dismiss', ({target, event}) => foobar.retry());

Interfaces

INotyfPosition

Viewport location where notifications are rendered.

Param Type Details
x left | center | right x-position
y top | center | bottom y-position

INotyfNotificationOptions

Configuration interface for each individual toast.

Param Type Details
type string Notification type for which this configuration will be applied
className string Custom class name to be set in the toast wrapper element
duration number 2000
icon string INotyfIcon false Either a string with HTML markup, an object with the properties of the icon, or 'false' to hide the icon
background string Background color of the toast
message string Message to be rendered inside of the toast. Becomes the default message when used in the global config.
ripple boolean Whether or not to render the ripple at revealing
dismissible boolean Whether to allow users to dismiss the notification with a button

INotyfIcon

Icon configuration

Param Type Details
className string Custom class name to be set in the icon element
tagName string HTML5 tag used to render the icon
text string Inner text rendered within the icon (useful when using ligature icons)
color string Icon color. It must be a valid CSS color value. Defaults to background color.

Examples

Global configuration

The following example configures Notyf with the following settings:

  • 1s duration
  • Render notifications in the top-right corner
  • New custom notification called 'warning' with a ligature material icon
  • Error notification with custom duration, color and dismiss button
const notyf = new Notyf({
  duration: 1000,
  position: {
    x: 'right',
    y: 'top',
  },
  types: [
    {
      type: 'warning',
      background: 'orange',
      icon: {
        className: 'material-icons',
        tagName: 'i',
        text: 'warning'
      }
    },
    {
      type: 'error',
      background: 'indianred',
      duration: 2000,
      dismissible: true
    }
  ]
});

Custom toast type

Register a new toast type and use it by referencing its type name:

const notyf = new Notyf({
  types: [
    {
      type: 'info',
      background: 'blue',
      icon: false
    }
  ]
});

notyf.open({
  type: 'info',
  message: 'Send us <b>an email</b> to get support'
});

Warning: Notyf doesn't sanitize the content when rendering your message. To avoid injection attacks, you should either sanitize your HTML messages or make sure you don't render user generated content on the notifications.

Default types with custom configurations

The default types are 'success' and 'error'. You can use them simply by passing a message as its argument, or you can pass a settings object in case you want to modify its behaviour.

const notyf = new Notyf();

notyf.error({
  message: 'Accept the terms before moving forward',
  duration: 9000,
  icon: false
})

Recipes

Notyf is well supported in all of the modern frameworks such as Angular, React, Aurelia, Vue, or Svelte. Check out the recipes and learn how to integrate the library to your application.

Contributing

Please see the contributing document and read the contribution guidelines. Thanks in advance for all the help!

Licence

Notyf is under MIT licence

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].