Last active
September 29, 2016 21:36
-
-
Save alexlafroscia/35b024e2e8e9f56a83b8cce6048ffca5 to your computer and use it in GitHub Desktop.
selection-wizard component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
selections: [], | |
actions: { | |
'log-transition'(name, value) { | |
this.get('selections').pushObject(value); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { Component, computed, get, set } = Ember; | |
export default Component.extend({ | |
/** | |
* Step should only be visible when the `currentStep` matches the assigned index | |
* for this step | |
* | |
* @property {boolean} isVisible | |
* @public | |
*/ | |
isVisible: computed('currentStep', 'name', function() { | |
return get(this, 'currentStep') === get(this, 'name'); | |
}), | |
didInsertElement() { | |
const name = get(this, 'name'); | |
this.attrs['register-step'](name); | |
}, | |
actions: { | |
'choose-option'() { | |
this.attrs['selection-action'](...arguments); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { A, Component, computed, isEmpty, get, set } = Ember; | |
export default Component.extend({ | |
/** | |
* @property {string} the step to start on | |
* @public | |
*/ | |
initialStep: null, | |
/** | |
* @property {string} currentStep the current active step | |
* @private | |
*/ | |
currentStep: computed.oneWay('initialStep'), | |
actions: { | |
/** | |
* Register a step with the wizard | |
* | |
* Called by a step component to get it's index number assignment | |
* | |
* @method registerStep | |
* @param {string} name the name of the step being registered | |
* @returns number | |
* @private | |
*/ | |
'register-step-component'(name) { | |
const currentStep = get(this, 'currentStep'); | |
if (isEmpty(currentStep)) { | |
set(this, 'currentStep', name); | |
} | |
}, | |
'transition-to'(name, option) { | |
if (isEmpty(name)) { | |
throw new Error('You must provide a step to transition to'); | |
} | |
set(this, 'currentStep', name); | |
if (this.attrs['on-transition']) { | |
this.attrs['on-transition'](...arguments); | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": true, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.8.0", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "2.8.0", | |
"ember-testing": "2.8.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment