2018-02-14 06:36:30 -06:00
|
|
|
<template>
|
|
|
|
<div class="mk-poll-editor">
|
|
|
|
<p class="caution" v-if="choices.length < 2">
|
2018-04-14 11:04:40 -05:00
|
|
|
%fa:exclamation-triangle%%i18n:@no-only-one-choice%
|
2018-02-14 06:36:30 -06:00
|
|
|
</p>
|
|
|
|
<ul ref="choices">
|
2018-02-21 14:57:24 -06:00
|
|
|
<li v-for="(choice, i) in choices">
|
2018-05-20 06:26:38 -05:00
|
|
|
<input :value="choice" @input="onInput(i, $event)" :placeholder="'%i18n:@choice-n%'.replace('{}', i + 1)">
|
2018-04-14 11:04:40 -05:00
|
|
|
<button @click="remove(i)" title="%i18n:@remove%">
|
2018-02-14 06:36:30 -06:00
|
|
|
%fa:times%
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2018-04-14 11:04:40 -05:00
|
|
|
<button class="add" v-if="choices.length < 10" @click="add">%i18n:@add%</button>
|
|
|
|
<button class="destroy" @click="destroy" title="%i18n:@destroy%">
|
2018-02-14 06:36:30 -06:00
|
|
|
%fa:times%
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-09-06 10:02:55 -05:00
|
|
|
import { erase } from '../../../../../prelude/array';
|
2018-02-14 06:36:30 -06:00
|
|
|
export default Vue.extend({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
choices: ['', '']
|
|
|
|
};
|
|
|
|
},
|
2018-02-21 14:57:24 -06:00
|
|
|
watch: {
|
|
|
|
choices() {
|
|
|
|
this.$emit('updated');
|
|
|
|
}
|
|
|
|
},
|
2018-02-14 06:36:30 -06:00
|
|
|
methods: {
|
|
|
|
onInput(i, e) {
|
2018-02-20 10:23:25 -06:00
|
|
|
Vue.set(this.choices, i, e.target.value);
|
2018-02-14 06:36:30 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
add() {
|
|
|
|
this.choices.push('');
|
2018-02-21 14:57:24 -06:00
|
|
|
this.$nextTick(() => {
|
|
|
|
(this.$refs.choices as any).childNodes[this.choices.length - 1].childNodes[0].focus();
|
|
|
|
});
|
2018-02-14 06:36:30 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
remove(i) {
|
|
|
|
this.choices = this.choices.filter((_, _i) => _i != i);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.$emit('destroyed');
|
|
|
|
},
|
|
|
|
|
|
|
|
get() {
|
|
|
|
return {
|
2018-09-06 10:02:55 -05:00
|
|
|
choices: erase('', this.choices)
|
2018-02-14 06:36:30 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
set(data) {
|
|
|
|
if (data.choices.length == 0) return;
|
|
|
|
this.choices = data.choices;
|
2018-02-21 14:57:24 -06:00
|
|
|
if (data.choices.length == 1) this.choices = this.choices.concat('');
|
2018-02-14 06:36:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-26 06:19:35 -05:00
|
|
|
|
2018-03-02 22:47:55 -06:00
|
|
|
|
2018-04-20 20:10:04 -05:00
|
|
|
root(isDark)
|
2018-02-14 06:36:30 -06:00
|
|
|
padding 8px
|
|
|
|
|
|
|
|
> .caution
|
|
|
|
margin 0 0 8px 0
|
|
|
|
font-size 0.8em
|
|
|
|
color #f00
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
> ul
|
|
|
|
display block
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
list-style none
|
|
|
|
|
|
|
|
> li
|
|
|
|
display block
|
|
|
|
margin 8px 0
|
|
|
|
padding 0
|
|
|
|
width 100%
|
|
|
|
|
|
|
|
&:first-child
|
|
|
|
margin-top 0
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
margin-bottom 0
|
|
|
|
|
|
|
|
> input
|
2018-02-24 12:05:29 -06:00
|
|
|
padding 6px 8px
|
|
|
|
width 300px
|
|
|
|
font-size 14px
|
2018-09-27 08:50:34 -05:00
|
|
|
color var(--inputText)
|
2018-04-20 20:10:04 -05:00
|
|
|
background isDark ? #191b22 : #fff
|
2018-09-26 06:19:35 -05:00
|
|
|
border solid 1px var(--primaryAlpha01)
|
2018-02-14 06:36:30 -06:00
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
&:hover
|
2018-09-26 06:19:35 -05:00
|
|
|
border-color var(--primaryAlpha02)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
&:focus
|
2018-09-26 06:19:35 -05:00
|
|
|
border-color var(--primaryAlpha05)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
> button
|
|
|
|
padding 4px 8px
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryAlpha04)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
&:hover
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryAlpha06)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryDarken30)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
> .add
|
|
|
|
margin 8px 0 0 0
|
|
|
|
vertical-align top
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primary)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
> .destroy
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
right 0
|
|
|
|
padding 4px 8px
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryAlpha04)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
&:hover
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryAlpha06)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 06:19:35 -05:00
|
|
|
color var(--primaryDarken30)
|
2018-02-14 06:36:30 -06:00
|
|
|
|
2018-04-20 20:10:04 -05:00
|
|
|
.mk-poll-editor[data-darkmode]
|
|
|
|
root(true)
|
|
|
|
|
|
|
|
.mk-poll-editor:not([data-darkmode])
|
|
|
|
root(false)
|
|
|
|
|
2018-02-14 06:36:30 -06:00
|
|
|
</style>
|