Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
#27 Add slots for custom-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
cristijora committed Aug 28, 2017
1 parent 3c75843 commit d9c9b1e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 45 deletions.
33 changes: 23 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,32 @@ Vue-form-wizard emits certain events when certain actions happen inside the comp
* **prev** - Previous button content (no need to worry about handling the button functionality)
* **next** - Next button content
* **finish** - Finish button content
* **custom-buttons-left** - Appears on right of "Back" button
* **custom-buttons-right** - Appears on the left of "Next/Finish" button

## Scoped slots
Form-wizard exposes 2 scoped slots which can be used to customize some parts of the wizard. Usage example and implementation details are presented in [0.6.2 release](https://github.com/cristijora/vue-form-wizard/releases/tag/v0.6.2)

Form-wizard exposes multiple scoped slots which can be used to customize some parts of the wizard. Usage example and implementation details are presented in [0.6.2 release](https://github.com/cristijora/vue-form-wizard/releases/tag/v0.6.2)
Since [0.6.3](https://github.com/cristijora/vue-form-wizard/releases/tag/v0.6.3), button slots can be also used as scoped slots and have the following methods/properties exposed

* **prev** - Previous button content (no need to worry about handling the button functionality)
* **next** - Next button content
* **finish** - Finish button content
* **custom-buttons-left** - Appears on right of "Back" button
* **custom-buttons-right** - Appears on the left of "Next/Finish" button

- nextTab // will go to the next tab/step when called
- prevTab //will got to the prev tab/step when called
- activeTabIndex // current active tab index
- isLastStep // boolean to tell whether it's the last step or not
- fillButtonStyle // object with styles for wizard-buttons (contains background and color passed through wizard props)

These properties apply to the following slots: prev, next, finish ,custom-buttons-left, custom-buttons-right, footer

### Footer slot
Has the buttons (back, next, finish) as default. When using this slot, those buttons are replaced with the content of your slot. You can achieve the same default functionallity and event tweak it with the help of the exposed methods/properties from `props`
The footer slot would be usually used to replace the whole content of your footer. By default it contains the wizard buttons (back, next, finish). When using this slot, those buttons are replaced with the content of your slot. You can achieve the same default functionallity and event tweak it with the help of the exposed methods/properties from `props`
Note that using this slot, means that you have to handle some of the wizard logic through the exposed methods/properties defined above and your template might get more verbose. If you need very fine customizations and more control over the wizard button actions
then you could use this slot. Otherwise, you could stick with the buttons slots.
One potential usage can be that you want to have a different button when completing the wizard. Maybe you want to position it in the center, give it a different color and click event
```html
<template slot="footer" scope="props">
Expand All @@ -170,13 +190,6 @@ One potential usage can be that you want to have a different button when complet
This is just one example. You can add more buttons, hide or display conditionally based on the exposed properties.
Working fiddle for the [example above](https://jsfiddle.net/bt5dhqtf/717/)

#### Exposed props for `footer` slot:
- nextTab // will go to the next tab/step when called
- prevTab //will got to the prev tab/step when called
- activeTabIndex // current active tab index
- isLastStep // boolean to tell whether it's the last step or not
- fillButtonStyle // object with styles for wizard-buttons (contains background and color passed through wizard props)

### Step slot
This slot can be used to disable the click event on the step or to customize the UI of each step
One possible usage:
Expand All @@ -189,7 +202,7 @@ One possible usage:
</template>
```
#### Exposed props for the `step` slot
- tab (the tab object which contains the tab-content component corresponding to the step) This object contains several fields such as `active, checked, shape, color` and so on. You can check how these are used [here](https://github.com/cristijora/vue-form-wizard/blob/master/src/components/WizardStep.vue):
- tab (the tab object which contains the tab-content component corresponding to the step) This object contains several fields such as `active, checked, shape, color` and so on. You can check how these are used [here](https://github.com/cristijora/vue-form-wizard/blob/master/src/components/WizardStep.vue):
- index (The index of the step)
- transition (Transition prop passed from form-wizard)

Expand Down
74 changes: 39 additions & 35 deletions src/components/FormWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,38 @@

<div class="wizard-card-footer clearfix" v-if="!hideButtons">
<slot name="footer"
:next-tab="nextTab"
:prev-tab="prevTab"
:active-tab-index="activeTabIndex"
:is-last-step="isLastStep"
:fill-button-style="fillButtonStyle">
v-bind="slotProps">
<div class="wizard-footer-left">
<span @click="prevTab" v-if="displayPrevButton">
<slot name="prev" v-bind="slotProps">
<wizard-button :style="fillButtonStyle"
:disabled="loading">
{{backButtonText}}
</wizard-button>
</slot>
</span>
<slot name="custom-buttons-left" v-bind="slotProps"></slot>
</div>

<template>
<span @click="prevTab" v-if="displayPrevButton" class="wizard-footer-left">
<slot name="prev">
<wizard-button :style="fillButtonStyle"
:disabled="loading">
{{backButtonText}}
</wizard-button>
</slot>
</span>
</template>
<div class="wizard-footer-right">
<slot name="custom-buttons-right" v-bind="slotProps"></slot>
<span @click="nextTab" v-if="isLastStep">
<slot name="finish" v-bind="slotProps">
<wizard-button :style="fillButtonStyle">
{{finishButtonText}}
</wizard-button>
</slot>
</span>
<span @click="nextTab" v-else>
<slot name="next" v-bind="slotProps">
<wizard-button :style="fillButtonStyle"
:disabled="loading">
{{nextButtonText}}
</wizard-button>
</slot>
</span>
</div>

<template>
<span @click="finish" class="wizard-footer-right" v-if="isLastStep">
<slot name="nextTab">
<wizard-button :style="fillButtonStyle">
{{finishButtonText}}
</wizard-button>
</slot>
</span>
</template>

<template>
<span @click="nextTab" class="wizard-footer-right" v-if="!isLastStep">
<slot name="next">
<wizard-button :style="fillButtonStyle"
:disabled="loading">
{{nextButtonText}}
</wizard-button>
</slot>
</span>
</template>
</slot>
</div>
</div>
Expand Down Expand Up @@ -153,6 +148,15 @@
}
},
computed: {
slotProps () {
return {
nextTab: this.nextTab,
prevTab: this.prevTab,
activeTabIndex: this.activeTabIndex,
isLastStep: this.isLastStep,
fillButtonStyle: this.fillButtonStyle
}
},
tabCount () {
return this.tabs.length
},
Expand Down

0 comments on commit d9c9b1e

Please sign in to comment.