You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PollResults.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // @flow
  2. import React from 'react';
  3. import AbstractPollResults from '../AbstractPollResults';
  4. import type { AbstractProps } from '../AbstractPollResults';
  5. /**
  6. * Component that renders the poll results.
  7. *
  8. * @param {Props} props - The passed props.
  9. * @returns {React.Node}
  10. */
  11. const PollResults = (props: AbstractProps) => {
  12. const {
  13. answers,
  14. changeVote,
  15. haveVoted,
  16. showDetails,
  17. question,
  18. t,
  19. toggleIsDetailed
  20. } = props;
  21. return (
  22. <div className = 'poll-results'>
  23. <div className = 'poll-header'>
  24. <div className = 'poll-question'>
  25. <strong>{ question }</strong>
  26. </div>
  27. </div>
  28. <ol className = 'poll-result-list'>
  29. {answers.map(({ name, percentage, voters, voterCount }, index) =>
  30. (<li key = { index }>
  31. <div className = 'poll-answer-header'>
  32. <span className = 'poll-answer-vote-name' >{name}</span>
  33. </div>
  34. <div className = 'poll-answer-short-results'>
  35. <span className = 'poll-bar-container'>
  36. <div
  37. className = 'poll-bar'
  38. style = {{ width: `${percentage}%` }} />
  39. </span>
  40. <div className = 'poll-answer-vote-count-container'>
  41. <span className = 'poll-answer-vote-count'>({voterCount}) {percentage}%</span>
  42. </div>
  43. </div>
  44. { showDetails && voters && voterCount > 0
  45. && <ul className = 'poll-answer-voters'>
  46. {voters.map(voter =>
  47. <li key = { voter.id }>{voter.name}</li>
  48. )}
  49. </ul>}
  50. </li>)
  51. )}
  52. </ol>
  53. <div className = { 'poll-result-links' }>
  54. <a
  55. className = { 'poll-detail-link' }
  56. onClick = { toggleIsDetailed }>
  57. {showDetails ? t('polls.results.hideDetailedResults') : t('polls.results.showDetailedResults')}
  58. </a>
  59. <a
  60. className = { 'poll-change-vote-link' }
  61. onClick = { changeVote }>
  62. {haveVoted ? t('polls.results.changeVote') : t('polls.results.vote')}
  63. </a>
  64. </div>
  65. </div>
  66. );
  67. };
  68. /*
  69. * We apply AbstractPollResults to fill in the AbstractProps common
  70. * to both the web and native implementations.
  71. */
  72. // eslint-disable-next-line new-cap
  73. export default AbstractPollResults(PollResults);