import React, { Component, PropTypes } from 'react'; import classnames from 'classnames'; import { themr } from 'react-css-themr'; import { SNACKBAR } from '../identifiers.js'; import ActivableRenderer from '../hoc/ActivableRenderer.js'; import FontIcon from '../font_icon/FontIcon.js'; import InjectOverlay from '../overlay/Overlay.js'; import InjectButton from '../button/Button.js'; const factory = (Overlay, Button) => { class Snackbar extends Component { static propTypes = { action: PropTypes.string, active: PropTypes.bool, children: PropTypes.node, className: PropTypes.string, icon: PropTypes.oneOfType([ PropTypes.string, PropTypes.element ]), label: PropTypes.oneOfType([ PropTypes.string, PropTypes.element ]), onClick: PropTypes.func, onTimeout: PropTypes.func, theme: PropTypes.shape({ accept: PropTypes.string, active: PropTypes.string, button: PropTypes.string, cancel: PropTypes.string, icon: PropTypes.string, label: PropTypes.string, snackbar: PropTypes.string, warning: PropTypes.string }), timeout: PropTypes.number, type: PropTypes.oneOf([ 'accept', 'cancel', 'warning' ]) }; componentWillReceiveProps (nextProps) { if (nextProps.active && nextProps.timeout) { if (this.curTimeout) clearTimeout(this.curTimeout); this.curTimeout = setTimeout(() => { nextProps.onTimeout(); this.curTimeout = null; }, nextProps.timeout); } } componentWillUnmount () { clearTimeout(this.curTimeout); } render () { const {action, active, children, icon, label, onClick, theme, type } = this.props; const className = classnames([theme.snackbar, theme[type]], { [theme.active]: active }, this.props.className); return (
{icon ? : null} {label} {children} {action ?
); } } return ActivableRenderer()(Snackbar); }; const Snackbar = factory(InjectOverlay, InjectButton); export default themr(SNACKBAR)(Snackbar); export { factory as snackbarFactory }; export { Snackbar };