Skip to content

Instantly share code, notes, and snippets.

@smebberson
Created October 17, 2018 22:24
Show Gist options
  • Save smebberson/33d95445fe716ec42e91eca1e3ad3a15 to your computer and use it in GitHub Desktop.
Save smebberson/33d95445fe716ec42e91eca1e3ad3a15 to your computer and use it in GitHub Desktop.
A dismissible alert based on smooth-ui Alert.
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