Skip to content

Commit fcf6422

Browse files
authored
Merge pull request #1225 from miguelcobain/paper-item-class
update paper-item to use native class syntax
2 parents a9b86c7 + ad82df8 commit fcf6422

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

addon/components/paper-item.js

+44-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* eslint-disable ember/no-classic-components, ember/require-tagless-components, ember/no-component-lifecycle-hooks */
2-
/**
3-
* @module ember-paper
4-
*/
5-
import { filter, bool, or } from '@ember/object/computed';
1+
/* eslint-disable ember/no-computed-properties-in-native-classes, ember/no-classic-components, ember/no-component-lifecycle-hooks */
2+
import { attributeBindings, classNameBindings, tagName, layout as templateLayout } from '@ember-decorators/component';
3+
import { computed } from '@ember/object';
4+
import { or, bool, filter } from '@ember/object/computed';
65

76
import Component from '@ember/component';
8-
import { computed } from '@ember/object';
97
import layout from '../templates/components/paper-item';
108
import { ParentMixin } from 'ember-composability-tools';
119
import { invokeAction } from 'ember-paper/utils/invoke-action';
@@ -14,78 +12,87 @@ import { invokeAction } from 'ember-paper/utils/invoke-action';
1412
* @extends Ember.Component
1513
* @uses ParentMixin
1614
*/
17-
export default Component.extend(ParentMixin, {
18-
layout,
19-
tagName: 'md-list-item',
20-
21-
_mouseEnterHandler: undefined,
22-
_mouseLeaveHandler: undefined,
15+
@templateLayout(layout)
16+
@tagName('md-list-item')
17+
@classNameBindings(
18+
'hasProxiedComponent:md-proxy-focus',
19+
'shouldBeClickable:md-clickable',
20+
'focused:md-focused',
21+
'hasPrimaryAction:_md-button-wrap'
22+
)
23+
@attributeBindings('role', 'tabindex', 'title')
24+
export default class PaperItem extends Component.extend(ParentMixin) {
25+
_mouseEnterHandler = undefined;
26+
_mouseLeaveHandler = undefined;
2327

2428
// Ripple Overrides
2529
// disable ripple when we have a primary action or when we don't have a proxied component
26-
noink: computed('hasPrimaryAction', 'hasProxiedComponent', function() {
30+
@computed('hasPrimaryAction', 'hasProxiedComponent')
31+
get noink() {
2732
return this.hasPrimaryAction || !this.hasProxiedComponent;
28-
}),
33+
}
2934

30-
classNameBindings: [
31-
'hasProxiedComponent:md-proxy-focus', 'shouldBeClickable:md-clickable',
32-
'focused:md-focused', 'hasPrimaryAction:_md-button-wrap'
33-
],
34-
attributeBindings: ['role', 'tabindex', 'title'],
35-
role: 'listitem',
36-
tabindex: '-1',
35+
role = 'listitem';
36+
tabindex = '-1';
3737

38-
proxiedComponents: filter('childComponents', function(c) {
38+
@filter('childComponents', function(c) {
3939
return !c.get('skipProxy');
40-
}),
40+
})
41+
proxiedComponents;
42+
43+
@bool('proxiedComponents.length')
44+
hasProxiedComponent;
4145

42-
hasProxiedComponent: bool('proxiedComponents.length'),
43-
shouldBeClickable: or('hasProxiedComponent', 'onClick'),
46+
@or('hasProxiedComponent', 'onClick')
47+
shouldBeClickable;
4448

45-
hasPrimaryAction: or('onClick', 'href'),
49+
@or('onClick', 'href')
50+
hasPrimaryAction;
4651

47-
noProxy: computed('hasPrimaryAction', 'hasProxiedComponent', function() {
52+
@computed('hasPrimaryAction', 'hasProxiedComponent')
53+
get noProxy() {
4854
return !this.hasPrimaryAction && !this.hasProxiedComponent;
49-
}),
55+
}
5056

51-
secondaryItem: computed('proxiedComponents.[]', function() {
57+
@computed('proxiedComponents.[]')
58+
get secondaryItem() {
5259
let proxiedComponents = this.proxiedComponents;
5360
return proxiedComponents.objectAt(0);
54-
}),
61+
}
5562

5663
didInsertElement() {
57-
this._super(...arguments);
64+
super.didInsertElement(...arguments);
5865

5966
this._mouseEnterHandler = this.handleMouseEnter.bind(this);
6067
this._mouseLeaveHandler = this.handleMouseLeave.bind(this);
6168

6269
this.element.addEventListener('mouseenter', this._mouseEnterHandler);
6370
this.element.addEventListener('mouseleave', this._mouseLeaveHandler);
64-
},
71+
}
6572

6673
willDestroyElement() {
67-
this._super(...arguments);
74+
super.willDestroyElement(...arguments);
6875

6976
this.element.removeEventListener('mouseenter', this._mouseEnterHandler);
7077
this.element.removeEventListener('mouseleave', this._mouseLeaveHandler);
7178

7279
this._mouseEnterHandler = undefined;
7380
this._mouseLeaveHandler = undefined;
74-
},
81+
}
7582

7683
click() {
7784
this.proxiedComponents.forEach((component) => {
7885
if (component.processProxy && !component.get('disabled') && (component.get('bubbles') | !this.hasPrimaryAction)) {
7986
component.processProxy();
8087
}
8188
});
82-
},
89+
}
8390

8491
handleMouseEnter(e) {
8592
invokeAction(this, 'onMouseEnter', e);
86-
},
93+
}
8794

8895
handleMouseLeave(e) {
8996
invokeAction(this, 'onMouseLeave', e);
9097
}
91-
});
98+
}

0 commit comments

Comments
 (0)