2022-04-06 11:01:37 +02:00
|
|
|
<script setup>
|
|
|
|
import { ref } from "vue";
|
|
|
|
import { Splide, SplideSlide } from "@splidejs/vue-splide";
|
|
|
|
import "@splidejs/splide/dist/css/splide.min.css";
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
question: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
});
|
2022-04-06 14:29:04 +02:00
|
|
|
const emits = defineEmits(["answerSelected", "nextQuestion"]);
|
2022-04-06 11:01:37 +02:00
|
|
|
|
|
|
|
const slides = ref();
|
2022-04-06 12:32:04 +02:00
|
|
|
|
|
|
|
const answerWeight = ref(props.question.weight);
|
2022-04-06 11:01:37 +02:00
|
|
|
|
|
|
|
function selectAnswer(answer) {
|
|
|
|
const answerIndex = props.question.answers.findIndex(
|
|
|
|
(a) => a.id === answer.id
|
|
|
|
);
|
|
|
|
slides.value.splide.go(answerIndex);
|
|
|
|
}
|
2022-04-06 12:32:04 +02:00
|
|
|
|
2022-04-06 11:01:37 +02:00
|
|
|
function slideMove(splide, newIndex) {
|
2022-04-06 14:29:04 +02:00
|
|
|
answerWeight.value = props.question.answers[newIndex].weight;
|
|
|
|
emits("answerSelected", props.question, answerWeight);
|
2022-04-06 11:01:37 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="main">
|
2023-04-24 23:15:13 +02:00
|
|
|
<div class="center">
|
2022-04-06 11:01:37 +02:00
|
|
|
<legend>{{ question.title }}</legend>
|
2023-04-24 23:15:13 +02:00
|
|
|
|
|
|
|
<div class="images">
|
|
|
|
<template v-if="question.answers">
|
|
|
|
<Splide
|
|
|
|
@splide:move="slideMove"
|
|
|
|
class="answers"
|
|
|
|
:id="`question_${question.id}`"
|
|
|
|
ref="slides"
|
|
|
|
>
|
|
|
|
<SplideSlide
|
|
|
|
v-for="answer in question.answers"
|
|
|
|
:key="answer.id"
|
|
|
|
@click="$emit('nextQuestion')"
|
|
|
|
>
|
|
|
|
<img height="200" :src="`/answers/${answer.image}.webp`" />
|
|
|
|
</SplideSlide>
|
|
|
|
</Splide>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
|
2022-04-06 11:01:37 +02:00
|
|
|
<template v-if="question.answers">
|
2023-04-24 23:15:13 +02:00
|
|
|
<ul class="choices">
|
|
|
|
<li
|
|
|
|
class="choice"
|
|
|
|
v-for="answer in question.answers"
|
|
|
|
:key="answer.id"
|
|
|
|
>
|
2022-04-06 11:01:37 +02:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
:data-answerId="answer.id"
|
|
|
|
:name="`question_${question.id}`"
|
2023-04-24 23:15:13 +02:00
|
|
|
:id="`question_${question.id}_answer_${answer.id}`"
|
2022-04-06 11:01:37 +02:00
|
|
|
:value="answer.weight"
|
|
|
|
v-model="answerWeight"
|
2022-04-06 14:29:04 +02:00
|
|
|
@change="selectAnswer(answer)"
|
|
|
|
@click="nextQuestion"
|
2022-04-06 11:01:37 +02:00
|
|
|
/>
|
2023-04-24 23:15:13 +02:00
|
|
|
<label :for="`question_${question.id}_answer_${answer.id}`">
|
|
|
|
{{ answer.title }}
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-04-06 11:01:37 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-06 14:40:34 +02:00
|
|
|
<style lang="sass">
|
2023-04-24 23:15:13 +02:00
|
|
|
.splide__arrow
|
|
|
|
background: transparent
|
|
|
|
border: 3px solid var(--color-green)
|
|
|
|
width: 3rem
|
|
|
|
height: 3rem
|
|
|
|
opacity: 1
|
|
|
|
|
|
|
|
svg
|
|
|
|
fill: var(--color-green)
|
|
|
|
height: 1.6rem
|
|
|
|
width: 1.6rem
|
2022-04-06 14:40:34 +02:00
|
|
|
.splide__pagination
|
|
|
|
bottom: -1.5em
|
2023-04-24 23:15:13 +02:00
|
|
|
.splide__pagination__page
|
|
|
|
width: .7rem
|
|
|
|
height: .7rem
|
|
|
|
background: var(--color-green)
|
|
|
|
|
|
|
|
&.is-active
|
|
|
|
background: var(--color-green)
|
2022-04-06 14:40:34 +02:00
|
|
|
</style>
|
|
|
|
|
2022-04-06 11:01:37 +02:00
|
|
|
<style lang="sass" scoped>
|
2023-04-24 23:15:13 +02:00
|
|
|
|
|
|
|
legend
|
|
|
|
text-align: center
|
|
|
|
font-size: 1.4rem
|
|
|
|
line-height: 2rem
|
|
|
|
margin: 1rem
|
|
|
|
|
|
|
|
.choices
|
|
|
|
list-style-type: none
|
|
|
|
text-align: left
|
|
|
|
display: inline-block
|
|
|
|
padding-left: 0
|
|
|
|
|
|
|
|
input[type=radio]
|
|
|
|
display: none
|
|
|
|
|
|
|
|
& + label
|
|
|
|
position: relative
|
|
|
|
padding-left: 2rem
|
|
|
|
& + label::before,
|
|
|
|
& + label::after
|
|
|
|
display: block
|
|
|
|
position: absolute
|
|
|
|
box-sizing: border-box
|
|
|
|
content:''
|
|
|
|
border-radius: 1rem
|
|
|
|
& + label::before
|
|
|
|
bottom: 0
|
|
|
|
left: 0
|
|
|
|
background-color: var(--color-green)
|
|
|
|
width: 1rem
|
|
|
|
height: 1rem
|
|
|
|
& + label::after
|
|
|
|
bottom: 3px
|
|
|
|
left: 3px
|
|
|
|
width: calc(1rem - 6px)
|
|
|
|
height: calc(1rem - 6px)
|
|
|
|
&:checked + label::before
|
|
|
|
background-color: white
|
|
|
|
&:checked + label::after
|
|
|
|
background-color: var(--color-green)
|
2022-04-06 11:01:37 +02:00
|
|
|
|
|
|
|
.main
|
|
|
|
height: 100%
|
|
|
|
max-width: 100%
|
|
|
|
display: flex
|
|
|
|
flex-direction: column
|
|
|
|
justify-content: space-around
|
|
|
|
align-items: center
|
|
|
|
|
2023-04-24 23:15:13 +02:00
|
|
|
.center
|
|
|
|
width: 100%
|
|
|
|
text-align: center
|
|
|
|
|
|
|
|
.images
|
|
|
|
margin: 3rem auto
|
2022-04-06 11:01:37 +02:00
|
|
|
width: 400px
|
|
|
|
max-width: 100%
|
|
|
|
min-width: 280px
|
|
|
|
|
2023-04-24 23:15:13 +02:00
|
|
|
h2
|
|
|
|
font-size: 2rem
|
|
|
|
|
2022-04-06 11:01:37 +02:00
|
|
|
.answers
|
|
|
|
text-align: center
|
|
|
|
|
|
|
|
@media only screen and (orientation : landscape)
|
|
|
|
.main
|
|
|
|
flex-direction: row
|
|
|
|
|
2023-04-24 23:15:13 +02:00
|
|
|
.images
|
2022-04-06 11:01:37 +02:00
|
|
|
max-width: 50%
|
|
|
|
</style>
|