2017-08-26 02:56:21 +00:00
< template lang = "pug" >
transition ( name = "fade" )
2017-09-23 03:27:00 +00:00
. notification . callout . animated ( : class = "classes" , v - if = 'show' , @ click = 'show = false' )
2017-08-29 00:39:32 +00:00
. row ( v - if = 'notification.type === "error"' )
. text . col - 12
div ( v - html = 'notification.text' )
2017-11-30 18:37:53 +00:00
. row ( v - if = 'notification.type === "streak"' )
. text . col - 7. offset - 1
div { { message } }
. icon . col - 4
div . svg - icon ( v - html = "icons.gold" )
div ( v - html = 'notification.text' )
2017-09-05 18:34:00 +00:00
. row ( v - if = '["hp", "gp", "xp", "mp"].indexOf(notification.type) !== -1' )
2017-08-26 02:56:21 +00:00
. text . col - 7. offset - 1
div
| { { message } }
. icon . col - 4
div . svg - icon ( v - html = "icons.health" , v - if = 'notification.type === "hp"' )
div . svg - icon ( v - html = "icons.gold" , v - if = 'notification.type === "gp"' )
div . svg - icon ( v - html = "icons.star" , v - if = 'notification.type === "xp"' )
div . svg - icon ( v - html = "icons.mana" , v - if = 'notification.type === "mp"' )
div ( v - html = 'notification.text' )
2017-09-05 18:34:00 +00:00
. row ( v - if = '["info", "success", "crit", "lvl"].indexOf(notification.type) !== -1' )
2017-08-26 02:56:21 +00:00
. text . col - 12
div ( v - html = 'notification.text' )
2017-09-05 18:34:00 +00:00
. row ( v - if = 'notification.type === "drop"' )
2017-08-26 02:56:21 +00:00
. col - 2
. icon - item
div ( : class = 'notification.icon' )
. text . col - 9
div ( v - html = 'notification.text' )
< / template >
< style lang = "scss" scoped >
. notification {
border - radius : 1000 px ;
background - color : # 24 cc8f ;
box - shadow : 0 2 px 2 px 0 rgba ( 26 , 24 , 29 , 0.16 ) , 0 1 px 4 px 0 rgba ( 26 , 24 , 29 , 0.12 ) ;
color : white ;
width : 300 px ;
margin - left : 1 em ;
margin - bottom : 1 em ;
}
. info {
max - height : 56 px ;
background - color : # 46 a7d9 ;
padding - top : .5 em ;
}
2017-08-29 00:39:32 +00:00
. error {
background - color : # f74e52 ;
color : # fff ;
}
2017-08-26 02:56:21 +00:00
. negative {
background - color : # f74e52 ;
}
. text {
text - align : center ;
padding : .5 em ;
}
. svg - icon {
width : 20 px ;
2017-12-20 16:33:21 +00:00
height : 20 px ;
2017-08-26 02:56:21 +00:00
margin - right : .5 em ;
}
. hp . icon {
color : # f74e52 ;
}
. mp . icon {
color : # 2995 cd ;
}
. icon {
background : # fff ;
color : # ffa623 ;
border - radius : 0 1000 px 1000 px 0 ;
padding : .5 em ;
div {
display : inline - block ;
vertical - align : bottom ;
}
}
. drop {
background - color : # 4 e4a57 ;
}
. icon - item {
width : 64 px ;
height : 64 px ;
background - color : # ffffff ;
box - shadow : 0 2 px 2 px 0 rgba ( 26 , 24 , 29 , 0.16 ) , 0 1 px 4 px 0 rgba ( 26 , 24 , 29 , 0.12 ) ;
border - radius : 50 % ;
}
. fade - enter - active , . fade - leave - active {
transition : opacity .5 s
}
. fade - enter , . fade - leave - to /* .fade-leave-active below version 2.1.8 */ {
opacity : 0
}
< / style >
< script >
import health from 'assets/svg/health.svg' ;
import gold from 'assets/svg/gold.svg' ;
import star from 'assets/svg/star.svg' ;
import mana from 'assets/svg/mana.svg' ;
export default {
props : [ 'notification' ] ,
data ( ) {
return {
timer : null ,
icons : Object . freeze ( {
health ,
gold ,
star ,
mana ,
} ) ,
show : true ,
} ;
} ,
created ( ) {
2017-10-02 01:42:02 +00:00
// @TODO the notifications always close even if timeout is false
2017-08-26 02:56:21 +00:00
let timeout = this . notification . hasOwnProperty ( 'timeout' ) ? this . notification . timeout : true ;
if ( timeout ) {
2017-11-16 20:32:57 +00:00
let delay = this . notification . delay || 1500 ;
delay += this . $store . state . notificationStore . length * 1000 ;
2017-08-26 02:56:21 +00:00
setTimeout ( ( ) => {
this . show = false ;
} , delay ) ;
}
} ,
watch : {
show ( ) {
2017-10-20 13:22:13 +00:00
this . $store . dispatch ( 'snackbars:remove' , this . notification ) ;
2017-08-26 02:56:21 +00:00
} ,
} ,
computed : {
message ( ) {
2017-09-19 11:44:45 +00:00
let localeKey = this . negative === 'negative' ? 'lost' : 'gained' ;
if ( this . notification . type === 'hp' ) localeKey += 'Health' ;
if ( this . notification . type === 'mp' ) localeKey += 'Mana' ;
if ( this . notification . type === 'xp' ) localeKey += 'Experience' ;
if ( this . notification . type === 'gp' ) localeKey += 'Gold' ;
2017-11-30 18:37:53 +00:00
if ( this . notification . type === 'streak' ) localeKey = 'streakCoins' ;
2017-09-19 11:44:45 +00:00
return this . $t ( localeKey ) ;
// This requires eight translatable strings, but that gives the translators the most flexibility for matching gender/number and for using idioms for lost/spent/used/gained.
2017-08-26 02:56:21 +00:00
} ,
negative ( ) {
return this . notification . sign === '-' ? 'negative' : 'positive' ;
} ,
classes ( ) {
return ` ${ this . notification . type } ${ this . negative } ` ;
} ,
} ,
} ;
< / script >