Skip to content

Instantly share code, notes, and snippets.

@adamesque
Last active January 26, 2016 22:05
Show Gist options
  • Select an option

  • Save adamesque/9021a8e1ff7ab51b7efd to your computer and use it in GitHub Desktop.

Select an option

Save adamesque/9021a8e1ff7ab51b7efd to your computer and use it in GitHub Desktop.

Revisions

  1. adamesque revised this gist Jan 26, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions toggle-button.template.hbs
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    <label>{{currentLabel}}</label><br>
    <button>Button</button>
    <button>Button</button>
    <label>{{currentLabel}}</label>
  2. adamesque created this gist Jan 26, 2016.
    11 changes: 11 additions & 0 deletions application.controller.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import Ember from 'ember';

    export default Ember.Controller.extend({
    appName:'Ember Twiddle',
    isActive: false,
    actions: {
    toggle() {
    this.toggleProperty('isActive');
    }
    }
    });
    6 changes: 6 additions & 0 deletions application.template.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <h1>Welcome to {{appName}}</h1>
    <br>
    <br>
    {{toggle-button isActive=isActive action='toggle'}}
    <br>
    <br>
    18 changes: 18 additions & 0 deletions styles.app.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    body {
    margin: 12px 16px;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 12pt;
    }

    button {
    background: lightgrey;
    border: none;
    border-radius: 4px;
    font-size: 20px;
    padding: 0.5em 1em;
    transition: background 200ms ease-in-out;
    }

    .is-active button {
    background: hotpink;
    }
    44 changes: 44 additions & 0 deletions toggle-button.component.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    import Ember from 'ember';

    const {
    computed,
    computed: {
    reads,
    },
    observer,
    run: {
    cancel,
    later,
    }
    } = Ember;

    export default Ember.Component.extend({
    classNameBindings: ['isActive'],
    isActive: false,
    defaultLabel: 'Label',
    currentLabel: reads('defaultLabel'),
    updateLabel: observer('isActive', function () {
    let isActive = this.get('isActive');
    if (isActive) {
    this.set('currentLabel', 'ON');
    } else {
    this.set('currentLabel', 'OFF');
    }

    this._timer = later(this, 'resetLabel', 1000);
    }),

    resetLabel() {
    this.set('currentLabel', this.get('defaultLabel'));
    },

    willDestroy() {
    if (this._timer) {
    cancel(this._timer);
    }
    },

    click() {
    this.sendAction();
    }
    });
    2 changes: 2 additions & 0 deletions toggle-button.template.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    <label>{{currentLabel}}</label><br>
    <button>Button</button>
    15 changes: 15 additions & 0 deletions twiddle.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "version": "0.5.0",
    "EmberENV": {
    "FEATURES": {}
    },
    "options": {
    "enable-testing": false
    },
    "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
    "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
    "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
    }
    }