2023-12-09 15:47:03 +01:00
|
|
|
<template>
|
2024-04-15 19:39:03 +02:00
|
|
|
<input-wrapper v-bind="inputWrapperProps">
|
2023-12-09 15:47:03 +01:00
|
|
|
<template #label>
|
|
|
|
|
<slot name="label" />
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<div class="stars-outer">
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
v-for="i in starsCount"
|
|
|
|
|
:key="i"
|
|
|
|
|
class="cursor-pointer inline-block text-gray-200 dark:text-gray-800"
|
|
|
|
|
:class="{
|
|
|
|
|
'!text-yellow-400 active-star': i <= compVal,
|
|
|
|
|
'!text-yellow-200 !dark:text-yellow-800 hover-star':
|
|
|
|
|
i > compVal && i <= hoverRating,
|
|
|
|
|
'!cursor-not-allowed': disabled,
|
|
|
|
|
}"
|
|
|
|
|
role="button"
|
|
|
|
|
@click="setRating(i)"
|
|
|
|
|
@mouseenter="onMouseHover(i)"
|
|
|
|
|
@mouseleave="hoverRating = -1"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
2024-06-27 17:52:49 +02:00
|
|
|
<Icon
|
|
|
|
|
name="heroicons:star-20-solid"
|
|
|
|
|
:class="theme.RatingInput.size"
|
|
|
|
|
/>
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<template #help>
|
|
|
|
|
<slot name="help" />
|
|
|
|
|
</template>
|
|
|
|
|
<template #error>
|
|
|
|
|
<slot name="error" />
|
|
|
|
|
</template>
|
|
|
|
|
</input-wrapper>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-04-15 19:39:03 +02:00
|
|
|
import { inputProps, useFormInput } from "./useFormInput.js"
|
|
|
|
|
import InputWrapper from "./components/InputWrapper.vue"
|
2023-12-09 15:47:03 +01:00
|
|
|
|
|
|
|
|
export default {
|
2024-04-15 19:39:03 +02:00
|
|
|
name: "RatingInput",
|
2023-12-09 15:47:03 +01:00
|
|
|
components: { InputWrapper },
|
|
|
|
|
|
|
|
|
|
props: {
|
|
|
|
|
...inputProps,
|
2024-04-15 19:39:03 +02:00
|
|
|
numberOfStars: { type: Number, default: 5 },
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
|
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
setup(props, context) {
|
2023-12-09 15:47:03 +01:00
|
|
|
return {
|
2024-04-15 19:39:03 +02:00
|
|
|
...useFormInput(props, context),
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
data() {
|
2023-12-09 15:47:03 +01:00
|
|
|
return {
|
2024-04-15 19:39:03 +02:00
|
|
|
hoverRating: -1,
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2024-03-20 20:09:52 +01:00
|
|
|
computed: {
|
|
|
|
|
starsCount() {
|
|
|
|
|
if (!this.numberOfStars || this.numberOfStars < 1) {
|
|
|
|
|
return 5
|
|
|
|
|
}
|
|
|
|
|
return this.numberOfStars
|
2024-04-15 19:39:03 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
if (!this.compVal) this.compVal = 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updated() {
|
|
|
|
|
if (!this.compVal) {
|
|
|
|
|
this.compVal = 0
|
2024-03-20 20:09:52 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2023-12-09 15:47:03 +01:00
|
|
|
methods: {
|
2024-04-15 19:39:03 +02:00
|
|
|
onMouseHover(i) {
|
|
|
|
|
this.hoverRating = this.disabled ? -1 : i
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
2024-04-15 19:39:03 +02:00
|
|
|
setRating(val) {
|
2023-12-09 15:47:03 +01:00
|
|
|
if (this.disabled) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.compVal === val) {
|
|
|
|
|
this.compVal = 0
|
|
|
|
|
} else {
|
|
|
|
|
this.compVal = val
|
|
|
|
|
}
|
2024-04-15 19:39:03 +02:00
|
|
|
},
|
|
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
</script>
|