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.

PollAnswer.tsx 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import { makeStyles } from 'tss-react/mui';
  3. import Button from '../../../base/ui/components/web/Button';
  4. import Checkbox from '../../../base/ui/components/web/Checkbox';
  5. import { BUTTON_TYPES } from '../../../base/ui/constants.web';
  6. import { isSubmitAnswerDisabled } from '../../functions';
  7. import AbstractPollAnswer, { AbstractProps } from '../AbstractPollAnswer';
  8. const useStyles = makeStyles()(theme => {
  9. return {
  10. buttonMargin: {
  11. marginRight: theme.spacing(2)
  12. }
  13. };
  14. });
  15. const PollAnswer = ({
  16. creatorName,
  17. checkBoxStates,
  18. poll,
  19. setCheckbox,
  20. skipAnswer,
  21. skipChangeVote,
  22. submitAnswer,
  23. t
  24. }: AbstractProps) => {
  25. const { changingVote } = poll;
  26. const { classes: styles } = useStyles();
  27. return (
  28. <div className = 'poll-answer'>
  29. <div className = 'poll-header'>
  30. <div className = 'poll-question'>
  31. <span>{ poll.question }</span>
  32. </div>
  33. <div className = 'poll-creator'>
  34. { t('polls.by', { name: creatorName }) }
  35. </div>
  36. </div>
  37. <ol className = 'poll-answer-list'>
  38. {
  39. poll.answers.map((answer: any, index: number) => (
  40. <li
  41. className = 'poll-answer-container'
  42. key = { index }>
  43. <Checkbox
  44. checked = { checkBoxStates[index] }
  45. key = { index }
  46. label = { answer.name }
  47. // eslint-disable-next-line react/jsx-no-bind
  48. onChange = { ev => setCheckbox(index, ev.target.checked) } />
  49. </li>
  50. ))
  51. }
  52. </ol>
  53. <div className = 'poll-footer poll-answer-footer' >
  54. <Button
  55. accessibilityLabel = { t('polls.answer.skip') }
  56. className = { styles.buttonMargin }
  57. fullWidth = { true }
  58. labelKey = { 'polls.answer.skip' }
  59. onClick = { changingVote ? skipChangeVote : skipAnswer }
  60. type = { BUTTON_TYPES.SECONDARY } />
  61. <Button
  62. accessibilityLabel = { t('polls.answer.submit') }
  63. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  64. fullWidth = { true }
  65. labelKey = { 'polls.answer.submit' }
  66. onClick = { submitAnswer } />
  67. </div>
  68. </div>
  69. );
  70. };
  71. /*
  72. * We apply AbstractPollAnswer to fill in the AbstractProps common
  73. * to both the web and native implementations.
  74. */
  75. // eslint-disable-next-line new-cap
  76. export default AbstractPollAnswer(PollAnswer);