Skip to content

Commit

Permalink
Added the a validation function that can be override for each steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
caribouflex committed Jan 9, 2018
1 parent 375595f commit e448436
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 23 deletions.
40 changes: 30 additions & 10 deletions caribou-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@
Custom property | Description | Default
----------------|-------------|----------
`--step-connector-line-color` | Color of the line that connect the steps | `#BDBDBD`
`--step-saved-label-color` | Color of the label once it's saved | `#424242`
`--step-active-label-color`| Color of the label when the step is active | `#424242`
`--step-label-color`| Initial color of the label | `#E0E0E0`
`--step-badge-height`| The height of the badge (without border) | `18px`
`--step-badge-width`| The width of the badge (without border) | `18px`
`--step-save-badge-color`| Color of the badge once the step is saved | `--primary-color`
`--step-badge-color`| Initial color of the badge | `#9E9E9E`
`--step-badge-content-color`| Color of the number and the icon inside the badge | `#FFFFFF`
`--step-connector-line-color` | Color of the line that connect the steps | `#BDBDBD`
`--step-saved-label-color` | Color of the label once it's saved | `#424242`
`--step-active-label-color`| Color of the label when the step is active | `#424242`
`--step-label-color`| Initial color of the label | `#E0E0E0`
`--step-badge-height`| The height of the badge (without border) | `18px`
`--step-badge-width`| The width of the badge (without border) | `18px`
`--step-save-badge-color`| Color of the badge once the step is saved | `--primary-color`
`--step-badge-color`| Initial color of the badge | `#9E9E9E`
`--step-badge-content-color`| Color of the number and the icon inside the badge | `#FFFFFF`
-->
<dom-module id="caribou-step">
<template>
Expand Down Expand Up @@ -143,6 +145,10 @@
background-color: var(--step-badge-color, #9E9E9E);
color: var(--step-badge-content-color, #FFFFFF);
}

caribou-step-action-buttons paper-button {
@apply --button-style;
}
</style>

<paper-button on-tap="_toggle">
Expand Down Expand Up @@ -187,6 +193,13 @@
* @param {Object} detail empty
*/

/**
* Fired when the step is invalid to the validation the user defined.
*
* @event step-invalid
* @param {Object} detail empty
*/

static get is() {
return 'caribou-step';
}
Expand Down Expand Up @@ -317,7 +330,14 @@
this.parentElement.setNextStep(this);
}
}


fireInvalidStep() {
this.dispatchEvent(new CustomEvent('step-invalid', {
bubbles: true,
composed: true
}));
}

}

window.customElements.define(CaribouStepElement.is, CaribouStepElement);
Expand Down
4 changes: 4 additions & 0 deletions caribou-stepper-step-property-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
this.parentElement._registerStep(this);
}

validate(){
return true;
}

/**
* This function is used to know if the property 'openFirstStepOnStartup' is set to true.
* @private
Expand Down
14 changes: 9 additions & 5 deletions caribou-stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@
* Then it will open the next step if there is one.
*/
openNextStep() {
this.activeStep.saveStep();
this.activeStep.toggleStep();
this.removeActiveStep();
if (this.nextStep !== null)
this.nextStep.toggleStep();
if (this.activeStep.validate()) {
this.activeStep.saveStep();
this.activeStep.toggleStep();
this.removeActiveStep();
if (this.nextStep !== null)
this.nextStep.toggleStep();
} else {
this.activeStep.fireInvalidStep();
}
}

/**
Expand Down
19 changes: 11 additions & 8 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

<custom-style>
<style is="custom-style" include="demo-pages-shared-styles">

#stepper1step1 {
--button-style: {
text-transform: capitalize;
background-color: lightgrey;
}
}
</style>
</custom-style>
</head>
Expand All @@ -27,7 +32,8 @@ <h3>Basic caribou-stepper demo</h3>
<demo-snippet>
<template>
<caribou-stepper id="stepper" open-first-step-on-startup>
<caribou-step id="stepper1step1" editable label="Step 1" back-button back-label="Back to the previous">
<caribou-step id="stepper1step1" editable label="Step 1" back-button back-label="Back to the previous">
<input type="checkbox" id="checkboxValid">Check to continue.
<div style="width:100%;height:200px;background-color:lightgreen">Content 1</div>
</caribou-step>
<caribou-step id="stepper1step2" label="Step 2" skip-button optional back-button back-label="<--">
Expand All @@ -42,16 +48,13 @@ <h3>Basic caribou-stepper demo</h3>
function reset() {
document.querySelector("#stepper").reset();
}
document.querySelector("#stepper1step1").validate = function () {
return document.querySelector("#checkboxValid").checked;
}
</script>
</template>
</demo-snippet>
</div>
<button onclick="reset">reset</button>
<script>
function reset() {
document.querySelector("#stepper").reset();
}
</script>
</body>

</html>

1 comment on commit e448436

@caribouflex
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the style for the buttons can be set on the steps.

Please sign in to comment.