Skip to content

Commit d76465b

Browse files
Michael Linjelbourn
Michael Lin
authored andcommitted
feat(radio): Radio component.
Closes #125
1 parent ad0c3eb commit d76465b

File tree

10 files changed

+823
-0
lines changed

10 files changed

+823
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
@import "default-theme";
2+
3+
$md-radio-width: 20px !default;
4+
5+
// Top-level host container.
6+
md-radio-button {
7+
display: inline-block;
8+
}
9+
10+
// Inner label container, wrapping entire element.
11+
// Enables focus by click.
12+
.md-radio-label {
13+
cursor: pointer;
14+
display: block;
15+
padding: 8px;
16+
white-space: nowrap;
17+
}
18+
19+
// Container for radio circles and ripple.
20+
.md-radio-container {
21+
box-sizing: border-box;
22+
display: inline-block;
23+
height: $md-radio-width;
24+
position: relative;
25+
top: 2px;
26+
width: $md-radio-width;
27+
}
28+
29+
// TODO(mtlin): Replace when ink ripple component is implemented.
30+
// A placeholder ink ripple, shown when keyboard focused.
31+
.md-ink-ripple {
32+
background-color: md-color($md-accent);
33+
border-radius: 50%;
34+
height: 48px;
35+
left: 10px;
36+
opacity: 0;
37+
pointer-events: none;
38+
position: absolute;
39+
top: 10px;
40+
transform: translate(-50%,-50%);
41+
transition: opacity ease 0.28s, background-color ease 0.28s;
42+
width: 48px;
43+
overflow: hidden;
44+
45+
// Fade in when radio focused.
46+
.md-radio-focused & {
47+
opacity: 0.1;
48+
}
49+
50+
// TODO(mtlin): This corresponds to disabled focus state, but it's unclear how to enter into
51+
// this state.
52+
.md-radio-disabled & {
53+
background: #000;
54+
}
55+
}
56+
57+
// The outer circle for the radio, always present.
58+
.md-radio-outer-circle {
59+
border-color: md-color($md-foreground, secondary-text);
60+
border: solid 2px;
61+
border-radius: 50%;
62+
box-sizing: border-box;
63+
height: $md-radio-width;
64+
left: 0;
65+
position: absolute;
66+
top: 0;
67+
transition: border-color ease 0.28s;
68+
width: $md-radio-width;
69+
70+
.md-radio-checked & {
71+
border-color: md-color($md-accent);
72+
}
73+
74+
.md-radio-disabled & {
75+
border-color: md-color($md-foreground, disabled);
76+
}
77+
}
78+
79+
// The inner circle for the radio, shown when checked.
80+
.md-radio-inner-circle {
81+
background-color: md-color($md-accent);
82+
border-radius: 50%;
83+
box-sizing: border-box;
84+
height: $md-radio-width;
85+
left: 0;
86+
position: absolute;
87+
top: 0;
88+
transition: transform ease 0.28s, background-color ease 0.28s;
89+
transform: scale(0);
90+
width: $md-radio-width;
91+
92+
.md-radio-checked & {
93+
transform: scale(0.5);
94+
}
95+
96+
.md-radio-disabled & {
97+
background-color: md-color($md-foreground, disabled);
98+
}
99+
}
100+
101+
// Text label next to radio.
102+
.md-radio-label-content {
103+
display: inline-block;
104+
float: right;
105+
line-height: 24px;
106+
// Equal padding on both sides, for RTL.
107+
padding-left: 8px;
108+
padding-right: 8px;
109+
position: relative;
110+
vertical-align: top;
111+
}
112+
113+
// Underlying native input element.
114+
// Visually hidden but still able to respond to focus.
115+
.md-radio-input {
116+
position: absolute;
117+
width: 0;
118+
height: 0;
119+
margin: 0;
120+
padding: 0;
121+
opacity: 0;
122+
appearance: none;
123+
border: none;
124+
}
125+
126+
// Basic disabled state.
127+
.md-radio-disabled, .md-radio-disabled .md-radio-label {
128+
cursor: default;
129+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- TODO(jelbourn): render the radio on either side of the content -->
2+
<!-- TODO(mtlin): Evaluate trade-offs of using native radio vs. cost of additional bindings. -->
3+
<label [attr.for]="inputId" class="md-radio-label">
4+
<!-- The actual `radio` part of the control. -->
5+
<div class="md-radio-container">
6+
<div class="md-radio-outer-circle"></div>
7+
<div class="md-radio-inner-circle"></div>
8+
<div class="md-ink-ripple"></div>
9+
</div>
10+
11+
<input #input class="md-radio-input" type="radio"
12+
[id]="inputId"
13+
[checked]="checked"
14+
[disabled]="disabled"
15+
[name]="name"
16+
(change)="onInputChange()"
17+
(focus)="onInputFocus()"
18+
(blur)="onInputBlur()" />
19+
20+
<!-- The label content for radio control. -->
21+
<div class="md-radio-label-content">
22+
<ng-content></ng-content>
23+
</div>
24+
</label>

0 commit comments

Comments
 (0)