summaryrefslogtreecommitdiffstats
path: root/WebContent/VAADIN/themes/valo/components/_textfield.scss
blob: 50cb7b80420927dd3a732efd34b26e3d7480827d (plain)
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/**
 * The background color for text fields.
 * @group textfield
 */
$v-textfield-background-color: if(is-dark-color($v-app-background-color), darken($v-app-background-color, 4%), lighten($v-app-background-color, 8%)) !default;

/**
 * The background color for read-only text fields.
 * @group textfield
 */
$v-textfield-background-color--readonly: darkest-color($v-app-background-color, darken($v-textfield-background-color, 2%));

/**
 * The bevel style for text fields. See the documentation for $v-bevel.
 * @group textfield
 */
$v-textfield-bevel: if($v-bevel and ($v-bevel != none), inset 0 1px 0 v-shade, $v-bevel) !default;

/**
 * The shadow style for text fields. See the documentation for $v-shadow.
 * @group textfield
 */
$v-textfield-shadow: 0 1px 0 (v-tint 2) !default;

/**
 * The font-weight for text fields.
 * @group textfield
 */
$v-textfield-font-weight: 400 !default;

/**
 * The border style for text fields. See the documentation for $v-border.
 * @group textfield
 */
$v-textfield-border: $v-border !default;

/**
 * The border-radius for text fields. See the documentation for $v-border-radius;
 * @group textfield
 */
$v-textfield-border-radius: $v-border-radius !default;

/**
 * The opacity for disabled text fields.
 * @group textfield
 */
$v-textfield-disabled-opacity: $v-disabled-opacity !default;


/**
 * Outputs the selectors and properties for the TextField component.
 *
 * @param {string} $primary-stylename (v-textfield) - the primary style name for the selectors
 * @param {bool} $include-additional-styles - should the mixin output all the different style variations of the component
 *
 * @group textfield
 */
@mixin valo-textfield ($primary-stylename: v-textfield, $include-additional-styles: contains($v-included-additional-styles, textfield)) {

  .#{$primary-stylename} {
    @include valo-textfield-style;
    width: $v-default-field-width;
  }

  .#{$primary-stylename}-readonly {
    @include valo-textfield-readonly-style;
  }

  .#{$primary-stylename}-error {
    @include valo-textfield-error-style;
  }


  @if $include-additional-styles {
    .#{$primary-stylename}-borderless {
      @include valo-textfield-borderless-style;
    }

    .#{$primary-stylename}-tiny {
      @include valo-textfield-style($unit-size: $v-unit-size--tiny, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
      font-size: $v-font-size--tiny;
    }

    .#{$primary-stylename}-compact,
    .#{$primary-stylename}-small {
      @include valo-textfield-style($unit-size: $v-unit-size--small, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
    }

    .#{$primary-stylename}-small {
      font-size: $v-font-size--small;
    }

    .#{$primary-stylename}-large {
      @include valo-textfield-style($unit-size: $v-unit-size--large, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
      font-size: $v-font-size--large;
    }

    .#{$primary-stylename}-huge {
      @include valo-textfield-style($unit-size: $v-unit-size--huge, $states: normal, $background-color: null, $border: null, $gradient: null, $bevel: null, $shadow: null);
      font-size: $v-font-size--huge;
    }

    @include valo-textfield-inline-icon($stylenames: inline-icon);
    @include valo-textfield-inline-icon($stylenames: inline-icon tiny, $unit-size: $v-unit-size--tiny, $font-size: $v-font-size--tiny);
    @include valo-textfield-inline-icon($stylenames: inline-icon compact, $unit-size: $v-unit-size--small);
    @include valo-textfield-inline-icon($stylenames: inline-icon small, $unit-size: $v-unit-size--small, $font-size: $v-font-size--small);
    @include valo-textfield-inline-icon($stylenames: inline-icon large, $unit-size: $v-unit-size--large, $font-size: $v-font-size--large);
    @include valo-textfield-inline-icon($stylenames: inline-icon huge, $unit-size: $v-unit-size--huge, $font-size: $v-font-size--huge);

    .#{$primary-stylename}-align-right {
      text-align: right;
    }

    .#{$primary-stylename}-align-center {
      text-align: center;
    }
  }

}


/**
 * Outputs the styles for a text field variant.
 *
 * @param {size} $unit-size ($v-unit-size) - The sizing of the text field, which corresponds its height
 * @param {size | list} $padding (null) - The padding of the text field. Computed from other parameters by default.
 * @param {color} $font-color (null) - The font color of the text field. Computed from the $background-color by default.
 * @param {number} $font-weight (max(400, $v-font-weight)) - The font weight of the text field
 * @param {size} $font-size (null) - The font size of the text field. Inherited from the parent by default.
 * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
 * @param {list} $border ($v-textfield-border) - The border of the text field
 * @param {size} $border-radius ($v-textfield-border-radius) - The border-radius of the text field
 * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
 * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
 * @param {list} $states (normal focus disabled) - The text field states for which to output corresponding styles
 *
 * @group textfield
 */
@mixin valo-textfield-style (
    $unit-size        : $v-unit-size,
    $padding          : null,

    $font-color       : null,
    $font-weight      : max(400, $v-font-weight),
    $font-size        : null,

    $background-color : $v-textfield-background-color,
    $border           : $v-textfield-border,
    $border-radius    : $v-textfield-border-radius,

    $gradient         : none,
    $bevel            : $v-textfield-bevel,
    $shadow           : $v-textfield-shadow,

    $states           : (normal, focus, disabled)
  ) {

  @if contains($states, normal) {
    @include appearance(none);
    @include user-select(text);
    margin: 0;
    font: inherit;
    font-size: $font-size;
    font-weight: $font-weight;
    line-height: normal;
    height: $unit-size;
    border-radius: $border-radius;

    .v-ie8 &,
    .v-ie9 & {
      line-height: $unit-size;
      padding-top: 0;
      padding-bottom: 0;
    }

    @if type-of($padding) == number or type-of($padding) == list {
      padding: $padding;
    } @else {
      $padding-width: ceil($unit-size/6);
      @if $border-radius {
        $padding-width: $padding-width + ceil($border-radius/3);
      }
      $padding-height: round($unit-size/9);
      padding: $padding-height $padding-width;
    }

    @if $background-color and $border {
      border: valo-border($border, darkest-color($background-color, $v-app-background-color));
    }

    @if $gradient == none {
      background: $background-color;
    } @else if $gradient {
      @include valo-gradient($color: $background-color, $gradient: $gradient)
    }

    @if $background-color {
      color: valo-font-color($background-color);
    }

    @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient));

    @if $v-animations-enabled {
      @include transition(box-shadow 180ms, border 180ms);
    }
  }

  @if contains($states, disabled) {
    &.v-disabled {
      @include opacity($v-textfield-disabled-opacity);
    }
  }

  @if contains($states, focus) {
    &:focus {
      @include valo-textfield-focus-style($bevel: $bevel, $shadow: $shadow, $gradient: $gradient, $background-color: $background-color);
    }
  }

  // TODO allow parent selector to be used in interpolation
  &[class*="prompt"] {
    @include valo-textfield-prompt-style($background-color);
  }

}


/**
 * Outputs the styles for a text field input prompt.
 * 
 * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
 * 
 * @group textfield
 */
@mixin valo-textfield-prompt-style ($background-color: $v-textfield-background-color) {
  @if $background-color ==  transparent {
    color: inherit;
    @include opacity(.5);
  } @else if type-of($background-color) == color {
    $font-color: valo-font-color($background-color);
    $font-color: mix($background-color, $font-color);
    @if is-dark-color($background-color) and saturation($background-color) > 50% {
      $font-color: scale-color($font-color, $lightness: 20%);
    }
    $font-color: scale-color($font-color, $saturation: saturation($font-color));
    color: $font-color;
  }
}


/**
 * Outputs the styles for a text field focus state.
 * 
 * @param {list} $bevel ($v-textfield-bevel) - Box-shadow value according to $v-bevel documentation
 * @param {list} $shadow ($v-textfield-shadow) - Box-shadow value according to $v-shadow documentation
 * @param {color} $background-color ($v-textfield-background-color) - The background color of the text field
 * @param {list} $gradient (null) - Valo specific gradient value. See the documentation for $v-gradient.
 * 
 * @group textfield
 */
@mixin valo-textfield-focus-style ($bevel: $v-textfield-bevel, $shadow: $v-textfield-shadow, $background-color: $v-textfield-background-color, $gradient: null) {
  outline: none;
  @if $v-animations-enabled {
    @include transition(none);
  }

  $focus-color: $v-focus-color;

  @if color-luminance($focus-color) + 50 < color-luminance($v-background-color) {
    border-color: $focus-color;
  }

  @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient, $include-focus: true));

  @include valo-focus-style;
}


/**
 * Outputs the styles for a read-only text field.
 * 
 * @group textfield
 */
@mixin valo-textfield-readonly-style {
  background: $v-textfield-background-color--readonly;
  color: valo-font-color($v-textfield-background-color--readonly);
  @include box-shadow(none);
  &:focus {
    box-shadow: none;
    border-color: first-color(valo-border($v-textfield-border, $v-textfield-background-color--readonly));
  }
}


/**
 * Outputs the styles for a borderless style text field.
 * 
 * @param {color} $background-color (transparent) - The background color of the text field
 * 
 * @group textfield
 */
@mixin valo-textfield-borderless-style ($background-color: transparent) {
  border: none;
  border-radius: 0;
  background: $background-color;
  @include box-shadow(none);

  $font-color: inherit;
  @if $background-color != transparent and type-of($background-color) == color {
    $font-color: valo-font-color($background-color);
  }
  color: $font-color;

  &:focus {
    @include box-shadow(none);
  }

  &[class*="prompt"] {
    @include valo-textfield-prompt-style($background-color);
  }
}


/**
 * Outputs the styles for a text field error state.
 * 
 * @group textfield
 */
@mixin valo-textfield-error-style {
  border-color: $v-error-indicator-color !important;
  $bg: scale-color($v-error-indicator-color, $lightness: 98%);
  background: $bg;
  color: valo-font-color($bg);
}


/**
 * Outputs the selectors and styles for an inline-icon style for a text field. Included indipendently (i.e. not enclosed with a parent text field selector). 
 * 
 * @param {string} $primary-stylename (v-textfield) - The primary style name for the selectors
 * @param {string | list} $stylenames (inline-icon) - The additional style names which will define the inline-icon style
 * @param {string} $input-selector (null) - Additional selector for a nested input element which should be targeted
 * @param {size} $unit-size ($v-unit-size) - The unit size which the resulting style will support
 * @param {size} $font-size ($v-font-size) - The font size which the resulting style will support (needed for font icons)
 * @param {size} $image-icon-size (16px) - The image icon height which the resulting style will support (needed to center the icon vertically inside the text field)
 * 
 * @group text field
 */
@mixin valo-textfield-inline-icon($primary-stylename: v-textfield, $stylenames: inline-icon, $input-selector: null, $unit-size: $v-unit-size, $font-size: $v-font-size, $image-icon-size: 16px) {
  $slot-selector: "";
  $caption-selector: "";
  $text-input-selector: "";

  @each $style in $stylenames {
    $slot-selector: $slot-selector + ".v-slot-" + $style;
    $caption-selector: $caption-selector + ".v-caption-" + $style;
    $text-input-selector: $text-input-selector + "." + $primary-stylename + "-" + $style;
  }

  #{$slot-selector} {
    position: relative;
  }

  #{$caption-selector} {
    padding: 0;

    .v-captiontext {
      // Need to include to get the default padding back
      @include valo-caption-style;
      margin: 0;
    }

    .v-icon {
      position: absolute;
      z-index: 10;
    }

    // Font icons
    span.v-icon {
      $border-width: first-number($v-textfield-border);
      left: $border-width;
      bottom: $border-width;
      width: $unit-size;
      line-height: $unit-size - $border-width*2;
      text-align: center;
      font-size: $font-size;
    }

    // Image icons
    img.v-icon {
      left: round(($unit-size - $image-icon-size)/2);
      bottom: round(($unit-size - $image-icon-size)/2);
    }
  }

  #{$text-input-selector} #{$input-selector} {
    padding-left: $unit-size;
  }
}