OLD | NEW |
1 part of widgets; | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import '../fn.dart'; |
| 6 import 'button_base.dart'; |
| 7 |
| 8 typedef void ValueChanged(value); |
2 | 9 |
3 class Radio extends ButtonBase { | 10 class Radio extends ButtonBase { |
4 | |
5 Object value; | 11 Object value; |
6 Object groupValue; | 12 Object groupValue; |
7 ValueChanged onChanged; | 13 ValueChanged onChanged; |
8 | 14 |
9 static Style _style = new Style(''' | 15 static final Style _style = new Style(''' |
10 transform: translateX(0); | 16 transform: translateX(0); |
11 display: inline-block; | 17 display: inline-block; |
12 -webkit-user-select: none; | 18 -webkit-user-select: none; |
13 width: 14px; | 19 width: 14px; |
14 height: 14px; | 20 height: 14px; |
15 border-radius: 7px; | 21 border-radius: 7px; |
16 border: 1px solid blue; | 22 border: 1px solid blue; |
17 margin: 0 5px;''' | 23 margin: 0 5px;''' |
18 ); | 24 ); |
19 | 25 |
20 static Style _highlightStyle = new Style(''' | 26 static final Style _highlightStyle = new Style(''' |
21 transform: translateX(0); | 27 transform: translateX(0); |
22 display: inline-block; | 28 display: inline-block; |
23 -webkit-user-select: none; | 29 -webkit-user-select: none; |
24 width: 14px; | 30 width: 14px; |
25 height: 14px; | 31 height: 14px; |
26 border-radius: 7px; | 32 border-radius: 7px; |
27 border: 1px solid blue; | 33 border: 1px solid blue; |
28 margin: 0 5px; | 34 margin: 0 5px; |
29 background-color: orange;''' | 35 background-color: orange;''' |
30 ); | 36 ); |
31 | 37 |
32 static Style _dotStyle = new Style(''' | 38 static final Style _dotStyle = new Style(''' |
33 -webkit-user-select: none; | 39 -webkit-user-select: none; |
34 width: 10px; | 40 width: 10px; |
35 height: 10px; | 41 height: 10px; |
36 border-radius: 5px; | 42 border-radius: 5px; |
37 background-color: black; | 43 background-color: black; |
38 margin: 2px;''' | 44 margin: 2px;''' |
39 ); | 45 ); |
40 | 46 |
41 Radio({ | 47 Radio({ |
42 Object key, | 48 Object key, |
43 this.onChanged, | 49 this.onChanged, |
44 this.value, | 50 this.value, |
45 this.groupValue | 51 this.groupValue |
46 }) : super(key: key); | 52 }) : super(key: key) { |
| 53 events.listen('click', _handleClick); |
| 54 } |
47 | 55 |
48 Node build() { | 56 Node build() { |
49 return new Container( | 57 return new Container( |
50 style: _highlight ? _highlightStyle : _style, | 58 style: highlight ? _highlightStyle : _style, |
51 children: value == groupValue ? | 59 children: value == groupValue ? |
52 [super.build(), new Container( style : _dotStyle )] : [super.build()] | 60 [super.build(), new Container( style : _dotStyle )] : [super.build()] |
53 )..events.listen('click', _handleClick); | 61 ) |
54 } | 62 } |
55 | 63 |
56 void _handleClick(_) { | 64 void _handleClick(_) { |
57 onChanged(value); | 65 onChanged(value); |
58 } | 66 } |
59 } | 67 } |
OLD | NEW |