index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. export default class HardInput extends Component {
  4. render() {
  5. const { focus, answer = [], show, list = [], correct, onClick, onDelete } = this.props;
  6. const a = answer.length > 0 ? answer[0] : [];
  7. const otherList = [];
  8. if (show) {
  9. const map = {};
  10. list.forEach((row) => {
  11. map[row.uuid] = row;
  12. });
  13. a.forEach((row) => {
  14. if (!map[row.uuid]) otherList.push(row);
  15. });
  16. }
  17. return (
  18. <div className={`hard-input ${focus ? 'focus' : ''}`} onClick={() => {
  19. if (onClick) onClick();
  20. }}>
  21. {list.map((item) => {
  22. return (
  23. <div className={`item ${a.indexOf(item.uuid) >= 0 || correct ? 'true' : 'false'} ${show ? 'show' : ''}`} onClick={() => {
  24. if (onDelete) onDelete(item);
  25. }}>
  26. <div className="text">{item.text}</div>
  27. <div className="icon" />
  28. </div>
  29. );
  30. })}
  31. {otherList.map(item => {
  32. return (
  33. <div className="other-item">
  34. <div className="text">{item.text}</div>
  35. </div>
  36. );
  37. })}
  38. </div>
  39. );
  40. }
  41. }