Skip to content

Commit

Permalink
feat(textfield): Parameterize border radius for text field
Browse files Browse the repository at this point in the history
  • Loading branch information
amsheehan committed Oct 20, 2017
1 parent f91f269 commit be494d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
33 changes: 25 additions & 8 deletions packages/mdc-textfield/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
// limitations under the License.
//

@mixin mdc-text-field-box-corner-radius($top-left-radius, $top-right-radius: $top-left-radius) {
border-radius: $top-left-radius $top-right-radius 0 0;
}

@mixin mdc-text-field-textarea-corner-radius($radius) {
border-radius: $radius;

.mdc-textfield__label {
border-radius: $radius;
}

.mdc-textfield__input {
// The input element is required to have 2 pixels shaved off
// of the radius of its parent. This prevents an ugly space of
// background between the two borders in each corner when the
// textarea is focused. This also means we need to guard against
// invalid output with @if/@else directives.
@if ($radius >= 2) {
border-radius: $radius - 2;
} @else {
border-radius: 0;
}
}
}

@mixin mdc-text-field-invalid-label-shake-keyframes_($modifier, $positionY) {
@keyframes invalid-shake-float-above-#{$modifier} {
0% {
Expand All @@ -35,11 +60,3 @@
}
}
}

@mixin mdc-text-field-corner-radius($position, $radius) {
border-#{$position}-radius: $radius;
}

@mixin mdc-text-field-corner-radius-all($radius) {
border-radius: $radius;
}
2 changes: 2 additions & 0 deletions packages/mdc-textfield/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ $mdc-textarea-light-background: rgba(white, 1);
$mdc-textarea-dark-background: rgba(48, 48, 48, 1);
$mdc-textarea-disabled-background-on-light: rgba(249, 249, 249, 1);
$mdc-textarea-disabled-background-on-dark: rgba(47, 47, 47, 1);

$mdc-textfield-border-radius: 4px !default;
14 changes: 5 additions & 9 deletions packages/mdc-textfield/mdc-textfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@
}

.mdc-textfield--box {
@include mdc-text-field-corner-radius-all(0);
@include mdc-text-field-corner-radius(top-left, 4px);
@include mdc-text-field-corner-radius(top-right, 4px);
@include mdc-text-field-box-corner-radius($mdc-textfield-default-border-radius);

display: inline-flex;
position: relative;
Expand All @@ -179,13 +177,12 @@

&::before,
&::after {
@include mdc-text-field-corner-radius-all(50%);

position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
background-color: inherit;
opacity: 0;
pointer-events: none;
Expand Down Expand Up @@ -506,7 +503,7 @@
}

.mdc-textfield--textarea {
@include mdc-text-field-corner-radius-all(4px);
@include mdc-text-field-textarea-corner-radius($mdc-textfield-default-border-radius);

$padding-inset: 16px;
$label-offset-y: $padding-inset + 2;
Expand All @@ -516,15 +513,14 @@
height: initial;
transition: none;
border: 1px solid $mdc-textarea-border-on-light;
overflow: hidden;

@include mdc-theme-dark(".mdc-textfield") {
border-color: $mdc-textarea-border-on-dark;
}

// stylelint-disable plugin/selector-bem-pattern
.mdc-textfield__input {
@include mdc-text-field-corner-radius-all(2px);

padding: $padding-inset;
padding-top: $padding-inset * 2;
border: 1px solid transparent;
Expand Down Expand Up @@ -688,7 +684,7 @@

&::before,
&::after {
@include mdc-text-field-corner-radius-all(0);
border-radius: 0;
}

.mdc-textfield__input {
Expand Down

0 comments on commit be494d7

Please sign in to comment.