UNPKG

6.68 kBSCSSView Raw
1@import 'default-theme';
2@import 'mixins';
3@import 'variables';
4
5$md-input-floating-placeholder-scale-factor: 0.75 !default;
6
7// Placeholder colors. Required is used for the `*` star shown in the placeholder.
8$md-input-placeholder-color: md-color($md-foreground, hint-text);
9$md-input-floating-placeholder-color: md-color($md-primary);
10$md-input-required-placeholder-color: md-color($md-accent);
11
12// Underline colors.
13$md-input-underline-color: md-color($md-foreground, hint-text);
14$md-input-underline-color-accent: md-color($md-accent);
15$md-input-underline-color-warn: md-color($md-warn);
16$md-input-underline-disabled-color: md-color($md-foreground, hint-text);
17$md-input-underline-focused-color: md-color($md-primary);
18
19// Gradient for showing the dashed line when the input is disabled.
20$md-input-underline-disabled-background-image: linear-gradient(to right,
21 rgba(0, 0, 0, 0.26) 0%, rgba(0, 0, 0, 0.26) 33%, transparent 0%);
22
23/**
24 * Undo the red box-shadow glow added by Firefox on invalid inputs.
25 * See https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-invalid
26 */
27:-moz-ui-invalid {
28 box-shadow: none;
29}
30
31/**
32 * Applies a floating placeholder above the input itself.
33 */
34@mixin md-input-placeholder-floating {
35 display: block;
36 padding-bottom: 5px;
37 transform: translateY(-100%) scale($md-input-floating-placeholder-scale-factor);
38 width: 100% / $md-input-floating-placeholder-scale-factor;
39
40 .md-placeholder-required {
41 color: $md-input-required-placeholder-color;
42 }
43}
44
45:host {
46 display: inline-block;
47 position: relative;
48 font-family: $md-font-family;
49
50 // To avoid problems with text-align.
51 text-align: left;
52
53 // Global wrapper. We need to apply margin to the element for spacing, but
54 // cannot apply it to the host element directly.
55 .md-input-wrapper {
56 margin: 16px 0;
57 }
58
59 // We use a table layout to baseline align the prefix and suffix classes.
60 // The underline is outside of it so it can cover all of the elements under
61 // this table.
62 // Flex does not respect the baseline. What we really want is akin to a table
63 // as want an inline-block where elements don't wrap.
64 .md-input-table {
65 display: inline-table;
66 flex-flow: column;
67 vertical-align: bottom;
68 width: 100%;
69
70 & > * {
71 display: table-cell;
72 }
73 }
74
75 // The Input element proper.
76 .md-input-element {
77 // Font needs to be inherited, because by default <input> has a system font.
78 font: inherit;
79
80 // The Material input should match whatever background it is above.
81 background: transparent;
82
83 // By default, <input> has a padding, border, outline and a default width.
84 border: none;
85 outline: none;
86 padding: 0;
87 width: 100%;
88
89 &.md-end {
90 text-align: right;
91 }
92 }
93
94 .md-input-infix {
95 position: relative;
96 }
97
98 // The placeholder label. This is invisible unless it is. The logic to show it is
99 // basically `empty || (float && (!empty || focused))`. Float is dependent on the
100 // `floatingPlaceholder` input.
101 .md-input-placeholder {
102 // The placeholder is after the <input>, but needs to be aligned top-left of the
103 // infix <div>.
104 position: absolute;
105 left: 0;
106 top: 0;
107
108 font-size: 100%;
109 pointer-events: none; // We shouldn't catch mouse events (let them through).
110 color: $md-input-placeholder-color;
111 z-index: 1;
112
113 // Put ellipsis text overflow.
114 width: 100%;
115 display: none;
116 white-space: nowrap;
117 text-overflow: ellipsis;
118 overflow-x: hidden;
119
120 transform: translateY(0);
121 transform-origin: bottom left;
122 transition: transform $swift-ease-out-duration $swift-ease-out-timing-function,
123 scale $swift-ease-out-duration $swift-ease-out-timing-function,
124 color $swift-ease-out-duration $swift-ease-out-timing-function,
125 width $swift-ease-out-duration $swift-ease-out-timing-function;
126
127 &.md-empty {
128 display: block;
129 cursor: text;
130 }
131
132 // Show the placeholder above the input when it's not empty, or focused.
133 &.md-float:not(.md-empty), &.md-float.md-focused {
134 @include md-input-placeholder-floating;
135 }
136
137 // :focus is applied to the input, but we apply md-focused to the other elements
138 // that need to listen to it.
139 &.md-focused {
140 color: $md-input-floating-placeholder-color;
141
142 &.md-accent {
143 color: $md-input-underline-color-accent;
144 }
145 &.md-warn {
146 color: $md-input-underline-color-warn;
147 }
148 }
149 }
150
151 // Pseudo-class for Chrome and Safari auto-fill to move the placeholder to
152 // the floating position. This is necessary because these browsers do not actually
153 // fire any events when a form auto-fill is occurring.
154 // Once the autofill is committed, a change event happen and the regular md-input
155 // classes take over to fulfill this behaviour.
156 input:-webkit-autofill + .md-input-placeholder {
157 @include md-input-placeholder-floating;
158 }
159
160 // The underline is what's shown under the input, its prefix and its suffix.
161 // The ripple is the blue animation coming on top of it.
162 .md-input-underline {
163 position: absolute;
164 height: 1px;
165 width: 100%;
166 margin-top: 4px;
167 border-top: 1px solid $md-input-underline-color;
168
169 &.md-disabled {
170 border-top: 0;
171 background-image: $md-input-underline-disabled-background-image;
172 background-position: 0;
173 background-size: 4px 1px;
174 background-repeat: repeat-x;
175 }
176
177 .md-input-ripple {
178 position: absolute;
179 height: 2px;
180 z-index: 1;
181 background-color: $md-input-underline-focused-color;
182 top: -1px;
183 width: 100%;
184 transform-origin: top;
185 opacity: 0;
186 transform: scaleY(0);
187 transition: transform $swift-ease-out-duration $swift-ease-out-timing-function,
188 opacity $swift-ease-out-duration $swift-ease-out-timing-function;
189
190 &.md-accent {
191 background-color: $md-input-underline-color-accent;
192 }
193 &.md-warn {
194 background-color: $md-input-underline-color-warn;
195 }
196
197 &.md-focused {
198 opacity: 1;
199 transform: scaleY(1);
200 }
201 }
202 }
203
204 // The hint is shown below the underline. There can be more than one; one at the start
205 // and one at the end.
206 .md-hint {
207 position: absolute;
208 font-size: 75%;
209 bottom: -0.5em;
210
211 &.md-right {
212 right: 0;
213 }
214 }
215}
216
217
218// RTL support.
219:host-context([dir='rtl']) {
220 text-align: right;
221
222 .md-input-placeholder {
223 transform-origin: bottom right;
224 }
225
226 .md-input-element.md-end {
227 text-align: left;
228 }
229
230 .md-hint {
231 right: 0;
232 left: auto;
233
234 &.md-right {
235 right: auto;
236 left: 0;
237 }
238 }
239}