-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradio.tsx
More file actions
60 lines (44 loc) · 1.28 KB
/
radio.tsx
File metadata and controls
60 lines (44 loc) · 1.28 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
import {
o,
click,
Attrs,
O,
Observable,
RO,
Component
} from 'elt'
import {Flex} from './flex'
import {Checkbox} from './checkbox'
import {Icon} from './icon'
import {inkable} from './ink'
var CHECKED = 'dot-circle'
var UNCHECKED = 'circle-o'
export interface RadioAttributes<T> extends Attrs {
model: O<T>
value: RO<T>
disabled?: RO<boolean>
}
export class Radio<T> extends Component<RadioAttributes<T>> {
disabled: RO<boolean> = o(this.attrs.disabled||false)
value: RO<T> = this.attrs.value
model: Observable<T> = o(this.attrs.model)
setValue() {
this.model.set(o.get(this.value))
}
render(children: DocumentFragment): Element {
let classes = {
[Checkbox.on]: this.model.equals(this.value),
[Checkbox.off]: this.model.differs(this.value),
[Checkbox.disabled]: this.disabled
};
return <label class={Checkbox.label} $$={[inkable(), click(e => this.setValue())]}>
<div class={[Flex.row, Flex.align_center]}>
<Icon
class={[Checkbox.icon, classes]}
name={o.merge({model: this.model, value: this.value}).tf(({model: m, value: v}) => m === v ? CHECKED : UNCHECKED)}
/>
<span class={[Checkbox.content, classes]}>{children}</span>
</div>
</label>;
}
}