Skip to content

Commit

Permalink
feat: added an option to hide next step while beforeStep hook is exec…
Browse files Browse the repository at this point in the history
…uting

resolve #76
  • Loading branch information
fatihsolhan committed Feb 9, 2024
1 parent 8b5dd13 commit 8571a93
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/pages/3.props/2.options.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ You can override `VOnboardingWrapper`'s options by passing options to `VOnboardi
previousButton: 'Previous',
nextButton: 'Next',
finishButton: 'Finish'
}
},
hideNextStepDuringHook: false
}
```
---
Expand All @@ -64,7 +65,7 @@ You can override `VOnboardingWrapper`'s options by passing options to `VOnboardi
| `labels.previousButton` | `String` | `Previous` |
| `labels.nextButton` | `String` | `Next` |
| `labels.finishButton` | `String` | `Finish` |

| `hideNextStepDuringHook` | `Boolean` | `false` |



Expand Down
15 changes: 12 additions & 3 deletions src/components/VOnboardingWrapper.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="!isFinished" data-v-onboarding-wrapper style="pointer-events: auto;">
<slot :key="index" :step="activeStep" :next="next" :previous="previous" :exit="exit" :is-first="isFirstStep"
:is-last="isLastStep" :index="index">
<slot v-if="showStep" :key="index" :step="activeStep" :next="next" :previous="previous" :exit="exit"
:is-first="isFirstStep" :is-last="isLastStep" :index="index">
<VOnboardingStep :key="index" />
</slot>
</div>
Expand Down Expand Up @@ -32,6 +32,7 @@ export default defineComponent({
emits: ['finish', 'exit'],
setup(props, { expose, emit }) {
const mergedOptions = computed(() => merge({}, defaultVOnboardingWrapperOptions, props.options))
const showStep = ref(true)
const index = ref(OnboardingState.IDLE)
const privateIndex = ref(index.value)
const setIndex = (value: number | ((_: number) => number)) => {
Expand All @@ -45,6 +46,9 @@ export default defineComponent({
const activeStepMergedOptions = computed(() => {
return activeStep.value ? merge({}, mergedOptions.value, activeStep.value.options) : mergedOptions.value
})
const mergeOptions = (step: StepEntity) => {
return merge({}, mergedOptions.value, step.options)
}
const { beforeHook, afterHook } = useStepHooks(activeStepMergedOptions)
watch(index, async (newIndex, oldIndex) => {
const direction: number = newIndex < oldIndex ? Direction.BACKWARD : Direction.FORWARD
Expand Down Expand Up @@ -73,9 +77,13 @@ export default defineComponent({
step: newStep,
}
removePointerEvents(useGetElement(newStep.attachTo.element) as HTMLElement)
if (mergeOptions(newStep)?.hideNextStepDuringHook) {
showStep.value = false
}
await beforeHook(newStep, beforeHookOptions)
}
privateIndex.value = newIndex
showStep.value = true
removePointerEvents(useGetElement('body') as HTMLElement)
if (activeStepMergedOptions.value.overlay?.preventOverlayInteraction) {
updateBodyPointerEvents()
Expand Down Expand Up @@ -137,7 +145,8 @@ export default defineComponent({
isFirstStep: state.value.isFirstStep,
isLastStep: state.value.isLastStep,
finish,
exit
exit,
showStep
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/types/VOnboardingWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface VOnboardingWrapperOptions {
nextButton?: string
finishButton?: string
}
hideNextStepDuringHook?: boolean
}

export const defaultVOnboardingWrapperOptions: VOnboardingWrapperOptions = {
Expand Down Expand Up @@ -63,5 +64,6 @@ export const defaultVOnboardingWrapperOptions: VOnboardingWrapperOptions = {
previous: false,
next: false,
exit: false
}
},
hideNextStepDuringHook: false
}

0 comments on commit 8571a93

Please sign in to comment.