forked from adopted-ember-addons/ember-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper-checkbox.js
More file actions
84 lines (73 loc) · 2.22 KB
/
Copy pathpaper-checkbox.js
File metadata and controls
84 lines (73 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* eslint-disable ember/no-classic-components, ember/no-get, ember/no-mixins, ember/require-tagless-components */
/**
* @module ember-paper
*/
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { not, and } from '@ember/object/computed';
import Component from '@ember/component';
import { assert } from '@ember/debug';
import FocusableMixin from 'ember-paper/mixins/focusable-mixin';
import ColorMixin from 'ember-paper/mixins/color-mixin';
import ProxiableMixin from 'ember-paper/mixins/proxiable-mixin';
import { invokeAction } from 'ember-paper/utils/invoke-action';
/**
* @class PaperCheckbox
* @extends Ember.Component
* @uses FocusableMixin
* @uses ColorMixin
* @uses ProxiableMixin
*/
export default Component.extend(FocusableMixin, ColorMixin, ProxiableMixin, {
tagName: 'md-checkbox',
classNames: ['md-checkbox', 'md-default-theme'],
classNameBindings: ['isChecked:md-checked', 'indeterminate:md-indeterminate'],
attributeBindings: [
'role:role',
'ariaLabel:aria-label',
'ariaChecked:aria-checked',
'labelId:aria-labelledby',
],
/* FocusableMixin Overrides */
focusOnlyOnKey: true,
constants: service(),
value: false,
role: 'checkbox',
notIndeterminate: not('indeterminate'),
isChecked: and('notIndeterminate', 'value'),
ariaChecked: computed('isChecked', 'indeterminate', function () {
if (this.indeterminate) {
return 'mixed';
}
return this.isChecked ? 'true' : 'false';
}),
labelId: computed('elementId', function () {
return `${this.elementId}-label`;
}),
init() {
this._super(...arguments);
assert(
'<PaperCheckbox /> requires an `onChange` action or null for no action.',
this.onChange !== undefined
);
},
click() {
if (!this.disabled) {
invokeAction(this, 'onChange', !this.value);
}
// Prevent bubbling, if specified. If undefined, the event will bubble.
return this.bubbles;
},
keyPress(ev) {
if (
ev.which === this.get('constants.KEYCODE.SPACE') ||
ev.which === this.get('constants.KEYCODE.ENTER')
) {
ev.preventDefault();
this.click();
}
},
processProxy() {
invokeAction(this, 'onChange', !this.value);
},
});