-
Notifications
You must be signed in to change notification settings - Fork 842
/
_form.scss
332 lines (275 loc) Β· 8.6 KB
/
_form.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// Labels
@mixin euiFormLabel {
@include euiFontSizeXS;
color: $euiTitleColor;
font-weight: $euiFontWeightSemiBold;
}
@mixin euiFormControlLayoutPadding($numOfIcons, $side: 'right', $compressed: false) {
$firstIconSize: $euiFormControlPadding + $euiSize + $euiFormControlPadding;
$secondIconSize: $euiFormControlPadding + $euiSize;
@if ($compressed) {
$firstIconSize: $euiFormControlCompressedPadding + $euiSize + $euiFormControlCompressedPadding;
$secondIconSize: $euiFormControlCompressedPadding + $euiSize;
}
@if variable-exists(numOfIcons) == false {
@error '$numOfIcons:integer (1-3) must be provided to @mixin euiFormControlLayoutPadding().';
} @else if $numOfIcons == 1 {
padding-#{$side}: $firstIconSize;
} @else if $numOfIcons == 2 {
padding-#{$side}: $firstIconSize + $secondIconSize;
} @else if $numOfIcons == 3 {
padding-#{$side}: $firstIconSize + ($secondIconSize * 2);
}
}
@mixin euiFormControlLayoutClearIcon($iconClass) {
$clearSize: $euiSize;
@include size($clearSize);
pointer-events: all;
background-color: lightOrDarkTheme($euiColorMediumShade, $euiColorDarkShade);
border-radius: $clearSize;
line-height: 0; // ensures the icon stays vertically centered
&:focus {
@include euiFocusRing;
}
#{$iconClass} {
@include size($euiSizeS);
fill: $euiColorEmptyShade;
stroke: $euiColorEmptyShade;
stroke-width: 2px; // increase thickness of icon at such a small size
}
}
@mixin euiPlaceholderPerBrowser {
// sass-lint:disable-block no-vendor-prefixes
// Each prefix must be its own content block
&::-webkit-input-placeholder { @content; }
&::-moz-placeholder { @content; }
&:-ms-input-placeholder { @content; }
&:-moz-placeholder { @content; }
&::placeholder { @content; }
}
@function euiFormControlGradient($color: $euiColorPrimary) {
@return linear-gradient(to top,
$color,
$color 2px,
transparent 2px,
transparent 100%
);
}
@mixin euiFormControlText {
@include euiFont;
font-size: $euiFontSizeS;
line-height: 1em; // fixes text alignment in IE
color: $euiTextColor;
// sass-lint:disable-block mixins-before-declarations
@include euiPlaceholderPerBrowser {
color: $euiColorDarkShade;
}
}
@mixin euiFormControlSize(
$height: $euiFormControlHeight,
$includeAlternates: false
) {
// Default
max-width: $euiFormMaxWidth;
width: 100%;
height: $height;
@if ($includeAlternates) {
&--fullWidth {
max-width: 100%;
}
&--compressed {
height: $euiFormControlCompressedHeight;
}
&--inGroup {
height: 100%;
}
}
}
@mixin euiFormControlWithIcon($isIconOptional: false, $side: 'left', $compressed: false) {
@if ($isIconOptional) {
@at-root {
#{&}--withIcon {
@include euiFormControlLayoutPadding(1, $side, $compressed);
}
}
} @else {
@include euiFormControlLayoutPadding(1, $side, $compressed);
}
}
@mixin euiFormControlIsLoading($isNextToIcon: false) {
@at-root {
#{&}-isLoading,
#{&}-isLoading#{&}--compressed {
@if ($isNextToIcon) {
@include euiFormControlLayoutPadding(2);
} @else {
@include euiFormControlLayoutPadding(1);
}
}
}
}
// 1. Must supply both values to background-size or some browsers apply the single value to both directions
@mixin euiFormControlDefaultShadow($borderOnly: false) {
// sass-lint:disable-block indentation
background-color: $euiFormBackgroundColor;
background-repeat: no-repeat;
background-size: 0% 100%; // 1
@if ($borderOnly) {
box-shadow: inset 0 0 0 1px $euiFormBorderColor;
} @else {
box-shadow:
#{$euiFormControlBoxShadow},
inset 0 0 0 1px $euiFormBorderColor;
}
transition:
box-shadow $euiAnimSpeedFast ease-in,
background-image $euiAnimSpeedFast ease-in,
background-size $euiAnimSpeedFast ease-in,
background-color $euiAnimSpeedFast ease-in;
// Fixes bug in Firefox where adding a transition to the background-color
// caused a flash of differently styled dropdown.
@supports (-moz-appearance: none) { // sass-lint:disable-line no-vendor-prefixes
// List *must* be in the same order as the above.
transition-property: box-shadow, background-image, background-size;
}
}
@mixin euiFormControlFocusStyle($borderOnly: false) {
// sass-lint:disable-block indentation, empty-args
background-color: tintOrShade($euiColorEmptyShade, 0%, 40%);
background-image: euiFormControlGradient();
background-size: 100% 100%; // 1
@if ($borderOnly) {
box-shadow: inset 0 0 0 1px $euiFormBorderColor;
} @else {
box-shadow:
0 1px 1px -1px transparentize($euiShadowColor, .8),
0 4px 4px -2px transparentize($euiShadowColor, .8),
inset 0 0 0 1px $euiFormBorderColor;
}
}
@mixin euiFormControlInvalidStyle {
background-image: euiFormControlGradient($euiColorDanger);
background-size: 100%;
}
@mixin euiFormControlDisabledStyle {
cursor: not-allowed;
color: $euiFormControlDisabledColor;
background: $euiFormBackgroundDisabledColor;
box-shadow: inset 0 0 0 1px $euiFormBorderDisabledColor;
// sass-lint:disable-block mixins-before-declarations
@include euiPlaceholderPerBrowser {
color: $euiFormControlDisabledColor;
}
}
@mixin euiFormControlReadOnlyStyle {
cursor: default;
// Use transparency since there is no border and in case form is on a non-white background
background: $euiFormBackgroundReadOnlyColor;
border-color: transparent;
box-shadow: inset 0 0 0 1px $euiFormBorderDisabledColor;
}
// 2. Override invalid state with focus state.
@mixin euiFormControlStyle($borderOnly: false, $includeStates: true, $includeSizes: true) {
@include euiFormControlSize($includeAlternates: $includeSizes);
@include euiFormControlDefaultShadow;
@include euiFormControlText;
border: none;
border-radius: 0;
padding: $euiFormControlPadding;
@if ($includeStates) {
&:invalid { // 2
@include euiFormControlInvalidStyle;
}
&:focus { // 2
@include euiFormControlFocusStyle;
}
&:disabled {
@include euiFormControlDisabledStyle;
}
&[readOnly] {
@include euiFormControlReadOnlyStyle;
}
// Needs to be set for autofill
// sass-lint:disable-block no-vendor-prefixes
&:-webkit-autofill {
-webkit-text-fill-color: lightOrDarkTheme($euiColorDarkestShade, $euiColorLightShade);
~ .euiFormControlLayoutIcons {
color: lightOrDarkTheme($euiColorDarkestShade, $euiColorLightShade);
}
}
}
@if ($includeSizes) {
&--compressed {
@include euiFormControlStyleCompressed($borderOnly, $includeStates);
}
&--inGroup {
// sass-lint:disable-block no-important
box-shadow: none !important;
border-radius: 0;
}
}
}
@mixin euiFormControlStyleCompressed($borderOnly: false, $includeStates: true) {
@include euiFormControlDefaultShadow($borderOnly: true);
padding: $euiFormControlCompressedPadding;
border-radius: $euiFormControlCompressedBorderRadius;
@if ($includeStates) {
&:invalid { // 2
@include euiFormControlInvalidStyle;
}
&:focus { // 2
@include euiFormControlFocusStyle($borderOnly: true);
}
&:disabled {
@include euiFormControlDisabledStyle;
}
&[readOnly] {
@include euiFormControlReadOnlyStyle;
}
}
}
// Custom styles and states for checkboxes and radios
@mixin euiCustomControl($type: null, $size: $euiSize) {
@include euiSlightShadow;
@if $size {
$size: $size - 2px; // subtract 2px from size to account for border size
padding: $size / 2;
}
border: 1px solid $euiFormCustomControlBorderColor;
background: $euiColorEmptyShade no-repeat center;
@if $type == 'round' {
border-radius: $size;
} @else if $type == 'square' {
border-radius: $euiBorderRadius;
}
// sass-lint:disable-block indentation
transition: background-color $euiAnimSpeedFast ease-in,
border-color $euiAnimSpeedFast ease-in;
}
@mixin euiCustomControlSelected($type: null) {
border-color: $euiColorPrimary;
background-color: $euiColorPrimary;
@if $type != null {
@include euiIconBackground($type, $euiColorEmptyShade);
}
}
@mixin euiCustomControlDisabled($type: null) {
border-color: $euiColorLightShade;
background-color: $euiColorLightShade;
box-shadow: none;
@if $type != null {
@include euiIconBackground($type, $euiFormCustomControlDisabledIconColor);
}
}
@mixin euiCustomControlFocused {
@include euiFocusRing;
border-color: $euiColorPrimary;
}
@mixin euiHiddenSelectableInput {
position: absolute;
// sass-lint:disable no-important
opacity: 0 !important; // Make sure it's still hidden when :disabled
width: 100%;
height: 100%;
cursor: pointer;
}