Dots.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <script setup>
  2. const props = defineProps({
  3. stepCount: {
  4. type: Number,
  5. default: 10
  6. },
  7. initialIndex: {
  8. type: Number,
  9. default: null
  10. },
  11. period: { // Used only to identify the dots component in Accounts.vue
  12. type: Number,
  13. default: null
  14. },
  15. })
  16. const activeDot = ref(0)
  17. const isOff = computed(() => {
  18. return activeDot.value == -1
  19. })
  20. /**
  21. * Turns On dots
  22. */
  23. function turnOn(index) {
  24. activeDot.value = index < props.stepCount ? index + 1 : 1
  25. }
  26. /**
  27. * Turns Off all dots
  28. */
  29. function turnOff() {
  30. activeDot.value = -1
  31. }
  32. onMounted(() => {
  33. if (! isNaN(props.initialIndex)) {
  34. turnOn(props.initialIndex)
  35. }
  36. })
  37. defineExpose({
  38. turnOn,
  39. turnOff,
  40. props
  41. })
  42. </script>
  43. <template>
  44. <ul class="dots" :class="{'off' : isOff}">
  45. <li v-for="n in stepCount" :key="n" :data-is-active="n == activeDot ? true : null"></li>
  46. </ul>
  47. </template>