This commit is contained in:
syuilo 2018-02-08 14:54:16 +09:00
parent 43525c4839
commit 941206922a

View file

@ -1,19 +1,19 @@
<template> <template>
<div :data-is-voted="isVoted"> <div :data-is-voted="isVoted">
<ul> <ul>
<li v-for="choice in poll.choices" :key="choice.id" @click="vote.bind(choice.id)" :class="{ voted: choice.voted }" :title="!choice.isVoted ? '%i18n:common.tags.mk-poll.vote-to%'.replace('{}', choice.text) : ''"> <li v-for="choice in poll.choices" :key="choice.id" @click="vote.bind(choice.id)" :class="{ voted: choice.voted }" :title="!isVoted ? '%i18n:common.tags.mk-poll.vote-to%'.replace('{}', choice.text) : ''">
<div class="backdrop" :style="{ 'width:' + (result ? (choice.votes / total * 100) : 0) + '%' }"></div> <div class="backdrop" :style="{ 'width:' + (result ? (choice.votes / total * 100) : 0) + '%' }"></div>
<span> <span>
<template v-if="is_voted">%fa:check%</template> <template v-if="choice.is_voted">%fa:check%</template>
{{ text }} {{ text }}
<span class="votes" v-if="parent.result">({{ '%i18n:common.tags.mk-poll.vote-count%'.replace('{}', votes) }})</span> <span class="votes" v-if="result">({{ '%i18n:common.tags.mk-poll.vote-count%'.replace('{}', choice.votes) }})</span>
</span> </span>
</li> </li>
</ul> </ul>
<p v-if="total > 0"> <p v-if="total > 0">
<span>{ '%i18n:common.tags.mk-poll.total-users%'.replace('{}', total) }</span> <span>{{ '%i18n:common.tags.mk-poll.total-users%'.replace('{}', total) }}</span>
<a v-if="!isVoted" @click="toggleResult">{ result ? '%i18n:common.tags.mk-poll.vote%' : '%i18n:common.tags.mk-poll.show-result%' }</a> <a v-if="!isVoted" @click="toggleResult">{{ result ? '%i18n:common.tags.mk-poll.vote%' : '%i18n:common.tags.mk-poll.show-result%' }}</a>
<span v-if="isVoted">%i18n:common.tags.mk-poll.voted%</span> <span v-if="isVoted">%i18n:common.tags.mk-poll.voted%</span>
</p> </p>
</div> </div>
@ -59,59 +59,55 @@
}; };
</script> </script>
<mk-poll data-is-voted={ isVoted }> <style lang="stylus" scoped>
:scope
display block
<style lang="stylus" scoped> > ul
:scope
display block display block
margin 0
padding 0
list-style none
> ul > li
display block display block
margin 0 margin 4px 0
padding 0 padding 4px 8px
list-style none width 100%
border solid 1px #eee
border-radius 4px
overflow hidden
cursor pointer
> li &:hover
display block background rgba(0, 0, 0, 0.05)
margin 4px 0
padding 4px 8px
width 100%
border solid 1px #eee
border-radius 4px
overflow hidden
cursor pointer
&:hover &:active
background rgba(0, 0, 0, 0.05) background rgba(0, 0, 0, 0.1)
&:active > .backdrop
background rgba(0, 0, 0, 0.1) position absolute
top 0
left 0
height 100%
background $theme-color
transition width 1s ease
> .backdrop > .votes
position absolute margin-left 4px
top 0
left 0
height 100%
background $theme-color
transition width 1s ease
> .votes > p
margin-left 4px a
color inherit
> p &[data-is-voted]
a > ul > li
color inherit cursor default
&[data-is-voted] &:hover
> ul > li background transparent
cursor default
&:hover &:active
background transparent background transparent
&:active </style>
background transparent
</style>
</mk-poll>