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 }
|