Last active
October 30, 2018 10:56
-
-
Save jkarsrud/c8c9f62aa2bc9f7807edf89f8b246bfe to your computer and use it in GitHub Desktop.
Guides source PR 200 component example
This file contains 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.Component.extend({ | |
classNames: ['animated','sliding-elem'], | |
didInsertElement() { | |
this._super(...arguments); | |
this.animationHandler = () => { | |
this.element.classList.remove('sliding-elem'); | |
}; | |
this.element.addEventListener('animationstart', this.animationHandler); | |
}, | |
willDestroyElement() { | |
this.element.removeEventListener('animationend', this.animationHandler); | |
} | |
}); |
This file contains 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'; | |
function myDatePickerLib(input) { | |
console.log('myDatePickerLib attached to input', input); | |
input.classList.add('datepicker'); | |
return { | |
destroy() { | |
input.classList.remove('datepicker'); | |
console.log('myDatePickerLib destroyed'); | |
} | |
}; | |
} | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this._super(...arguments); | |
this.datePicker = myDatePickerLib(this.element.querySelector('input.date')); | |
}, | |
willDestroyElement() { | |
this.datePicker.destroy(); | |
this._super(...arguments); | |
} | |
}); |
This file contains 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.Component.extend({ | |
init() { | |
this._super(...arguments); | |
this.items = Array(25).fill().map((v, index) => ({ id: index + 1, label: `Item ${index + 1}` })); | |
}, | |
didReceiveAttrs() { | |
this._super(...arguments); | |
this.set('items', this.items.map((item) => { | |
return Object.assign({}, item, { | |
isSelected: item.id === this.selectedItem.id, | |
}); | |
})); | |
}, | |
didRender() { | |
this._super(...arguments); | |
const scrollTarget = Math.abs(this.element.getBoundingClientRect().top - this.element.querySelector('.selected-item').getBoundingClientRect().top); | |
this.element.querySelector('.item-list').scrollTop = scrollTarget; | |
} | |
}); |
This file contains 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', | |
showExample: true, | |
selectedItem: { id: 1 }, | |
actions: { | |
toggleExample() { | |
this.toggleProperty('showExample'); | |
}, | |
changeSelectedItem() { | |
console.log('changeSelectedItem from', this.selectedItem); | |
this.set('selectedItem', { id: 5 }); | |
console.log(this.selectedItem); | |
} | |
} | |
}); |
This file contains 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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.ember-view { | |
margin-bottom: 20px; | |
} | |
button.enabled { | |
background: green; | |
color: white; | |
} | |
input.datepicker { | |
border-color: green; | |
} | |
.animated { | |
position: relative; | |
width: 100px; | |
height: 100px; | |
background: green; | |
} | |
.sliding-elem { | |
animation: slide 2s infinite; | |
} | |
@keyframes slide { | |
from { | |
left: 0; | |
} | |
50% { | |
left: 100px; | |
} | |
to { | |
left: 0; | |
} | |
} | |
.selected-item { | |
background: green; | |
color: white; | |
} | |
.item-list { | |
max-height: 100px; | |
overflow: auto; | |
} |
This file contains 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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment