Created
October 17, 2018 22:24
-
-
Save smebberson/33d95445fe716ec42e91eca1e3ad3a15 to your computer and use it in GitHub Desktop.
A dismissible alert based on smooth-ui Alert.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { Alert, Box } from '@smooth-ui/core-sc'; | |
class DismissableAlert extends Component { | |
constructor (props) { | |
super(props); | |
const { onDismiss, ...rest } = props; | |
this.onDismiss = onDismiss; | |
this.rest = rest; | |
} | |
isDismissable () { | |
if (this.onDismiss) { | |
return <a onClick={this.onDismiss}><i className="far fa-times"></i></a>; | |
} | |
return ''; | |
} | |
render () { | |
return <Alert { ...this.rest }> | |
<Box | |
display="flex" | |
justifyContent="space-between" | |
> | |
<span>{ this.props.children }</span> | |
{ this.isDismissable() } | |
</Box> | |
</Alert>; | |
} | |
} | |
DismissableAlert.propTypes = { | |
children: PropTypes.node.isRequired, | |
onDismiss: PropTypes.func.isRequired, | |
}; | |
export default DismissableAlert; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment