You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
855 B
34 lines
855 B
import React, { FC } from 'react'
|
|
import { NotificationType } from '../../types'
|
|
|
|
interface Props {
|
|
id: string
|
|
type: NotificationType
|
|
auto: boolean
|
|
setAuto: (id: string) => void
|
|
dismiss: (id: string) => void
|
|
}
|
|
|
|
const getClassName = (type: NotificationType) => {
|
|
switch (type) {
|
|
case 'info': return 'is-info'
|
|
case 'success': return 'is-success'
|
|
case 'error': return 'is-danger'
|
|
}
|
|
}
|
|
|
|
const Notification: FC<Props> = ({ id, type, auto, setAuto, dismiss, children }) => {
|
|
const classnames = [
|
|
'notification',
|
|
getClassName(type),
|
|
].join(' ')
|
|
|
|
return (
|
|
<div className={classnames} onClick={() => setAuto(id)}>
|
|
{!auto && <button className="delete" onClick={() => dismiss(id)}></button>}
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Notification
|