2020-11-15 18:48:32 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
TOAST_TYPE_ERROR,
|
|
|
|
TOAST_TYPE_SUCCESS,
|
|
|
|
// TOAST_TYPE_NOTIFICATION,
|
|
|
|
} from '../constants'
|
|
|
|
import Button from './button'
|
|
|
|
import Image from './image'
|
|
|
|
import RelativeTimestamp from './relative_timestamp'
|
|
|
|
import Text from './text'
|
|
|
|
|
|
|
|
class Toast extends React.PureComponent {
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this._timer = setTimeout(() => {
|
|
|
|
this.handleOnDismiss()
|
|
|
|
}, 5000)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout(this._timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnDismiss = () => {
|
|
|
|
this.props.onDismiss(this.props.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
image,
|
|
|
|
isImageAccount,
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
date,
|
|
|
|
to,
|
|
|
|
} = this.props
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const containerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
radiusSmall: 1,
|
|
|
|
w228PX: 1,
|
2020-11-15 18:48:32 +00:00
|
|
|
mt5: 1,
|
2020-12-03 04:22:51 +00:00
|
|
|
mb5: 1,
|
|
|
|
px15: 1,
|
|
|
|
pt10: 1,
|
|
|
|
pb15: !!title,
|
|
|
|
pb10: !title,
|
|
|
|
bgToast: 1,
|
|
|
|
boxShadowToast: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
const contentClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
mt5: !!title,
|
|
|
|
pt2: !!title,
|
2020-11-15 18:48:32 +00:00
|
|
|
flexRow: !!image,
|
|
|
|
})
|
|
|
|
|
|
|
|
const innerContentClasses = CX({
|
2020-12-03 04:22:51 +00:00
|
|
|
d: 1,
|
2020-11-15 18:48:32 +00:00
|
|
|
flexNormal: 1,
|
|
|
|
pl10: !!image,
|
|
|
|
pt2: !!image,
|
|
|
|
displayInline: !!date && !image,
|
|
|
|
})
|
|
|
|
|
|
|
|
const imageClasses = CX({
|
|
|
|
radiusSmall: !isImageAccount,
|
|
|
|
circle: isImageAccount,
|
|
|
|
})
|
|
|
|
|
|
|
|
const dateClasses = CX({
|
|
|
|
mr5: 1,
|
|
|
|
mt2: !!image,
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2020-12-03 04:22:51 +00:00
|
|
|
<div className={containerClasses}>
|
2020-11-15 18:48:32 +00:00
|
|
|
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter, _s.justifyContentCenter].join(' ')}>
|
2020-12-03 04:22:51 +00:00
|
|
|
<Text size='medium' color='alt' weight='bold'>
|
2020-11-15 18:48:32 +00:00
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
<div className={contentClasses}>
|
|
|
|
{
|
|
|
|
!!image &&
|
|
|
|
<Image
|
|
|
|
src={image}
|
|
|
|
className={imageClasses}
|
|
|
|
height='52px'
|
|
|
|
width='52px'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
<div className={innerContentClasses}>
|
2020-12-03 04:22:51 +00:00
|
|
|
<Text size='small' color='alt'>
|
2020-11-15 18:48:32 +00:00
|
|
|
{message}
|
|
|
|
</Text>
|
|
|
|
{
|
|
|
|
date &&
|
2020-12-03 04:22:51 +00:00
|
|
|
<Text color='tertiary' size='extraSmall' className={dateClasses}>
|
|
|
|
{
|
|
|
|
!image &&
|
|
|
|
<Text size='small' color='tertiary' className={[_s.ml5, _s.mr5].join(' ')}>·</Text>
|
|
|
|
}
|
2020-11-15 18:48:32 +00:00
|
|
|
<RelativeTimestamp timestamp={date} />
|
|
|
|
</Text>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast.propTypes = {
|
|
|
|
date: PropTypes.string.isRequired,
|
|
|
|
image: PropTypes.string,
|
|
|
|
isImageAccount: PropTypes.bool,
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
message: PropTypes.string.isRequired,
|
|
|
|
onDismiss: PropTypes.func.isRequired,
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Toast
|