Git Product home page Git Product logo

dom-notifications's Introduction

dom-notifications semantic-release

js-standard-style

example gif

Have a look at the example page.

usage

Install with npm install dom-notifications --save and use something like browserify to create a bundle for the browser.

var domNotifications = require('dom-notifications')
var notifications = domNotifications(options)

document.body.appendChild(notifications.element())

notifications.add({message: 'You are now logged in'}) // defaults to `info`
notifications.add({message: 'This is a warning', type: 'warning'})
notifications.error('Oh noes: File not found')

By default this uses octicons icon classes that are not included automatically. Here's a CDN link that serves octicons that you can include in your HTML:

<style rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.5.0/octicons.min.css">

Have a look at the options to replace them with your own icon classes.

options

{
  repo: null, // Can be set to a GitHub url: 'http://github.com/finnp/notifications'
  icons: {
    error: 'octicon octicon-flame',
    warning: 'octicon octicon-alert',
    info: 'octicon octicon-info',
    success: 'octicon octicon-check',
    close: 'octicon octicon-x'

}

Setting the options.repo to a GitHub repository will add an Create an issue for this error button to the error notifications.

If you need more customization, instead of using the message property, you can also specify an element property and set it to DOMElement that will be the content.

For example with yo-yo:

notifications.add({
  type: 'error',
  element: yo`<div>
    <strong>My super custom <em>message</em>!</strong>
  </div>`
})

notifications.element()

Creates the root element for the component. Call this ones to append it to the DOM.

notifications.add(notification)

Add and show a notification. notification should be an object with a message property and optionally one of the types 'error', 'warning', 'info', 'success' (defaults to 'info').

If notification is a string it will use this as a message and default to 'info'.

notifications.info(message)

Shortcut for .add({type: 'info', message: message})

notifications.error(message)

Shortcut for .add({type: 'error', message: message})

notifications.warning(message)

Shortcut for .add({type: 'warning', message: message})

notifications.success(message)

Shortcut for .add({type: 'success', message: message})

Use without styles

If you don't want the styles to be used (or applied automatically), you can also use the module like this:

var domNotifications = require('dom-notifications/main')

// optionally apply styles yourself
var styles = require('dom-notifications/styles')
var insertCss = require('insert-css')
insertCss(styles)

Notes

The styles for the notifications were adapted from ember-cli-notifications and atom.

dom-notifications's People

Contributors

finnp avatar

Watchers

Raza avatar

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.