Skip to content

Commit

Permalink
fix: improve vote ui
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 15, 2023
1 parent 83a1980 commit 18ad1c2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions components/status/StatusPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ const votersCount = $computed(() => poll.votersCount ?? 0)
</script>

<template>
<div flex flex-col w-full items-stretch gap-3 dir="auto">
<form v-if="!poll.voted && !poll.expired" flex flex-col gap-4 accent-primary @click.stop="noop" @submit.prevent="vote">
<label v-for="(option, index) of poll.options" :key="index" flex items-center gap-2 px-2>
<div flex flex-col w-full items-stretch gap-2 py3 dir="auto">
<form v-if="!poll.voted && !poll.expired" flex="~ col gap3" accent-primary @click.stop="noop" @submit.prevent="vote">
<label v-for="(option, index) of poll.options" :key="index" flex="~ gap2" items-center>
<input name="choices" :value="index" :type="poll.multiple ? 'checkbox' : 'radio'">
{{ option.title }}
</label>
<button btn-solid>
<button btn-solid mt-1>
{{ $t('action.vote') }}
</button>
</form>
<template v-else>
<div v-for="(option, index) of poll.options" :key="index" py-1 relative :style="{ '--bar-width': toPercentage((option.votesCount || 0) / poll.votesCount) }">
<div
v-for="(option, index) of poll.options"
:key="index" py-1 relative
:style="{ '--bar-width': toPercentage((option.votesCount || 0) / poll.votesCount) }"
>
<div flex justify-between pb-2 w-full>
<span inline-flex align-items>
{{ option.title }}
Expand All @@ -62,7 +66,7 @@ const votersCount = $computed(() => poll.votersCount ?? 0)
</div>
</div>
</template>
<div text-sm flex="~ inline" gap-x-1>
<div text-sm flex="~ inline" gap-x-1 text-secondary>
<CommonLocalizedNumber
keypath="status.poll.count"
:count="poll.votesCount"
Expand Down

0 comments on commit 18ad1c2

Please sign in to comment.