All files / components/toast index.js

0% Statements 0/42
0% Branches 0/43
0% Functions 0/6
0% Lines 0/27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                                                                                   
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import alertify from 'alertifyjs'
import 'alertfy-css/alertify.css'
import ToastTemplate from './toast.template'
import Position from './toast.position'
 
const Toast = {
  setPosition (position) {
    switch (position) {
      case Position.LEFT:
        alertify.set('notifier', 'position', 'top-left')
        break
 
      case Position.RIGHT:
        alertify.set('notifier', 'position', 'top-right')
        break
 
      default:
        alertify.set('notifier', 'position', 'top-left')
        break
    }
    return this
  },
 
  notify (content, position) {
    this.setPosition(position)
    return alertify.notify(content)
  },
 
  warning (title = 'Atenção!', description = '', position = Position.DEFAULT) {
    const content = ReactDOMServer.renderToString(<ToastTemplate type='warning' title={title} description={description} side={position} />)
    return this.notify(content, position)
  },
 
  success (title = 'Perfeito!', description = 'Tudo certo.', position = Position.DEFAULT) {
    const content = ReactDOMServer.renderToString(<ToastTemplate type='success' title={title} description={description} side={position} />)
    return this.notify(content, position)
  },
 
  error (title = 'Oops!', description = 'Algo deu errado.', position = Position.DEFAULT) {
    const content = ReactDOMServer.renderToString(<ToastTemplate type='error' title={title} description={description} side={position} />)
    return this.notify(content, position)
  }
}
 
Toast.Position = Position
 
export { Toast }