pleroma-fe/src/components/poll/poll.vue

105 lines
2.9 KiB
Vue
Raw Normal View History

2019-06-18 20:28:31 +00:00
<template>
2019-07-05 10:17:44 +03:00
<div
class="poll"
:class="containerClass"
>
2019-06-18 20:28:31 +00:00
<div
2023-02-18 13:40:42 -05:00
:role="showResults ? 'section' : (poll.multiple ? 'group' : 'radiogroup')"
2019-06-18 20:28:31 +00:00
>
2019-07-05 10:17:44 +03:00
<div
2023-02-18 13:40:42 -05:00
v-for="(option, index) in options"
:key="index"
class="poll-option"
2019-07-05 10:17:44 +03:00
>
2023-02-18 13:40:42 -05:00
<div
v-if="showResults"
:title="resultTitle(option)"
class="option-result"
>
<div class="option-result-label">
<span class="result-percentage">
{{ percentageForOption(option.votes_count) }}%
</span>
<RichContent
:html="option.title_html"
:handle-links="false"
:emoji="emoji"
/>
</div>
<div
class="result-fill"
:style="{ 'width': `${percentageForOption(option.votes_count)}%` }"
/>
2019-06-18 20:28:31 +00:00
</div>
<div
v-else
2023-02-18 13:40:42 -05:00
tabindex="0"
:role="poll.multiple ? 'checkbox' : 'radio'"
:aria-labelledby="`option-vote-${randomSeed}-${index}`"
:aria-checked="choices[index]"
2019-06-18 20:28:31 +00:00
>
2025-03-13 02:10:20 +02:00
<Checkbox
:radio="!poll.multiple"
2023-02-18 13:40:42 -05:00
:disabled="loading"
2025-03-13 02:10:20 +02:00
:model-value="choices[index]"
@update:model-value="value => activateOption(index, value)"
2023-02-18 13:40:42 -05:00
>
<RichContent
:id="`option-vote-${randomSeed}-${index}`"
:html="option.title_html"
:handle-links="false"
:emoji="emoji"
/>
2025-03-13 02:10:20 +02:00
</Checkbox>
2023-02-18 13:40:42 -05:00
</div>
2019-06-18 20:28:31 +00:00
</div>
</div>
<div class="footer faint">
<p>
<span
v-if="poll.pleroma?.non_anonymous"
:title="$t('polls.non_anonymous_title')"
>
{{ $t('polls.non_anonymous') }}
&nbsp;·&nbsp;
</span>
<span class="total">
<template v-if="typeof poll.voters_count === 'number'">
{{ $t("polls.people_voted_count", { count: poll.voters_count }, poll.voters_count) }}
</template>
<template v-else>
{{ $t("polls.votes_count", { count: poll.votes_count }, poll.votes_count) }}
</template>
<span v-if="expiresAt !== null">
&nbsp;·&nbsp;
</span>
</span>
<span v-if="expiresAt !== null">
<i18n-t
scope="global"
:keypath="expirationLabel"
>
<Timeago
:time="expiresAt"
:auto-update="60"
:now-threshold="0"
/>
</i18n-t>
</span>
</p>
2019-06-18 20:28:31 +00:00
<button
v-if="!showResults"
class="btn button-default poll-vote-button"
2019-06-18 20:28:31 +00:00
type="button"
:disabled="isDisabled"
2019-07-05 10:17:44 +03:00
@click="vote"
2019-06-18 20:28:31 +00:00
>
2019-07-05 10:17:44 +03:00
{{ $t('polls.vote') }}
2019-06-18 20:28:31 +00:00
</button>
</div>
</div>
</template>
<script src="./poll.js"></script>
2025-03-13 02:23:18 +02:00
<style src="./poll.scss" lang="scss" />