import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { MdClose } from 'react-icons/md'; import { MdWarning } from 'react-icons/md'; import { MdError } from 'react-icons/md'; import { MdCheckCircle } from 'react-icons/md'; import { Base16Theme } from 'base16'; import createStyledComponent from '../utils/createStyledComponent'; import styles from './styles'; const NotificationWrapper = createStyledComponent(styles); export type Type = 'info' | 'success' | 'warning' | 'error'; export interface NotificationProps { children?: React.ReactNode; type: Type; onClose?: React.MouseEventHandler; theme?: Base16Theme; } export default class Notification extends Component { shouldComponentUpdate(nextProps: NotificationProps) { return ( nextProps.children !== this.props.children || nextProps.type !== this.props.type ); } getIcon = () => { switch (this.props.type) { case 'warning': return ; case 'error': return ; case 'success': return ; default: return null; } }; render() { return ( {this.getIcon()} {this.props.children} {this.props.onClose && ( )} ); } static propTypes = { children: PropTypes.any.isRequired, type: PropTypes.oneOf(['info', 'success', 'warning', 'error']), onClose: PropTypes.func, theme: PropTypes.object, }; static defaultProps = { type: 'info', }; }