StepView.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const Component = use('util.Component');
  2. export default def(class StepView extends Component {
  3. static ID = 'ui.component.StepView';
  4. static PROPERTIES = {
  5. children: {},
  6. done: { value: false },
  7. position: { value: 0 },
  8. }
  9. static CSS = `
  10. #wrapper { display: none }
  11. * { -webkit-font-smoothing: antialiased;}
  12. `;
  13. create_template ({ template }) {
  14. $(template).html(`
  15. <div id="wrapper">
  16. <slot name="inside"></slot>
  17. </div>
  18. `);
  19. }
  20. on_focus () {
  21. this.children[this.get('position')].focus();
  22. }
  23. on_ready ({ listen }) {
  24. for ( const child of this.get('children') ) {
  25. child.setAttribute('slot', 'inside');
  26. child.attach(this);
  27. $(child).hide();
  28. }
  29. // show the first child
  30. $(this.children[0]).show();
  31. // listen for changes to the current step
  32. listen('position', position => {
  33. // hide all children
  34. for ( const child of this.children ) {
  35. $(child).hide();
  36. }
  37. // show the child at the current position
  38. $(this.children[position]).show();
  39. this.children[position].focus();
  40. });
  41. // now that we're ready, show the wrapper
  42. $(this.dom_).find('#wrapper').show();
  43. }
  44. back () {
  45. if ( this.get('position') === 0 ) return;
  46. this.set('position', this.get('position') - 1);
  47. }
  48. next () {
  49. if ( this.get('position') === this.children.length - 1 ) {
  50. this.set('done', true);
  51. return;
  52. }
  53. this.set('position', this.get('position') + 1);
  54. }
  55. });