Skip to content

Commit

Permalink
Merge pull request #73 from rozsazoltan/main
Browse files Browse the repository at this point in the history
feat: finish by exit and show/hide exit button
  • Loading branch information
fatihsolhan authored May 22, 2023
2 parents 74729de + 73efe59 commit 07da5ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 6 additions & 2 deletions docs/pages/3.props/2.options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ You can override `VOnboardingWrapper`'s options by passing options to `VOnboardi
inline: 'center'
}
},
autoFinishByExit: true,
hideButtons: {
previous: false,
next: false
next: false,
exit: false
},
labels: {
previousButton: 'Previous',
Expand All @@ -51,9 +53,11 @@ You can override `VOnboardingWrapper`'s options by passing options to `VOnboardi
| `scrollToStep` | | |
| `scrollToStep.enabled` | `Boolean` | `true` |
| `scrollToStep.options` | [Scroll Into View Options](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) | `{ behavior: 'smooth', block: 'center', inline: 'center' }` |
| `hideButtons` | | Hide the `previous` or `next` Button|
| `autoFinishByExit` | `Boolean` | `true` (Close `overlay` when click `exit` Button)
| `hideButtons` | | Hide the `previous`, `next` or `exit` Button|
| `hideButtons.previous` | `Boolean` | `false` |
| `hideButtons.next` | `Boolean` | `false` |
| `hideButtons.exit` | `Boolean` | `false` |
| `labels` | | |
| `labels.previousButton` | `String` | `Previous` |
| `labels.nextButton` | `String` | `Next` |
Expand Down
15 changes: 12 additions & 3 deletions src/components/VOnboardingStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
v-if="step.content.title"
class="v-onboarding-item__header-title"
>{{ step.content.title }}</span>
<button @click="exit" class="v-onboarding-item__header-close">
<button v-if="isButtonVisible.exit" @click="exit" class="v-onboarding-item__header-close">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4"
Expand Down Expand Up @@ -64,14 +64,15 @@ export default defineComponent({
const show = ref(false)
const state = inject(STATE_INJECT_KEY, {} as Ref<OnboardingState>)
const { step, isFirstStep, isLastStep, options, next, previous, exit, finish } = toRefs(state.value)
const { step, isFirstStep, isLastStep, options, next, previous, exit: stateExit, finish } = toRefs(state.value)
const mergedOptions = computed(() => merge({}, options?.value, step.value.options))
const isButtonVisible = computed(() => {
return {
previous: !mergedOptions.value.hideButtons?.previous,
next: !mergedOptions.value.hideButtons?.next
next: !mergedOptions.value.hideButtons?.next,
exit: !mergedOptions.value.hideButtons?.exit
}
})
Expand Down Expand Up @@ -103,6 +104,14 @@ export default defineComponent({
}
};
watch(step, attachElement, { immediate: true })
const exit = () => {
stateExit.value()
if (mergedOptions.value?.autoFinishByExit) {
finish.value()
}
}
return {
stepElement,
next,
Expand Down
6 changes: 5 additions & 1 deletion src/types/VOnboardingWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export interface VOnboardingWrapperOptions {
enabled?: boolean
options?: ScrollIntoViewOptions
},
autoFinishByExit?: boolean
hideButtons?: {
previous?: boolean
next?: boolean
exit?: boolean
},
labels?: {
previousButton?: string
Expand All @@ -49,13 +51,15 @@ export const defaultVOnboardingWrapperOptions: VOnboardingWrapperOptions = {
inline: 'center'
}
},
autoFinishByExit: true,
labels: {
previousButton: 'Previous',
nextButton: 'Next',
finishButton: 'Finish'
},
hideButtons: {
previous: false,
next: false
next: false,
exit: false
}
}

0 comments on commit 07da5ef

Please sign in to comment.