logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

poll.vue (3999B)


  1. <template>
  2. <div
  3. class="poll"
  4. :class="containerClass"
  5. >
  6. <div
  7. :role="showResults ? 'section' : (poll.multiple ? 'group' : 'radiogroup')"
  8. >
  9. <div
  10. v-for="(option, index) in options"
  11. :key="index"
  12. class="poll-option"
  13. >
  14. <div
  15. v-if="showResults"
  16. :title="resultTitle(option)"
  17. class="option-result"
  18. >
  19. <div class="option-result-label">
  20. <span class="result-percentage">
  21. {{ percentageForOption(option.votes_count) }}%
  22. </span>
  23. <RichContent
  24. :html="option.title_html"
  25. :handle-links="false"
  26. :emoji="emoji"
  27. />
  28. </div>
  29. <div
  30. class="result-fill"
  31. :style="{ 'width': `${percentageForOption(option.votes_count)}%` }"
  32. />
  33. </div>
  34. <div
  35. v-else
  36. tabindex="0"
  37. :role="poll.multiple ? 'checkbox' : 'radio'"
  38. :aria-labelledby="`option-vote-${randomSeed}-${index}`"
  39. :aria-checked="choices[index]"
  40. class="input unstyled"
  41. @click="activateOption(index)"
  42. >
  43. <!-- TODO: USE CHECKBOX -->
  44. <input
  45. v-if="poll.multiple"
  46. type="checkbox"
  47. class="input -checkbox poll-checkbox"
  48. :disabled="loading"
  49. :value="index"
  50. >
  51. <input
  52. v-else
  53. type="radio"
  54. :disabled="loading"
  55. :value="index"
  56. class="input -radio"
  57. >
  58. <label class="option-vote">
  59. <RichContent
  60. :id="`option-vote-${randomSeed}-${index}`"
  61. :html="option.title_html"
  62. :handle-links="false"
  63. :emoji="emoji"
  64. />
  65. </label>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="footer faint">
  70. <button
  71. v-if="!showResults"
  72. class="btn button-default poll-vote-button"
  73. type="button"
  74. :disabled="isDisabled"
  75. @click="vote"
  76. >
  77. {{ $t('polls.vote') }}
  78. </button>
  79. <div class="total">
  80. <template v-if="typeof poll.voters_count === 'number'">
  81. {{ $tc("polls.people_voted_count", poll.voters_count, { count: poll.voters_count }) }}
  82. </template>
  83. <template v-else>
  84. {{ $tc("polls.votes_count", poll.votes_count, { count: poll.votes_count }) }}
  85. </template>
  86. <span v-if="expiresAt !== null">
  87. &nbsp;ยท&nbsp;
  88. </span>
  89. </div>
  90. <span v-if="expiresAt !== null">
  91. <i18n-t
  92. scope="global"
  93. :keypath="expired ? 'polls.expired' : 'polls.expires_in'"
  94. >
  95. <Timeago
  96. :time="expiresAt"
  97. :auto-update="60"
  98. :now-threshold="0"
  99. />
  100. </i18n-t>
  101. </span>
  102. </div>
  103. </div>
  104. </template>
  105. <script src="./poll.js"></script>
  106. <style lang="scss">
  107. .poll {
  108. .votes {
  109. display: flex;
  110. flex-direction: column;
  111. margin: 0 0 0.5em;
  112. }
  113. .poll-option {
  114. margin: 0.75em 0.5em;
  115. .input {
  116. line-height: inherit;
  117. }
  118. }
  119. .option-result {
  120. height: 100%;
  121. display: flex;
  122. flex-direction: row;
  123. position: relative;
  124. color: var(--textLight);
  125. }
  126. .option-result-label {
  127. display: flex;
  128. align-items: center;
  129. padding: 0.1em 0.25em;
  130. z-index: 1;
  131. word-break: break-word;
  132. }
  133. .result-percentage {
  134. width: 3.5em;
  135. flex-shrink: 0;
  136. }
  137. .result-fill {
  138. height: 100%;
  139. position: absolute;
  140. border-radius: var(--roundness);
  141. top: 0;
  142. left: 0;
  143. transition: width 0.5s;
  144. }
  145. .option-vote {
  146. display: flex;
  147. align-items: center;
  148. }
  149. input {
  150. width: 3.5em;
  151. }
  152. .footer {
  153. display: flex;
  154. align-items: center;
  155. }
  156. &.loading * {
  157. cursor: progress;
  158. }
  159. .poll-vote-button {
  160. padding: 0 0.5em;
  161. margin-right: 0.5em;
  162. }
  163. .poll-checkbox {
  164. display: none;
  165. }
  166. }
  167. </style>