Skip to content

Commit 5099a97

Browse files
committed
separate md-form-field into separate directory
1 parent 8dd246a commit 5099a97

25 files changed

+727
-599
lines changed

src/demo-app/demo-material-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
MdDatepickerModule,
1212
MdDialogModule,
1313
MdExpansionModule,
14+
MdFormFieldModule,
1415
MdGridListModule,
1516
MdIconModule,
1617
MdInputModule,
@@ -50,6 +51,7 @@ import {CdkTableModule} from '@angular/cdk/table';
5051
MdDatepickerModule,
5152
MdDialogModule,
5253
MdExpansionModule,
54+
//MdFormFieldModule,
5355
MdGridListModule,
5456
MdIconModule,
5557
MdInputModule,

src/e2e-app/e2e-app-module.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,24 @@ import {InputE2E} from './input/input-e2e';
2020
import {SidenavE2E} from './sidenav/sidenav-e2e';
2121
import {BlockScrollStrategyE2E} from './block-scroll-strategy/block-scroll-strategy-e2e';
2222
import {
23-
OverlayContainer, FullscreenOverlayContainer, MdGridListModule, MdProgressBarModule,
24-
MdProgressSpinnerModule, MdTabsModule, MdRadioModule, MdSlideToggleModule, MdMenuModule,
25-
MdListModule, MdInputModule, MdIconModule, MdDialogModule, MdCheckboxModule, MdButtonModule,
26-
MdSidenavModule, MdNativeDateModule,
23+
FullscreenOverlayContainer,
24+
MdButtonModule,
25+
MdCheckboxModule,
26+
MdDialogModule,
27+
MdFormFieldModule,
28+
MdGridListModule,
29+
MdIconModule,
30+
MdInputModule,
31+
MdListModule,
32+
MdMenuModule,
33+
MdNativeDateModule,
34+
MdProgressBarModule,
35+
MdProgressSpinnerModule,
36+
MdRadioModule,
37+
MdSidenavModule,
38+
MdSlideToggleModule,
39+
MdTabsModule,
40+
OverlayContainer,
2741
} from '@angular/material';
2842
import {ExampleModule} from '@angular/material-examples';
2943

@@ -35,6 +49,7 @@ import {ExampleModule} from '@angular/material-examples';
3549
MdButtonModule,
3650
MdCheckboxModule,
3751
MdDialogModule,
52+
MdFormFieldModule,
3853
MdGridListModule,
3954
MdIconModule,
4055
MdInputModule,

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import {Observable} from 'rxjs/Observable';
4040
import {MdOptionSelectionChange, MdOption} from '../core/option/option';
4141
import {ENTER, UP_ARROW, DOWN_ARROW, ESCAPE} from '../core/keyboard/keycodes';
4242
import {Directionality} from '../core/bidi/index';
43-
import {MdFormField, MdInput} from '../input/input-container';
43+
import {MdFormField} from '../form-field/index';
44+
import {MdInput} from '../input/input';
4445
import {Subscription} from 'rxjs/Subscription';
4546
import {merge} from 'rxjs/observable/merge';
4647
import {fromEvent} from 'rxjs/observable/fromEvent';

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Directionality, Direction} from '../core/bidi/index';
2323
import {Subscription} from 'rxjs/Subscription';
2424
import {ENTER, DOWN_ARROW, SPACE, UP_ARROW, ESCAPE} from '../core/keyboard/keycodes';
2525
import {MdOption} from '../core/option/option';
26-
import {MdFormField} from '../input/input-container';
26+
import {MdFormField, MdFormFieldModule} from '../form-field/index';
2727
import {Observable} from 'rxjs/Observable';
2828
import {Subject} from 'rxjs/Subject';
2929
import {createKeyboardEvent, dispatchFakeEvent, typeInElement} from '@angular/cdk/testing';
@@ -41,6 +41,7 @@ describe('MdAutocomplete', () => {
4141
TestBed.configureTestingModule({
4242
imports: [
4343
MdAutocompleteModule,
44+
MdFormFieldModule,
4445
MdInputModule,
4546
FormsModule,
4647
ReactiveFormsModule,

src/lib/chips/chip-list.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {createKeyboardEvent} from '@angular/cdk/testing';
99
import {MdInputModule} from '../input/index';
1010
import {LEFT_ARROW, RIGHT_ARROW, BACKSPACE, DELETE, TAB} from '../core/keyboard/keycodes';
1111
import {Directionality} from '../core';
12+
import {MdFormFieldModule} from '../form-field/index';
1213

1314
describe('MdChipList', () => {
1415
let fixture: ComponentFixture<any>;
@@ -23,7 +24,7 @@ describe('MdChipList', () => {
2324

2425
beforeEach(async(() => {
2526
TestBed.configureTestingModule({
26-
imports: [MdChipsModule, MdInputModule, NoopAnimationsModule],
27+
imports: [MdChipsModule, MdFormFieldModule, MdInputModule, NoopAnimationsModule],
2728
declarations: [
2829
StandardChipList, InputContainerChipList
2930
],

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@import '../../toolbar/toolbar-theme';
2828
@import '../../tooltip/tooltip-theme';
2929
@import '../../snack-bar/simple-snack-bar-theme';
30+
@import '../../form-field/form-field-theme';
3031

3132

3233
// Create a theme.
@@ -42,6 +43,7 @@
4243
@include mat-datepicker-theme($theme);
4344
@include mat-dialog-theme($theme);
4445
@include mat-expansion-panel-theme($theme);
46+
@include mat-form-field-theme($theme);
4547
@include mat-grid-list-theme($theme);
4648
@include mat-icon-theme($theme);
4749
@include mat-input-theme($theme);

src/lib/core/typography/_all-typography.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@import '../../snack-bar/simple-snack-bar-theme';
2929
@import '../option/option-theme';
3030
@import '../option/optgroup-theme';
31+
@import '../../form-field/form-field-theme';
3132

3233

3334
// Includes all of the typographic styles.
@@ -47,6 +48,7 @@
4748
@include mat-datepicker-typography($config);
4849
@include mat-dialog-typography($config);
4950
@include mat-expansion-panel-typography($config);
51+
@include mat-form-field-typography($config);
5052
@include mat-grid-list-typography($config);
5153
@include mat-icon-typography($config);
5254
@include mat-input-typography($config);

src/lib/datepicker/datepicker-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
Validators
3232
} from '@angular/forms';
3333
import {Subscription} from 'rxjs/Subscription';
34-
import {MdFormField} from '../input/input-container';
34+
import {MdFormField} from '../form-field/index';
3535
import {DOWN_ARROW} from '../core/keyboard/keycodes';
3636
import {DateAdapter} from '../core/datetime/index';
3737
import {createMissingDateImplError} from './datepicker-errors';

src/lib/datepicker/datepicker.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
createKeyboardEvent,
1717
dispatchEvent,
1818
} from '@angular/cdk/testing';
19+
import {MdFormFieldModule} from "../form-field/index";
1920

2021
describe('MdDatepicker', () => {
2122
afterEach(inject([OverlayContainer], (container: OverlayContainer) => {
@@ -28,6 +29,7 @@ describe('MdDatepicker', () => {
2829
imports: [
2930
FormsModule,
3031
MdDatepickerModule,
32+
MdFormFieldModule,
3133
MdInputModule,
3234
MdNativeDateModule,
3335
NoopAnimationsModule,
@@ -817,6 +819,7 @@ describe('MdDatepicker', () => {
817819
imports: [
818820
FormsModule,
819821
MdDatepickerModule,
822+
MdFormFieldModule,
820823
MdInputModule,
821824
NoopAnimationsModule,
822825
ReactiveFormsModule,
@@ -840,7 +843,13 @@ describe('MdDatepicker', () => {
840843

841844
beforeEach(async(() => {
842845
TestBed.configureTestingModule({
843-
imports: [MdDatepickerModule, MdInputModule, MdNativeDateModule, NoopAnimationsModule],
846+
imports: [
847+
MdDatepickerModule,
848+
MdFormFieldModule,
849+
MdInputModule,
850+
MdNativeDateModule,
851+
NoopAnimationsModule
852+
],
844853
declarations: [StandardDatepicker],
845854
}).compileComponents();
846855

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
@import '../core/theming/palette';
2+
@import '../core/theming/theming';
3+
@import '../core/style/form-common';
4+
@import '../core/typography/typography-utils';
5+
6+
7+
@mixin mat-form-field-theme($theme) {
8+
$primary: map-get($theme, primary);
9+
$accent: map-get($theme, accent);
10+
$warn: map-get($theme, warn);
11+
$background: map-get($theme, background);
12+
$foreground: map-get($theme, foreground);
13+
$is-dark-theme: map-get($theme, is-dark);
14+
15+
// Placeholder colors. Required is used for the `*` star shown in the placeholder.
16+
$form-field-placeholder-color: mat-color($foreground, secondary-text);
17+
$form-field-floating-placeholder-color: mat-color($primary);
18+
$form-field-required-placeholder-color: mat-color($accent);
19+
20+
// Underline colors.
21+
$form-field-underline-color: mat-color($foreground, divider, if($is-dark-theme, 0.7, 0.42));
22+
$form-field-underline-color-accent: mat-color($accent);
23+
$form-field-underline-color-warn: mat-color($warn);
24+
$form-field-underline-focused-color: mat-color($primary);
25+
26+
.mat-form-field-placeholder {
27+
color: $form-field-placeholder-color;
28+
}
29+
30+
.mat-hint {
31+
color: mat-color($foreground, secondary-text);
32+
}
33+
34+
.mat-focused .mat-form-field-placeholder {
35+
color: $form-field-floating-placeholder-color;
36+
37+
&.mat-accent {
38+
color: $form-field-underline-color-accent;
39+
}
40+
41+
&.mat-warn {
42+
color: $form-field-underline-color-warn;
43+
}
44+
}
45+
46+
.mat-form-field-autofill-float:-webkit-autofill + .mat-form-field-placeholder,
47+
.mat-focused .mat-form-field-placeholder.mat-form-field-float {
48+
.mat-form-field-required-marker {
49+
color: $form-field-required-placeholder-color;
50+
}
51+
}
52+
53+
.mat-form-field-underline {
54+
background-color: $form-field-underline-color;
55+
56+
&.mat-disabled {
57+
@include mat-control-disabled-underline($form-field-underline-color);
58+
}
59+
}
60+
61+
.mat-form-field-ripple {
62+
background-color: $form-field-underline-focused-color;
63+
64+
&.mat-accent {
65+
background-color: $form-field-underline-color-accent;
66+
}
67+
68+
&.mat-warn {
69+
background-color: $form-field-underline-color-warn;
70+
}
71+
}
72+
73+
// Styling for the error state of the form field. Note that while the same can be
74+
// achieved with the ng-* classes, we use this approach in order to ensure that the same
75+
// logic is used to style the error state and to show the error messages.
76+
.mat-form-field-invalid {
77+
.mat-form-field-placeholder {
78+
color: $form-field-underline-color-warn;
79+
80+
&.mat-accent,
81+
&.mat-form-field-float .mat-form-field-required-marker {
82+
color: $form-field-underline-color-warn;
83+
}
84+
}
85+
86+
.mat-form-field-ripple {
87+
background-color: $form-field-underline-color-warn;
88+
}
89+
}
90+
91+
.mat-error {
92+
color: $form-field-underline-color-warn;
93+
}
94+
}
95+
96+
// Applies a floating placeholder above the form field control itself.
97+
@mixin _mat-form-field-placeholder-floating($font-scale, $infix-padding, $infix-margin-top) {
98+
// We use perspective to fix the text blurriness as described here:
99+
// http://www.useragentman.com/blog/2014/05/04/fixing-typography-inside-of-2-d-css-transforms/
100+
// This results in a small jitter after the label floats on Firefox, which the
101+
// translateZ fixes.
102+
transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale) perspective(100px)
103+
translateZ(0.001px);
104+
// The tricks above used to smooth out the animation on chrome and firefox actually make things
105+
// worse on IE, so we don't include them in the IE version.
106+
-ms-transform: translateY(-$infix-margin-top - $infix-padding)
107+
scale($font-scale);
108+
109+
width: 100% / $font-scale;
110+
}
111+
112+
@mixin mat-form-field-typography($config) {
113+
// The unit-less line-height from the font config.
114+
$line-height: mat-line-height($config, input);
115+
116+
// The amount to scale the font for the floating label and subscript.
117+
$subscript-font-scale: 0.75;
118+
// The amount to scale the font for the prefix and suffix icons.
119+
$prefix-suffix-icon-font-scale: 1.5;
120+
121+
// The amount of space between the top of the line and the top of the actual text
122+
// (as a fraction of the font-size).
123+
$line-spacing: ($line-height - 1) / 2;
124+
// The padding on the infix. Mocks show half of the text size, but seem to measure from the edge
125+
// of the text itself, not the edge of the line; therefore we subtract off the line spacing.
126+
$infix-padding: 0.5em - $line-spacing;
127+
// The margin applied to the form-field-infix to reserve space for the floating label.
128+
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
129+
// Font size to use for the label and subscript text.
130+
$subscript-font-size: $subscript-font-scale * 100%;
131+
// Font size to use for the for the prefix and suffix icons.
132+
$prefix-suffix-icon-font-size: $prefix-suffix-icon-font-scale * 100%;
133+
// The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
134+
// Mocks show half of the text size, but this margin is applied to an element with the subscript
135+
// text font size, so we need to divide by the scale factor to make it half of the original text
136+
// size. We again need to subtract off the line spacing since the mocks measure to the edge of the
137+
// text, not the edge of the line.
138+
$subscript-margin-top: 0.5em / $subscript-font-scale - ($line-spacing * 2);
139+
// The padding applied to the form-field-wrapper to reserve space for the subscript, since it's
140+
// absolutely positioned. This is a combination of the subscript's margin and line-height, but we
141+
// need to multiply by the subscript font scale factor since the wrapper has a larger font size.
142+
$wrapper-padding-bottom: ($subscript-margin-top + $line-height) * $subscript-font-scale;
143+
144+
.mat-form-field {
145+
font-family: mat-font-family($config);
146+
font-size: inherit;
147+
font-weight: mat-font-weight($config, input);
148+
line-height: mat-line-height($config, input);
149+
}
150+
151+
.mat-form-field-wrapper {
152+
padding-bottom: $wrapper-padding-bottom;
153+
}
154+
155+
.mat-form-field-prefix,
156+
.mat-form-field-suffix {
157+
// Allow icons in a prefix or suffix to adapt to the correct size.
158+
.mat-icon {
159+
font-size: $prefix-suffix-icon-font-size;
160+
line-height: $line-height;
161+
}
162+
163+
// Allow icon buttons in a prefix or suffix to adapt to the correct size.
164+
.mat-icon-button {
165+
height: $prefix-suffix-icon-font-scale * 1em;
166+
width: $prefix-suffix-icon-font-scale * 1em;
167+
168+
.mat-icon {
169+
height: $line-height * 1em;
170+
line-height: $line-height;
171+
}
172+
}
173+
}
174+
175+
.mat-form-field-infix {
176+
padding: $infix-padding 0;
177+
// Throws off the baseline if we do it as a real margin, so we do it as a border instead.
178+
border-top: $infix-margin-top solid transparent;
179+
}
180+
181+
.mat-form-field-autofill-float:-webkit-autofill +
182+
.mat-form-field-placeholder-wrapper .mat-form-field-float {
183+
@include _mat-form-field-placeholder-floating(
184+
$subscript-font-scale, $infix-padding, $infix-margin-top);
185+
}
186+
187+
.mat-form-field-placeholder-wrapper {
188+
top: -$infix-margin-top;
189+
padding-top: $infix-margin-top;
190+
}
191+
192+
.mat-form-field-placeholder {
193+
top: $infix-margin-top + $infix-padding;
194+
195+
// Show the placeholder above the control when it's not empty, or focused.
196+
&.mat-form-field-float:not(.mat-form-field-empty),
197+
.mat-focused &.mat-form-field-float {
198+
@include _mat-form-field-placeholder-floating($subscript-font-scale,
199+
$infix-padding, $infix-margin-top);
200+
}
201+
}
202+
203+
.mat-form-field-underline {
204+
// We want the underline to start at the end of the content box, not the padding box,
205+
// so we move it up by the padding amount.
206+
bottom: $wrapper-padding-bottom;
207+
}
208+
209+
.mat-form-field-subscript-wrapper {
210+
font-size: $subscript-font-size;
211+
margin-top: $subscript-margin-top;
212+
213+
// We want the subscript to start at the end of the content box, not the padding box,
214+
// so we move it up by the padding amount (adjusted for the smaller font size);
215+
top: calc(100% - #{$wrapper-padding-bottom / $subscript-font-scale});
216+
}
217+
}

0 commit comments

Comments
 (0)