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

refactor(notched-outline): Refactor notched outline to use 3 divs #4035

Merged
merged 64 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a17c736
refactor(notched-outline): Refactor notched outline to use 3 divs
williamernest Nov 1, 2018
d5c8b87
refactor(notched-outline): Fix lint errors
williamernest Nov 1, 2018
9f7118e
refactor(notched-outline): Update select label
williamernest Nov 1, 2018
56b5690
refactor(notched-outline): Cleanup
williamernest Nov 1, 2018
ebbb08a
refactor(notched-outline): Fix closure
williamernest Nov 1, 2018
277b0b6
feat(notched-outline): Adjust leading icon and floating label padding
williamernest Nov 2, 2018
448f6db
fix(notched-outline): Update select floating label layout
williamernest Nov 2, 2018
3b39382
feat(notched-outline): Minor layout adjustments
williamernest Nov 2, 2018
46d6eeb
feat(notched-outline): Add FOUC transforms
williamernest Nov 2, 2018
6fe1882
fix(notched-outline): Fix notched state for outline
williamernest Nov 2, 2018
7a0a26b
Merge branch 'master' into refactor/notched-outline
williamernest Nov 2, 2018
eff8812
refactor(notched-outline): Update asterisk for required
williamernest Nov 2, 2018
86c2b8c
Merge branch 'master' into refactor/notched-outline
williamernest Nov 8, 2018
3520d1f
fix(notched-outline): Update textarea styles
williamernest Nov 8, 2018
1b931f6
refactor(select): Update
williamernest Nov 14, 2018
d02b300
refactor(notched-outline): Update
williamernest Nov 14, 2018
bac20d3
Merge branch 'master' into refactor/notched-outline
williamernest Nov 14, 2018
daa35f3
refactor(notched-outline): Add variable
williamernest Nov 14, 2018
fcee88f
refactor(notched-outline): Adjust styles for icons
williamernest Nov 14, 2018
4feda93
refactor(notched-outline): Move label into notched-outline
williamernest Nov 14, 2018
a05f6bd
refactor(notched-outline): Fix tests
williamernest Nov 14, 2018
6ee812a
refactor(notched-outline): Update
williamernest Nov 15, 2018
6547c39
refactor(notched-outline): Update
williamernest Nov 15, 2018
f320482
refactor(notched-outline): Remove extra label
williamernest Nov 15, 2018
e4b0c0d
Merge branch 'master' into refactor/notched-outline
williamernest Nov 15, 2018
59651e8
Merge branch 'master' into refactor/notched-outline
williamernest Nov 20, 2018
a848d3b
Merge branch 'master' into refactor/notched-outline
williamernest Nov 20, 2018
71ea18b
refactor(notched-outline): Update text field outlined shape radius st…
williamernest Nov 20, 2018
28a9375
refactor(notched-outline): Update outlined mixins for padding
williamernest Nov 20, 2018
5455f94
refactor(notched-outline): Detect and add class if no label element
williamernest Nov 21, 2018
333404b
refactor(notched-outline): Add no js screenshots to test for FOUC
williamernest Nov 21, 2018
8cbde9a
Merge branch 'master' into refactor/notched-outline
williamernest Nov 21, 2018
7027f18
refactor(notched-outline): Update goldens
williamernest Nov 21, 2018
63d6800
refactor(notched-outline): Cleanup
williamernest Nov 21, 2018
c5f2fe3
Merge branch 'master' into refactor/notched-outline
williamernest Nov 21, 2018
e95ae74
refactor(notched-outline): Move mixin to notched-outline
williamernest Nov 21, 2018
33f5cb7
refactor(notched-outline): Fix rtl for notched-outline
williamernest Nov 21, 2018
44b594c
refactor(notched-outline): Update text field --dense variants styles …
williamernest Nov 26, 2018
40a8252
refactor(notched-outline): Revert screenshot changes
williamernest Nov 26, 2018
342b98d
refactor(notched-outline): add upgraded to root element
williamernest Nov 26, 2018
2544d6f
refactor(notched-outline): Remove duplicate shape
williamernest Nov 26, 2018
1241ce0
Merge branch 'master' into refactor/notched-outline
williamernest Nov 26, 2018
17095c5
WIP Fix excessive border-radius styles
Nov 27, 2018
bd6009f
WIP Fix lint and closure
Nov 30, 2018
fa6ce6a
WIP Notched Outline readme updates
Nov 30, 2018
e3eaf88
Merge remote-tracking branch 'origin/master' into refactor/notched-ou…
Nov 30, 2018
396c4eb
WIP Update goldens due to sync with master
Nov 30, 2018
18c3f8c
feat(notched-outline): Update for some comments
williamernest Nov 30, 2018
c2b5805
WIP: Update for comments
williamernest Nov 30, 2018
1ef9676
Merge branch 'master' into refactor/notched-outline
williamernest Nov 30, 2018
0cdbf56
WIP: Update tests
williamernest Dec 1, 2018
6779c07
WIP: Add no-js to page
williamernest Dec 1, 2018
e47e319
WIP Add No JS to the other no-js test page
Dec 1, 2018
d04990f
WIP Replace mdc-rtl with equivalent mdc-rtl-reflexive-box for noflip
Dec 1, 2018
438c8bc
WIP Remove remaining stale notched-outline DOM references
Dec 3, 2018
1e04648
WIP Remove obsolete scss comments
Dec 3, 2018
677c83a
WIP Remove obsolete section from README
Dec 3, 2018
013ae74
WIP: Add extra selector to float position mixin
williamernest Dec 4, 2018
f27f8c2
Merge branch 'master' into refactor/notched-outline
williamernest Dec 4, 2018
d10994a
WIP: Fix missed imports
williamernest Dec 4, 2018
06b148a
WIP: Update dense variant for text field
williamernest Dec 4, 2018
7869033
WIP: Update readme with dense deprececation notice
williamernest Dec 4, 2018
e3da3e3
WIP: Remove textarea mixin apply fill color to label
williamernest Dec 4, 2018
955ca04
Merge branch 'master' into refactor/notched-outline
williamernest Dec 4, 2018
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
27 changes: 12 additions & 15 deletions demos/text-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ <h2>Outlined Text Field</h2>
aria-describedby="name-validation-message">
<label for="tf-outlined-input" class="mdc-floating-label">Your Name</label>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
<p class="mdc-text-field-helper-text mdc-text-field-helper-text--validation-msg"
id="name-validation-message">Helper Text</p>
Expand Down Expand Up @@ -213,11 +212,10 @@ <h2>Text Field - Leading/Trailing icons</h2>
<input type="text" id="tf-outlined-leading" class="mdc-text-field__input">
<label for="tf-outlined-leading" class="mdc-floating-label">Your other name</label>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>
<div id="demo-tf-outlined-trailing-wrapper" class="demo-text-field-wrapper demo-tf-add-space">
Expand All @@ -227,11 +225,10 @@ <h2>Text Field - Leading/Trailing icons</h2>
<label for="tf-outlined-trailing" class="mdc-floating-label">Your other name</label>
<i class="material-icons mdc-text-field__icon" tabindex="0" role="button">delete</i>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>
<div>
Expand Down
9 changes: 4 additions & 5 deletions demos/theme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,10 @@ <h3 class="mdc-typography--headline5 demo-component-section__heading">
aria-describedby="demo-text-field-helper-text">
<label for="demo-text-field" class="mdc-floating-label">Outlined Text Field</label>
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
</div>
<div class="mdc-notched-outline__idle"></div>
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
<p class="mdc-text-field-helper-text" id="demo-text-field-helper-text"
aria-hidden="true">
Expand Down
2 changes: 2 additions & 0 deletions packages/mdc-floating-label/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
const cssClasses = {
LABEL_FLOAT_ABOVE: 'mdc-floating-label--float-above',
LABEL_SHAKE: 'mdc-floating-label--shake',
ROOT: 'mdc-floating-label',
UPGRADED: 'mdc-floating-label--upgraded',
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
};

export {cssClasses};
5 changes: 5 additions & 0 deletions packages/mdc-floating-label/mdc-floating-label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
cursor: auto;
}

//.mdc-floating-label--upgraded {
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
// .mdc-floating-label--float-above {
// }
//}

@at-root {
@include mdc-floating-label-float-position($mdc-floating-label-position-y);
@include mdc-floating-label-shake-animation(standard);
Expand Down
14 changes: 6 additions & 8 deletions packages/mdc-notched-outline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ npm install @material/notched-outline

```html
<div class="mdc-notched-outline">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
<div class="mdc-notched-outline__idle"></div>
```

> For usage within a text field see [here](../mdc-textfield/README.md#outlined).
Expand Down Expand Up @@ -95,11 +94,10 @@ Consider the following example HTML:
```html
<div class="foo__parent">
<div class="mdc-notched-outline foo__child">
<svg>
<path class="mdc-notched-outline__path"/>
</svg>
<div class="mdc-notched-outline__leading"></div>
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
<div class="mdc-notched-outline__notch"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
<div class="mdc-notched-outline__idle"></div>
</div>
```
In order to customize any "non-idle" part of notched-outline, use the .foo__child CSS selector:
Expand Down
26 changes: 22 additions & 4 deletions packages/mdc-notched-outline/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

@import "@material/theme/mixins";
@import "@material/shape/mixins";
@import "@material/rtl/mixins";

@mixin mdc-notched-outline-idle-color($color) {
.mdc-notched-outline__idle {
Expand All @@ -30,19 +31,36 @@
}

@mixin mdc-notched-outline-color($color) {
.mdc-notched-outline__path {
@include mdc-theme-prop(stroke, $color);
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
@include mdc-theme-prop(border-color, $color);
}
}

@mixin mdc-notched-outline-stroke-width($width) {
.mdc-notched-outline__path {
stroke-width: $width;
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
border-width: $width;
}
}

@mixin mdc-notched-outline-shape-radius($radius, $rtl-reflexive: false) {
@include mdc-shape-radius($radius, $rtl-reflexive);
$radius: mdc-shape-prop-value($radius);

.mdc-notched-outline__leading {
@include mdc-rtl-reflexive(border-radius, 0 $radius $radius 0, border-radius, $radius 0 0 $radius);
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved

@if ($radius > 12px) {
width: $radius;
}
}

.mdc-notched-outline__trailing {
@include mdc-rtl-reflexive(border-radius, $radius 0 0 $radius, border-radius, 0 $radius $radius 0);
}
}

@mixin mdc-notched-outline-idle-shape-radius($radius, $rtl-reflexive: false) {
Expand Down
26 changes: 3 additions & 23 deletions packages/mdc-notched-outline/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@
* @record
*/
class MDCNotchedOutlineAdapter {
/**
* Returns the width of the root element.
* @return {number}
*/
getWidth() {}

/**
* Returns the height of the root element.
* @return {number}
*/
getHeight() {}

/**
* Adds a class to the root element.
* @param {string} className
Expand All @@ -59,18 +47,10 @@ class MDCNotchedOutlineAdapter {
removeClass(className) {}

/**
* Sets the "d" attribute of the outline element's SVG path.
* @param {string} value
*/
setOutlinePathAttr(value) {}

/**
* Returns the idle outline element's computed style value of the given css property `propertyName`.
* We achieve this via `getComputedStyle(...).getPropertyValue(propertyName)`.
* @param {string} propertyName
* @return {string}
* Sets the width style property of the notch element.
* @param {number} width
*/
getIdleOutlineStyleValue(propertyName) {}
setNotchWidthProperty(width) {}
}

export default MDCNotchedOutlineAdapter;
11 changes: 2 additions & 9 deletions packages/mdc-notched-outline/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@

/** @enum {string} */
const strings = {
PATH_SELECTOR: '.mdc-notched-outline__path',
IDLE_OUTLINE_SELECTOR: '.mdc-notched-outline__idle',
NOTCH_ELEMENT_SELECTOR: '.mdc-notched-outline__notch',
};

/** @enum {string} */
const cssClasses = {
OUTLINE_NOTCHED: 'mdc-notched-outline--notched',
};

/** @enum {number} */
const numbers = {
NOTCH_GUTTER_SIZE: 4,
MIN_LEADING_STROKE_EDGE_POSITION: 12,
};

export {cssClasses, strings, numbers};
export {cssClasses, strings};
73 changes: 11 additions & 62 deletions packages/mdc-notched-outline/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import MDCFoundation from '@material/base/foundation';
import MDCNotchedOutlineAdapter from './adapter';
import {cssClasses, strings, numbers} from './constants';
import {cssClasses, strings} from './constants';

/**
* @extends {MDCFoundation<!MDCNotchedOutlineAdapter>}
Expand All @@ -40,24 +40,16 @@ class MDCNotchedOutlineFoundation extends MDCFoundation {
return cssClasses;
}

/** @return enum {number} */
static get numbers() {
return numbers;
}

/**
* {@see MDCNotchedOutlineAdapter} for typing information on parameters and return
* types.
* @return {!MDCNotchedOutlineAdapter}
*/
static get defaultAdapter() {
return /** @type {!MDCNotchedOutlineAdapter} */ ({
getWidth: () => {},
getHeight: () => {},
addClass: () => {},
removeClass: () => {},
setOutlinePathAttr: () => {},
getIdleOutlineStyleValue: () => {},
setNotchWidthProperty: () => {},
});
}

Expand All @@ -70,14 +62,18 @@ class MDCNotchedOutlineFoundation extends MDCFoundation {

/**
* Adds the outline notched selector and updates the notch width
* calculated based off of notchWidth and isRtl.
* calculated based off of notchWidth.
* @param {number} notchWidth
* @param {boolean=} isRtl
*/
notch(notchWidth, isRtl = false) {
notch(notchWidth) {
const {OUTLINE_NOTCHED} = MDCNotchedOutlineFoundation.cssClasses;

if (notchWidth > 0) {
notchWidth += 8; // Add padding from left/right.
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
}

this.adapter_.setNotchWidthProperty(notchWidth);
this.adapter_.addClass(OUTLINE_NOTCHED);
this.updateSvgPath_(notchWidth, isRtl);
}

/**
Expand All @@ -86,54 +82,7 @@ class MDCNotchedOutlineFoundation extends MDCFoundation {
closeNotch() {
const {OUTLINE_NOTCHED} = MDCNotchedOutlineFoundation.cssClasses;
this.adapter_.removeClass(OUTLINE_NOTCHED);
}

/**
* Updates the SVG path of the focus outline element based on the notchWidth
* and the RTL context.
* @param {number} notchWidth
* @param {boolean=} isRtl
* @private
*/
updateSvgPath_(notchWidth, isRtl) {
// Fall back to reading a specific corner's style because Firefox doesn't report the style on border-radius.
const radiusStyleValue = this.adapter_.getIdleOutlineStyleValue('border-radius') ||
this.adapter_.getIdleOutlineStyleValue('border-top-left-radius');
const radius = parseFloat(radiusStyleValue);
const width = this.adapter_.getWidth();
const height = this.adapter_.getHeight();
const cornerWidth = radius + 1.2;
const leadingStrokeLength = Math.max(0, numbers.MIN_LEADING_STROKE_EDGE_POSITION - radius - 1.2);

// If the notchWidth is 0, the the notched outline doesn't need to add padding.
let paddedNotchWidth = 0;
if (notchWidth > 0) {
paddedNotchWidth = notchWidth + 2 * numbers.NOTCH_GUTTER_SIZE;
}

// The right, bottom, and left sides of the outline follow the same SVG path.
const pathMiddle = 'a' + radius + ',' + radius + ' 0 0 1 ' + radius + ',' + radius
+ 'v' + (height - (2 * cornerWidth))
+ 'a' + radius + ',' + radius + ' 0 0 1 ' + -radius + ',' + radius
+ 'h' + (-width + (2 * cornerWidth))
+ 'a' + radius + ',' + radius + ' 0 0 1 ' + -radius + ',' + -radius
+ 'v' + (-height + (2 * cornerWidth))
+ 'a' + radius + ',' + radius + ' 0 0 1 ' + radius + ',' + -radius;

let path;
if (!isRtl) {
path = 'M' + (cornerWidth + leadingStrokeLength + paddedNotchWidth) + ',' + 1
+ 'h' + (width - (2 * cornerWidth) - paddedNotchWidth - leadingStrokeLength)
+ pathMiddle
+ 'h' + leadingStrokeLength;
} else {
path = 'M' + (width - cornerWidth - leadingStrokeLength) + ',' + 1
+ 'h' + leadingStrokeLength
+ pathMiddle
+ 'h' + (width - (2 * cornerWidth) - paddedNotchWidth - leadingStrokeLength);
}

this.adapter_.setOutlinePathAttr(path);
this.adapter_.setNotchWidthProperty(0);
}
}

Expand Down
Loading