-
Notifications
You must be signed in to change notification settings - Fork 50
/
radio-button.js
42 lines (35 loc) · 1.05 KB
/
radio-button.js
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
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { isEqual } from '@ember/utils';
export default class RadioButtonComponent extends Component {
// value - passed in, required, the value for this radio button
// groupValue - passed in, required, the currently selected value
// optionally passed in:
// disabled - boolean
// required - boolean
// name - string
// radioClass - string
// radioId - string
// ariaLabelledby - string
// ariaDescribedby - string
get joinedClassNames() {
const classNames = this.args.classNames;
if (classNames && classNames.length && classNames.join) {
return classNames.join(' ');
}
return classNames;
}
get checkedClass() {
return this.args.checkedClass || 'checked';
}
get checked() {
return isEqual(this.args.groupValue, this.args.value);
}
@action changed(newValue) {
let changedAction = this.args.changed;
// providing a closure action is optional
if (changedAction) {
changedAction(newValue);
}
}
}