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 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React from 'react';
  2. import { makeStyles } from 'tss-react/mui';
  3. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  4. import Button from '../../../base/ui/components/web/Button';
  5. import Checkbox from '../../../base/ui/components/web/Checkbox';
  6. import { BUTTON_TYPES } from '../../../base/ui/constants.web';
  7. import { isSubmitAnswerDisabled } from '../../functions';
  8. import AbstractPollAnswer, { AbstractProps } from '../AbstractPollAnswer';
  9. const useStyles = makeStyles()(theme => {
  10. return {
  11. container: {
  12. margin: '24px',
  13. padding: '16px',
  14. backgroundColor: theme.palette.ui02,
  15. borderRadius: '8px'
  16. },
  17. header: {
  18. marginBottom: '24px'
  19. },
  20. question: {
  21. ...withPixelLineHeight(theme.typography.heading6),
  22. color: theme.palette.text01,
  23. marginBottom: '8px'
  24. },
  25. creator: {
  26. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  27. color: theme.palette.text02
  28. },
  29. answerList: {
  30. listStyleType: 'none',
  31. margin: 0,
  32. padding: 0,
  33. marginBottom: '24px'
  34. },
  35. answer: {
  36. display: 'flex',
  37. marginBottom: '16px'
  38. },
  39. footer: {
  40. display: 'flex',
  41. justifyContent: 'flex-end'
  42. },
  43. buttonMargin: {
  44. marginRight: theme.spacing(3)
  45. }
  46. };
  47. });
  48. const PollAnswer = ({
  49. creatorName,
  50. checkBoxStates,
  51. poll,
  52. setCheckbox,
  53. skipAnswer,
  54. skipChangeVote,
  55. submitAnswer,
  56. t
  57. }: AbstractProps) => {
  58. const { changingVote } = poll;
  59. const { classes } = useStyles();
  60. return (
  61. <div className = { classes.container }>
  62. <div className = { classes.header }>
  63. <div className = { classes.question }>
  64. { poll.question }
  65. </div>
  66. <div className = { classes.creator }>
  67. { t('polls.by', { name: creatorName }) }
  68. </div>
  69. </div>
  70. <ul className = { classes.answerList }>
  71. {
  72. poll.answers.map((answer: any, index: number) => (
  73. <li
  74. className = { classes.answer }
  75. key = { index }>
  76. <Checkbox
  77. checked = { checkBoxStates[index] }
  78. key = { index }
  79. label = { answer.name }
  80. // eslint-disable-next-line react/jsx-no-bind
  81. onChange = { ev => setCheckbox(index, ev.target.checked) } />
  82. </li>
  83. ))
  84. }
  85. </ul>
  86. <div className = { classes.footer } >
  87. <Button
  88. accessibilityLabel = { t('polls.answer.skip') }
  89. className = { classes.buttonMargin }
  90. labelKey = { 'polls.answer.skip' }
  91. onClick = { changingVote ? skipChangeVote : skipAnswer }
  92. type = { BUTTON_TYPES.SECONDARY } />
  93. <Button
  94. accessibilityLabel = { t('polls.answer.submit') }
  95. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  96. labelKey = { 'polls.answer.submit' }
  97. onClick = { submitAnswer } />
  98. </div>
  99. </div>
  100. );
  101. };
  102. /*
  103. * We apply AbstractPollAnswer to fill in the AbstractProps common
  104. * to both the web and native implementations.
  105. */
  106. // eslint-disable-next-line new-cap
  107. export default AbstractPollAnswer(PollAnswer);