2FAuth/resources/js_vue3/components/Dots.vue

54 lines
1.1 KiB
Vue
Raw Normal View History

2023-10-19 11:40:19 +02:00
<script setup>
const props = defineProps({
stepCount: {
type: Number,
default: 10
},
initialIndex: {
type: Number,
default: null
},
2023-10-24 13:27:50 +02:00
period: { // Used only to identify the dots component in Accounts.vue
type: Number,
default: null
},
2023-10-19 11:40:19 +02:00
})
const activeDot = ref(0)
const isOff = computed(() => {
return activeDot.value == -1
})
/**
* Turns On dots
*/
function turnOn(index) {
activeDot.value = index < props.stepCount ? index + 1 : 1
}
/**
* Turns Off all dots
*/
function turnOff() {
activeDot.value = -1
}
onMounted(() => {
if (props.initialIndex != null) {
turnOn(props.initialIndex)
}
})
defineExpose({
turnOn,
2023-10-24 13:27:50 +02:00
turnOff,
props
2023-10-19 11:40:19 +02:00
})
</script>
<template>
<ul class="dots" :class="{'off' : isOff}">
<li v-for="n in stepCount" :key="n" :data-is-active="n == activeDot ? true : null"></li>
</ul>
</template>