Skip to content

Commit

Permalink
fix back action
Browse files Browse the repository at this point in the history
- add back action (fix #9)
- fire event stepper-completed
- reset "selected" old value if the new one isn't valid
  • Loading branch information
Zecat committed May 10, 2016
1 parent bbe9ae7 commit 3bbfd6a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paper-stepper",
"version": "2.0-beta",
"version": "2.0-beta.1",
"authors": [
"Zecat <jullienfelix@gmail.com>"
],
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<style is="custom-style" include="demo-pages-shared-styles">
.vertical-stepper-wrapper {
max-width: 600px;
max-width: 700px;
margin: auto;
}
.horizontal-stepper-wrapper {
Expand Down
5 changes: 5 additions & 0 deletions paper-horizontal-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<link rel="import" href="paper-step-behavior.html">
<link rel="import" href="paper-step-shared-styles.html">

<!--
@element paper-horizontal-step
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="paper-horizontal-step">
<template>
<style include="paper-step-shared-styles">
Expand Down
6 changes: 3 additions & 3 deletions paper-horizontal-stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<content></content>
</neon-animated-pages>
<div id="buttonsWrapper">
<paper-button disabled on-tap="back">[[backText]]</paper-button>
<paper-button disabled=[[!_hasBackStep]] on-tap="back">[[backText]]</paper-button>
<span class="layout-flex"></span>
<paper-button disabled="[[completed]]" on-tap="progress">[[skipText]]</paper-button>
<paper-button disabled="[[completed]]" id="continueButton" on-tap="continue">[[continueText]]</paper-button>
Expand All @@ -103,7 +103,7 @@
reflectToAttribute: true
},
selected: {
observer: '_selectedChange'
observer: '_chooseAnimationDirection'
}
},

Expand All @@ -124,7 +124,7 @@
}.bind(this));
},

_selectedChange: function(newValue, oldValue) {
_chooseAnimationDirection: function(newValue, oldValue) {
if (newValue > oldValue) {
this.$.slideshow.entryAnimation = 'slide-from-right-animation';
this.$.slideshow.exitAnimation = 'slide-left-animation';
Expand Down
4 changes: 3 additions & 1 deletion paper-step-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<script>

window.Zecat = window.Zecat || {};

/*
@polymerBehavior Zecat.PaperStepBehavior
*/
Zecat.PaperStepBehavior = {
properties: {
completed: {
Expand Down
2 changes: 0 additions & 2 deletions paper-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<link rel="import" href="../polymer/polymer.html">

<!--
@group Seed Elements
@element paper-step
@demo demo/index.html
@hero hero.svg
Expand Down
66 changes: 59 additions & 7 deletions paper-stepper-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
<script>

window.Zecat = window.Zecat || {};

/*
@polymerBehavior Zecat.PaperStepperBehavior
*/
Zecat.PaperStepperBehavior = {

listeners: {
'continue-step': '_continueStep',
'skip-step': 'progress',
'back-step': 'back',
'progress': '_updatePreviousCompleted'
},

properties: {
/**
* Fired when all steps are completed.
*
* @event stepper-completed
*/
backText: {
type: String,
value: 'BACK'
Expand All @@ -27,7 +35,8 @@
},
selected: {
type: Number,
value: 0
value: 0,
observer: '_selectedChange'
},
linear: {
type: Boolean,
Expand All @@ -45,6 +54,14 @@
value: false,
readOnly: true,
observer: '_completedChange'
},
_backStepIndex: {
type: Number,
computed: '_compute_backStepIndex(selected)'
},
_hasBackStep: {
type: Boolean,
computed: '_compute_hasBackStep(_backStepIndex)'
}
},

Expand Down Expand Up @@ -84,7 +101,7 @@
var selectedIndex = selector.selected;
var items = selector.items;
var length = items.length;
if (selectedIndex < 0 || selectedIndex > length - 1) {
if (selectedIndex == null || selectedIndex > length - 1) {
selectedIndex = 0;
}
for (var i=(selectedIndex+1)%length; i!=selectedIndex; i=(i+1)%length) {
Expand All @@ -95,14 +112,49 @@
}
return false;
},

/**
* Select a step from index if it is selectable. Return true if the step has been selected.
*/
selectStep: function(index) {
this.selected = index;
return this.selected == index;
},
/**
* Select the previous selectable step if it exist. Return true if the step has been selected.
*/
back: function() {
if (this._hasBackStep) {
this.selected = this._backStepIndex;
return true;
} else {
return false;
}
},
_completedChange: function(completed) {
if (completed) {
//maybe use null instead
this.$.stepSelector.selected = -1;
this.$.stepSelector.selected = null;
this.fire('completed');
}
},
_compute_backStepIndex: function(selected) {
for (i=selected - 1; i >= 0; i--) {
console.log(i);
if (this.$.stepSelector.items[i] && this.$.stepSelector.items[i].selectable) {
return i;
}
}
return null;
},
_compute_hasBackStep: function(_backStepIndex) {
return _backStepIndex != null;
},
/* Reset the old value if the step isn't selectable*/
_selectedChange: function(newValue, oldValue) {
if (newValue != null && this.$.stepSelector.items.length
&& !( (step = this.$.stepSelector.items[newValue]) && step.selectable) ) {
this.selected = oldValue;
}
}

};


Expand Down
1 change: 0 additions & 1 deletion paper-stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<link rel="import" href="paper-horizontal-stepper.html">

<!--
@group Seed Elements
@element paper-stepper
@demo demo/index.html
@hero hero.svg
Expand Down
1 change: 0 additions & 1 deletion paper-vertical-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<link rel="import" href="paper-step-shared-styles.html">

<!--
@group Seed Elements
@element paper-vertical-step
@demo demo/index.html
@hero hero.svg
Expand Down
1 change: 0 additions & 1 deletion paper-vertical-stepper.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<link rel="import" href="paper-vertical-step.html">

<!--
@group Seed Elements
@element paper-vertical-stepper
@demo demo/index.html
@hero hero.svg
Expand Down

0 comments on commit 3bbfd6a

Please sign in to comment.