| 1 |
<script setup lang="ts"> |
| 2 |
interface Props { |
| 3 |
stepsCount: number; |
| 4 |
isClickable?: boolean; |
| 5 |
wide?: boolean; |
| 6 |
step?: number; |
| 7 |
} |
| 8 |
|
| 9 |
type Emits = { |
| 10 |
(eventName: 'on-click', index: number): void; |
| 11 |
}; |
| 12 |
|
| 13 |
const props = withDefaults(defineProps<Props>(), { |
| 14 |
stepsCount: 0, |
| 15 |
isClickable: false, |
| 16 |
wide: false, |
| 17 |
step: 0 |
| 18 |
}); |
| 19 |
|
| 20 |
const emit = defineEmits<Emits>(); |
| 21 |
|
| 22 |
const getIsActive = (index: number, step: number) => |
| 23 |
(!props.isClickable && index <= step) || (props.isClickable && index === step); |
| 24 |
</script> |
| 25 |
|
| 26 |
<template> |
| 27 |
<div class="stepper"> |
| 28 |
<div |
| 29 |
v-for="(_, index) in stepsCount" |
| 30 |
:key="index" |
| 31 |
class="stepper__indicator" |
| 32 |
:class="{ |
| 33 |
'stepper__indicator--active': getIsActive(index, step), |
| 34 |
'stepper__indicator--clickable': isClickable, |
| 35 |
'stepper__indicator--wide': wide |
| 36 |
}" |
| 37 |
@click="emit('on-click', index)" |
| 38 |
/> |
| 39 |
</div> |
| 40 |
</template> |
| 41 |
|
| 42 |
<style lang="scss" scoped> |
| 43 |
.stepper { |
| 44 |
display: flex; |
| 45 |
justify-content: center; |
| 46 |
margin-top: 24px; |
| 47 |
|
| 48 |
&__indicator { |
| 49 |
width: 8px; |
| 50 |
height: 8px; |
| 51 |
margin-left: 4px; |
| 52 |
border-radius: 50%; |
| 53 |
background-color: rgba(114, 117, 134, 0.3); |
| 54 |
|
| 55 |
&--wide { |
| 56 |
margin: 0 8px; |
| 57 |
} |
| 58 |
&--active { |
| 59 |
background-color: var(--primary); |
| 60 |
} |
| 61 |
&--clickable { |
| 62 |
cursor: pointer; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
</style> |
| 67 |
|