warning.js 878 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import classnames from 'classnames';
  3. class Warning extends React.Component {
  4. constructor(props, context) {
  5. super(props, context);
  6. this.handleClick = this.handleClick.bind(this);
  7. this.state = {
  8. expanded: false
  9. };
  10. }
  11. handleClick() {
  12. this.setState(prevState => ({
  13. expanded: !prevState.expanded
  14. }));
  15. }
  16. render() {
  17. const { text } = this.props;
  18. const { expanded } = this.state;
  19. const className = classnames('warning', {
  20. 'warning-expanded': expanded
  21. });
  22. return (
  23. <div className={className} onClick={this.handleClick}>
  24. <div className="warning-wrapper">
  25. <i className="warning-icon fa fa-exclamation-triangle" title={text} />
  26. {expanded && <span className="warning-text">{text}</span>}
  27. </div>
  28. </div>
  29. );
  30. }
  31. }
  32. export default Warning;