index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import Icon from '../Icon';
  4. export default class OtherAnswer extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.Text = null;
  8. this.state = { show: false, more: false };
  9. this.checkHeight();
  10. }
  11. checkHeight() {
  12. if (this.Text != null) {
  13. if (this.Text.offsetHeight > 80) {
  14. this.setState({ more: true });
  15. }
  16. } else {
  17. setTimeout(() => {
  18. this.checkHeight();
  19. }, 1);
  20. }
  21. }
  22. render() {
  23. const { show, more } = this.state;
  24. return (
  25. <div className={`other-answer ${more ? 'more' : ''} ${!show ? 'hide' : ''}`}>
  26. <div className="title">Q: Agreement;Rhetorical construction</div>
  27. <div
  28. ref={ref => {
  29. this.Text = ref;
  30. }}
  31. className="desc"
  32. >
  33. A: They are generally not good at taking care of themselves.and services to prevent worsening health and
  34. increased health costs.They are worsening health and increased health costs..and services to
  35. </div>
  36. {more && show && <Icon name="up" onClick={() => this.setState({ show: false })} />}
  37. {more && !show && <Icon name="down" onClick={() => this.setState({ show: true })} />}
  38. </div>
  39. );
  40. }
  41. }