logo

pleroma-fe

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

poll.vue (4186B)


  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. <span
  80. v-if="poll.pleroma?.non_anonymous"
  81. :title="$t('polls.non_anonymous_title')"
  82. >
  83. {{ $t('polls.non_anonymous') }}
  84. &nbsp;·&nbsp;
  85. </span>
  86. <div class="total">
  87. <template v-if="typeof poll.voters_count === 'number'">
  88. {{ $t("polls.people_voted_count", { count: poll.voters_count }, poll.voters_count) }}
  89. </template>
  90. <template v-else>
  91. {{ $t("polls.votes_count", { count: poll.votes_count }, poll.votes_count) }}
  92. </template>
  93. <span v-if="expiresAt !== null">
  94. &nbsp;·&nbsp;
  95. </span>
  96. </div>
  97. <span v-if="expiresAt !== null">
  98. <i18n-t
  99. scope="global"
  100. :keypath="expired ? 'polls.expired' : 'polls.expires_in'"
  101. >
  102. <Timeago
  103. :time="expiresAt"
  104. :auto-update="60"
  105. :now-threshold="0"
  106. />
  107. </i18n-t>
  108. </span>
  109. </div>
  110. </div>
  111. </template>
  112. <script src="./poll.js"></script>
  113. <style lang="scss">
  114. .poll {
  115. .votes {
  116. display: flex;
  117. flex-direction: column;
  118. margin: 0 0 0.5em;
  119. }
  120. .poll-option {
  121. margin: 0.75em 0.5em;
  122. .input {
  123. line-height: inherit;
  124. }
  125. }
  126. .option-result {
  127. height: 100%;
  128. display: flex;
  129. flex-direction: row;
  130. position: relative;
  131. color: var(--textLight);
  132. }
  133. .option-result-label {
  134. display: flex;
  135. align-items: center;
  136. padding: 0.1em 0.25em;
  137. z-index: 1;
  138. word-break: break-word;
  139. }
  140. .result-percentage {
  141. width: 3.5em;
  142. flex-shrink: 0;
  143. }
  144. .result-fill {
  145. height: 100%;
  146. position: absolute;
  147. border-radius: var(--roundness);
  148. top: 0;
  149. left: 0;
  150. transition: width 0.5s;
  151. }
  152. .option-vote {
  153. display: flex;
  154. align-items: center;
  155. }
  156. input {
  157. width: 3.5em;
  158. }
  159. .footer {
  160. display: flex;
  161. align-items: center;
  162. }
  163. &.loading * {
  164. cursor: progress;
  165. }
  166. .poll-vote-button {
  167. padding: 0 0.5em;
  168. margin-right: 0.5em;
  169. }
  170. .poll-checkbox {
  171. display: none;
  172. }
  173. }
  174. </style>