From 989c51611f96da222f904375431fac3526449675 Mon Sep 17 00:00:00 2001 From: Will Ernest <34519388+williamernest@users.noreply.github.com> Date: Mon, 22 Jan 2018 13:15:08 -0800 Subject: [PATCH] feat(text-field): Move final JS colors to mixins. Update demos (#2006) feat(text-field): Move final JS colors to mixins. Update demos --- demos/text-field.html | 91 ++++++++-- demos/text-field.scss | 92 ++++++++-- packages/mdc-textfield/README.md | 9 +- packages/mdc-textfield/_mixins.scss | 162 +++++++++--------- .../mdc-textfield/bottom-line/_mixins.scss | 10 +- .../mdc-textfield/helper-text/_mixins.scss | 2 +- packages/mdc-textfield/icon/_mixins.scss | 31 ++++ .../icon/mdc-text-field-icon.scss | 4 - packages/mdc-textfield/label/_mixins.scss | 7 + packages/mdc-textfield/mdc-text-field.scss | 54 +++--- 10 files changed, 322 insertions(+), 140 deletions(-) create mode 100644 packages/mdc-textfield/icon/_mixins.scss diff --git a/demos/text-field.html b/demos/text-field.html index 95b84903e00..41475412813 100644 --- a/demos/text-field.html +++ b/demos/text-field.html @@ -119,10 +119,6 @@

Full Functionality JS Component (Floating Label, Validation)

-
- - -
@@ -168,8 +164,7 @@

Outlined Text Field

-

+

Must be at least 8 characters

@@ -221,7 +216,7 @@

Outlined Text Field

Text Field box

-
@@ -247,6 +242,14 @@

Text Field box

+
+ + +
+
+ + +
@@ -346,6 +360,10 @@

Text Field - Leading/Trailing icons

+
+ + +
@@ -383,6 +401,10 @@

Textarea

+
+ + +
@@ -413,6 +435,14 @@

Full-Width Text Field and Textarea

+
+ + +
+
+ + +
@@ -447,6 +477,7 @@

Full-Width Text Field and Textarea

var wrapperOutlinedTrailing = document.getElementById('demo-tf-outlined-trailing-wrapper'); var tfIcons = document.querySelectorAll('.mdc-text-field__icon'); + var tfInputs = tfIconContainer.querySelectorAll('.mdc-text-field__input'); document.getElementById('disable-leading-trailing').addEventListener('change', function(evt) { tfBoxLeading.disabled = evt.target.checked; @@ -498,12 +529,26 @@

Full-Width Text Field and Textarea

}); document.getElementById('required-leading-trailing').addEventListener('change', function(evt) { - tfIconContainer.querySelectorAll('.mdc-text-field__input') - .forEach(function(input) { + [].slice.call(tfInputs).forEach(function(input) { input.required = evt.target.checked; input.pattern = evt.target.checked ? '.{8,}' : '.*'; }); }); + + document.getElementById('leading-trailing-alternate-colors').addEventListener('change', function(evt) { + tfBoxLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors'); + tfBoxLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors'); + tfBoxLeading.layout(); + tfBoxTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors'); + tfBoxTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors'); + tfBoxTrailing.layout(); + tfOutlinedLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors'); + tfOutlinedLeadingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors'); + tfOutlinedLeading.layout(); + tfOutlinedTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-colors'); + tfOutlinedTrailingEl.classList[evt.target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors'); + tfOutlinedTrailing.layout(); + }); }); demoReady(function() { @@ -539,9 +584,6 @@

Full-Width Text Field and Textarea

document.getElementById('alternate-colors').addEventListener('change', function (evt) { var target = evt.target; tfRoot.classList[target.checked ? 'add' : 'remove']('demo-text-field-custom-colors'); - }); - document.getElementById('alternate-error-colors').addEventListener('change', function (evt) { - var target = evt.target; tfRoot.classList[target.checked ? 'add' : 'remove']('demo-text-field-custom-error-colors'); }); document.getElementById('use-helper-text').addEventListener('change', function(evt) { @@ -584,9 +626,18 @@

Full-Width Text Field and Textarea

var target = evt.target; section.classList[target.checked ? 'add' : 'remove']('mdc-theme--dark'); }); + + document.getElementById('textarea-alternate-colors').addEventListener('change', function (evt) { + var target = evt.target; + tfRoot.classList[target.checked ? 'add' : 'remove']('demo-textarea'); + }); + document.getElementById('textarea-required').addEventListener('change', function(evt) { var target = evt.target; - tfRoot.querySelector('.mdc-text-field__input').required = target.checked; + [].slice.call(tfRoot.querySelectorAll('.mdc-text-field__input')) + .forEach(function(input) { + input.required = target.checked; + }) }); }); @@ -615,6 +666,20 @@

Full-Width Text Field and Textarea

var target = evt.target; section.classList[target.checked ? 'add' : 'remove']('mdc-theme--dark'); }); + + document.getElementById('fullwidth-required').addEventListener('change', function(evt) { + var target = evt.target; + [].slice.call(section.querySelectorAll('.mdc-text-field__input')) + .forEach(function(input) { + input.required = target.checked; + }) + }); + + document.getElementById('fullwidth-alternate-colors').addEventListener('change', function (evt) { + var target = evt.target; + tfRoot.classList[target.checked ? 'add' : 'remove']('demo-fullwidth-input'); + tfMultiRoot.classList[target.checked ? 'add' : 'remove']('demo-textarea'); + }); }); diff --git a/demos/text-field.scss b/demos/text-field.scss index f25f0b74807..9be6aed9df1 100644 --- a/demos/text-field.scss +++ b/demos/text-field.scss @@ -20,30 +20,94 @@ // stylelint-disable selector-class-pattern .demo-text-field-custom-colors:not(.mdc-text-field--invalid) { - @include mdc-text-field-bottom-line-color(rgba(blue, .38)); - @include mdc-text-field-hover-bottom-line-color(rgba(blue, .6)); - @include mdc-text-field-focused-bottom-line-color(blue); + $idle-border: rgba(blue, .38); + $hover-border: rgba(blue, .6); + $focused-border: rgba(blue, 1); + + @include mdc-text-field-bottom-line-color($idle-border); + @include mdc-text-field-hover-bottom-line-color($hover-border); + @include mdc-text-field-focused-bottom-line-color($focused-border); @include mdc-text-field-ink-color(black); @include mdc-text-field-label-color(rgba(blue, .5)); - @include mdc-text-field-outline-color(rgba(blue, .38)); - @include mdc-text-field-hover-outline-color(rgba(blue, .6)); - @include mdc-text-field-focused-outline-color(rgba(blue, 1)); - @include mdc-text-field-helper-text-color(rgba(blue, .38)); + @include mdc-text-field-outline-color($idle-border); + @include mdc-text-field-hover-outline-color($hover-border); + @include mdc-text-field-focused-outline-color($focused-border); + @include mdc-text-field-helper-text-color($idle-border); + @include mdc-text-field-textarea-stroke-color($idle-border); + @include mdc-text-field-icon-color($hover-border); &.mdc-text-field--focused { @include mdc-text-field-label-color(rgba(blue, .87)); + @include mdc-text-field-icon-color($focused-border); } } -.demo-text-field-custom-error-colors.mdc-text-field--invalid { - @include mdc-text-field-bottom-line-color(rgba(orange, .38)); - @include mdc-text-field-hover-bottom-line-color(rgba(orange, .6)); +.demo-textarea:not(.mdc-text-field--invalid) { + $idle-border: rgba(blue, .38); + $hover-border: rgba(blue, .6); + $focused-border: rgba(blue, 1); + + @include mdc-text-field-ink-color(black); + @include mdc-text-field-label-color(rgba(blue, .5)); + @include mdc-text-field-textarea-stroke-color($idle-border); + + &.mdc-text-field--focused { + @include mdc-text-field-label-color(rgba(blue, .87)); + @include mdc-text-field-textarea-stroke-color($focused-border); + } +} + +.demo-textarea.mdc-text-field--invalid { + @include mdc-text-field-ink-color(orange); + @include mdc-text-field-label-color(rgba(orange, .5)); + @include mdc-text-field-textarea-stroke-color(orange); + + &.mdc-text-field--focused { + @include mdc-text-field-label-color(rgba(orange, .87)); + @include mdc-text-field-textarea-stroke-color(orange); + } +} + +.demo-fullwidth-input:not(.mdc-text-field--invalid) { + @include mdc-text-field-ink-color(black); + @include mdc-text-field-label-color(rgba(blue, .5)); + @include mdc-text-field-focused-bottom-line-color(blue); + + &.mdc-text-field--focused { + @include mdc-text-field-label-color(rgba(blue, .87)); + } +} + +.demo-fullwidth-input.mdc-text-field--invalid { + @include mdc-text-field-ink-color(orange); + @include mdc-text-field-label-color(rgba(orange, .5)); @include mdc-text-field-focused-bottom-line-color(orange); + + &.mdc-text-field--focused { + @include mdc-text-field-label-color(rgba(orange, .87)); + @include mdc-text-field-fullwidth-bottom-line-color(orange); + } +} + +.demo-text-field-custom-error-colors.mdc-text-field--invalid { + $idle-border: rgba(orange, .38); + $hover-border: rgba(orange, .6); + $focused-border: rgba(orange, 1); + + @include mdc-text-field-bottom-line-color($idle-border); + @include mdc-text-field-hover-bottom-line-color($hover-border); + @include mdc-text-field-focused-bottom-line-color($focused-border); @include mdc-text-field-ink-color(orange); @include mdc-text-field-label-color(rgba(orange, .87)); - @include mdc-text-field-outline-color(rgba(orange, .38)); - @include mdc-text-field-hover-outline-color(rgba(orange, .6)); - @include mdc-text-field-focused-outline-color(rgba(orange, 1)); - @include mdc-text-field-helper-text-validation-color(rgba(orange, .6)); + @include mdc-text-field-outline-color($idle-border); + @include mdc-text-field-hover-outline-color($hover-border); + @include mdc-text-field-focused-outline-color($focused-border); + @include mdc-text-field-helper-text-validation-color($hover-border); + @include mdc-text-field-textarea-stroke-color($idle-border); + + @include mdc-text-field-icon-color($focused-border); + + // Example for --invalid textfield when helper text is not a validation message. + @include mdc-text-field-helper-text-color(rgba(blue, .6)); } // stylelint-enable selector-class-pattern diff --git a/packages/mdc-textfield/README.md b/packages/mdc-textfield/README.md index 0175cc0d173..ca42496a84b 100644 --- a/packages/mdc-textfield/README.md +++ b/packages/mdc-textfield/README.md @@ -172,14 +172,19 @@ Mixin | Description --- | --- `mdc-text-field-box-corner-radius($radius)` | Customizes the border radius for a box text field `mdc-text-field-textarea-corner-radius($radius)` | Customizes the border radius for a `