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

180 行
4.0 KiB
Vue
Raw 通常表示 履歴

2019-06-19 05:28:31 +09:00
<template>
2019-07-05 16:17:44 +09:00
<div
class="poll"
:class="containerClass"
>
2019-06-19 05:28:31 +09:00
<div
2023-02-19 03:40:42 +09:00
:role="showResults ? 'section' : (poll.multiple ? 'group' : 'radiogroup')"
2019-06-19 05:28:31 +09:00
>
2019-07-05 16:17:44 +09:00
<div
2023-02-19 03:40:42 +09:00
v-for="(option, index) in options"
:key="index"
class="poll-option"
2019-07-05 16:17:44 +09:00
>
2023-02-19 03:40:42 +09: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-19 05:28:31 +09:00
</div>
<div
v-else
2023-02-19 03:40:42 +09:00
tabindex="0"
:role="poll.multiple ? 'checkbox' : 'radio'"
:aria-labelledby="`option-vote-${randomSeed}-${index}`"
:aria-checked="choices[index]"
@click="activateOption(index)"
2019-06-19 05:28:31 +09:00
>
2023-02-19 03:40:42 +09:00
<input
v-if="poll.multiple"
type="checkbox"
class="poll-checkbox"
:disabled="loading"
:value="index"
>
<input
v-else
type="radio"
:disabled="loading"
:value="index"
>
<label class="option-vote">
<RichContent
:id="`option-vote-${randomSeed}-${index}`"
:html="option.title_html"
:handle-links="false"
:emoji="emoji"
/>
</label>
</div>
2019-06-19 05:28:31 +09:00
</div>
</div>
<div class="footer faint">
<button
v-if="!showResults"
class="btn button-default poll-vote-button"
2019-06-19 05:28:31 +09:00
type="button"
:disabled="isDisabled"
2019-07-05 16:17:44 +09:00
@click="vote"
2019-06-19 05:28:31 +09:00
>
2019-07-05 16:17:44 +09:00
{{ $t('polls.vote') }}
2019-06-19 05:28:31 +09:00
</button>
<div class="total">
<template v-if="typeof poll.voters_count === 'number'">
{{ $tc("polls.people_voted_count", poll.voters_count, { count: poll.voters_count }) }}&nbsp;·&nbsp;
</template>
<template v-else>
{{ $tc("polls.votes_count", poll.votes_count, { count: poll.votes_count }) }}&nbsp;·&nbsp;
</template>
2019-06-19 05:28:31 +09:00
</div>
2022-03-30 01:04:01 +09:00
<span>
<i18n-t
scope="global"
:keypath="expired ? 'polls.expired' : 'polls.expires_in'"
>
<Timeago
:time="expiresAt"
:auto-update="60"
:now-threshold="0"
/>
</i18n-t>
</span>
2019-06-19 05:28:31 +09:00
</div>
</div>
</template>
<script src="./poll.js"></script>
<style lang="scss">
2023-01-10 03:02:16 +09:00
@import "../../variables";
2019-06-19 05:28:31 +09:00
.poll {
.votes {
display: flex;
flex-direction: column;
margin: 0 0 0.5em;
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.poll-option {
2019-06-20 22:00:10 +09:00
margin: 0.75em 0.5em;
2019-06-19 05:28:31 +09:00
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.option-result {
height: 100%;
display: flex;
flex-direction: row;
position: relative;
color: $fallback--lightText;
color: var(--lightText, $fallback--lightText);
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.option-result-label {
display: flex;
align-items: center;
padding: 0.1em 0.25em;
z-index: 1;
2020-08-25 18:17:42 +09:00
word-break: break-word;
2019-06-19 05:28:31 +09:00
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.result-percentage {
width: 3.5em;
2019-06-20 22:00:10 +09:00
flex-shrink: 0;
2019-06-19 05:28:31 +09:00
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.result-fill {
height: 100%;
position: absolute;
2020-01-13 06:41:11 +09:00
color: $fallback--text;
color: var(--pollText, $fallback--text);
2019-06-19 05:28:31 +09:00
background-color: $fallback--lightBg;
2020-01-13 06:41:11 +09:00
background-color: var(--poll, $fallback--lightBg);
2019-06-19 05:28:31 +09:00
border-radius: $fallback--panelRadius;
border-radius: var(--panelRadius, $fallback--panelRadius);
top: 0;
left: 0;
transition: width 0.5s;
}
2023-01-10 03:02:16 +09:00
2019-06-20 22:00:10 +09:00
.option-vote {
display: flex;
align-items: center;
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
input {
width: 3.5em;
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.footer {
display: flex;
align-items: center;
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
&.loading * {
cursor: progress;
}
2023-01-10 03:02:16 +09:00
2019-06-19 05:28:31 +09:00
.poll-vote-button {
padding: 0 0.5em;
margin-right: 0.5em;
}
2023-02-19 03:40:42 +09:00
.poll-checkbox {
display: none;
}
2019-06-19 05:28:31 +09:00
}
</style>