Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(radio): Radio component. #125

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions src/components/radio/radio-button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
@import "default-theme";

$md-radio-width: 20px !default;

// Top-level host container.
md-radio-button {
display: inline-block;
}

// Inner label container, wrapping entire element.
// Enables focus by click.
.md-radio-label {
cursor: pointer;
display: block;
padding: 8px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How possible is it to move things like this padding into variables that could be overridden by users in the name of density (which I know the designers have been thinking about but not yet really addressing in the spec)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible, though since we don't have any systematic guidance of that kind across components, my imagination is that users should just override the styles using their own cascaded styles.

white-space: nowrap;
}

// Container for radio circles and ripple.
.md-radio-container {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a brief description of what each css class is / is responsible for?

box-sizing: border-box;
display: inline-block;
height: $md-radio-width;
position: relative;
top: 2px;
width: $md-radio-width;
}

// TODO(mtlin): Replace when ink ripple component is implemented.
// A placeholder ink ripple, shown when keyboard focused.
.md-ink-ripple {
background-color: md-color($md-accent);
border-radius: 50%;
height: 48px;
left: 10px;
opacity: 0;
pointer-events: none;
position: absolute;
top: 10px;
transform: translate(-50%,-50%);
transition: opacity ease 0.28s, background-color ease 0.28s;
width: 48px;
overflow: hidden;

// Fade in when radio focused.
.md-radio-focused & {
opacity: 0.1;
}

// TODO(mtlin): This corresponds to disabled focus state, but it's unclear how to enter into
// this state.
.md-radio-disabled & {
background: #000;
}
}

// The outer circle for the radio, always present.
.md-radio-outer-circle {
border-color: md-color($md-foreground, secondary-text);
border: solid 2px;
border-radius: 50%;
box-sizing: border-box;
height: $md-radio-width;
left: 0;
position: absolute;
top: 0;
transition: border-color ease 0.28s;
width: $md-radio-width;

.md-radio-checked & {
border-color: md-color($md-accent);
}

.md-radio-disabled & {
border-color: md-color($md-foreground, disabled);
}
}

// The inner circle for the radio, shown when checked.
.md-radio-inner-circle {
background-color: md-color($md-accent);
border-radius: 50%;
box-sizing: border-box;
height: $md-radio-width;
left: 0;
position: absolute;
top: 0;
transition: transform ease 0.28s, background-color ease 0.28s;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be one of the common easing curves?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, but I am holding off on any design/motion tweaks because I need to get those reviewed by the team first.

transform: scale(0);
width: $md-radio-width;

.md-radio-checked & {
transform: scale(0.5);
}

.md-radio-disabled & {
background-color: md-color($md-foreground, disabled);
}
}

// Text label next to radio.
.md-radio-label-content {
display: inline-block;
float: right;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should change based on the align property, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to hold off on RTL until a later PR, since there might need to be more thought put into it.

line-height: 24px;
// Equal padding on both sides, for RTL.
padding-left: 8px;
padding-right: 8px;
position: relative;
vertical-align: top;
}

// Underlying native input element.
// Visually hidden but still able to respond to focus.
.md-radio-input {
position: absolute;
width: 0;
height: 0;
margin: 0;
padding: 0;
opacity: 0;
appearance: none;
border: none;
}

// Basic disabled state.
.md-radio-disabled, .md-radio-disabled .md-radio-label {
cursor: default;
}
24 changes: 24 additions & 0 deletions src/components/radio/radio_button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- TODO(jelbourn): render the radio on either side of the content -->
<!-- TODO(mtlin): Evaluate trade-offs of using native radio vs. cost of additional bindings. -->
<label [attr.for]="inputId" class="md-radio-label">
<!-- The actual `radio` part of the control. -->
<div class="md-radio-container">
<div class="md-radio-outer-circle"></div>
<div class="md-radio-inner-circle"></div>
<div class="md-ink-ripple"></div>
</div>

<input #input class="md-radio-input" type="radio"
[id]="inputId"
[checked]="checked"
[disabled]="disabled"
[name]="name"
(change)="onInputChange()"
(focus)="onInputFocus()"
(blur)="onInputBlur()" />

<!-- The label content for radio control. -->
<div class="md-radio-label-content">
<ng-content></ng-content>
</div>
</label>
Loading