Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Side by Side Diff: sky/framework/sky-radio/sky-radio.sky

Issue 874303003: Move sky-box,-button,-checkbox,-radio out of their directories (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/sky-radio.sky ('k') | sky/tests/resources/test-element.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" />
7
8 <sky-element
9 name="sky-radio"
10 attributes="selected:boolean, group:string"
11 on-click="handleClick">
12 <template>
13 <style>
14 :host {
15 display: inline-block;
16 -webkit-user-select: none;
17 width: 14px;
18 height: 14px;
19 border-radius: 7px;
20 border: 1px solid blue;
21 margin: 0 5px;
22 }
23 :host([highlight=true]) box {
24 background-color: orange;
25 }
26 dot {
27 -webkit-user-select: none;
28 width: 10px;
29 height: 10px;
30 border-radius: 5px;
31 background-color: black;
32 margin: 2px;
33 }
34 </style>
35 <template if="{{ selected }}">
36 <dot />
37 </template>
38 </template>
39 <script>
40 const kControllerMap = new WeakMap();
41
42 class RadioGroupController {
43 static forRadio(radio) {
44 var scope = radio.ownerScope;
45 var controller = kControllerMap.get(scope);
46 if (!controller)
47 kControllerMap.set(scope, new RadioGroupController());
48 return kControllerMap.get(scope);
49 }
50 constructor() {
51 this.radios = new Set();
52 }
53 addRadio(radio) {
54 this.radios.add(radio);
55 // If this new radio is default-selected, take selection from the group.
56 if (radio.selected)
57 this.takeSelectionFromGroup(radio);
58 }
59 removeRadio(radio) {
60 this.radios.remove(radio);
61 }
62 takeSelectionFromGroup(selectedRadio) {
63 // Emtpy/null/undefined group means an isolated radio.
64 if (!selectedRadio.group)
65 return;
66 this.radios.forEach(function(radio) {
67 if (selectedRadio === radio)
68 return;
69 if (radio.group != selectedRadio.group)
70 return;
71 radio.selected = false;
72 });
73 }
74 };
75
76 module.exports = class extends SkyButton {
77 created() {
78 super.created();
79
80 this.controller = null;
81 }
82 attached() {
83 super.attached();
84 this.controller = RadioGroupController.forRadio(this);
85 this.controller.addRadio(this);
86 }
87 detached() {
88 super.detached();
89 this.controller.removeRadio(this);
90 this.controller = null;
91 }
92 selectedChanged(oldValue, newValue) {
93 if (newValue && this.controller)
94 this.controller.takeSelectionFromGroup(this);
95 }
96 groupChanged(oldValue, newValue) {
97 if (this.selected && this.controller)
98 this.controller.takeSelectionFromGroup(this);
99 }
100 handleClick() {
101 this.selected = true;
102 }
103 }.register();
104 </script>
105 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/sky-radio.sky ('k') | sky/tests/resources/test-element.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698