summaryrefslogtreecommitdiffstats
path: root/WebContent/VAADIN/themes/valo/components/_button.scss
blob: 42953ea610dd3686cd3b25963b6cf9b708a2ea61 (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
@mixin valo-button ($primary-stylename: v-button, $include-additional-styles: contains($v-included-additional-styles, button)) {
  .#{$primary-stylename} {
    @include valo-button-static-style;
    @include valo-button-style;
  }


  @if $include-additional-styles {
    .#{$primary-stylename}-primary {
      @include valo-button-style($background-color: $v-selection-color);
      $padding-width: round($v-unit-size/2);
      padding: 0 $padding-width;
      font-weight: bold;
      $min-width: round($v-unit-size * 2.2);
      min-width: $min-width;

      // IE8 + border-box + min-width == fail
      .v-ie8 & {
        min-width: $min-width - ($padding-width * 2);
      }
    }

    .#{$primary-stylename}-friendly {
      @include valo-button-style($background-color: $v-friendly-color);
    }

    .#{$primary-stylename}-danger {
      @include valo-button-style($background-color: $v-error-indicator-color);
    }

    .#{$primary-stylename}-borderless {
      @include valo-button-borderless-style;
    }

    .#{$primary-stylename}-borderless-colored {
      @include valo-button-borderless-style($font-color: $v-selection-color);
    }

    .#{$primary-stylename}-quiet {
      @include valo-button-quiet-style;
    }

    .#{$primary-stylename}-link {
      @include valo-button-borderless-style;
      @include valo-link-style;
    }

    .#{$primary-stylename}-tiny {
      @include valo-button-style($unit-size: $v-unit-size--tiny, $bevel: null, $shadow: null, $background-color: null, $font-size: $v-font-size--tiny, $font-weight: null);
    }

    .#{$primary-stylename}-small {
      @include valo-button-style($unit-size: $v-unit-size--small, $bevel: null, $shadow: null, $background-color: null, $font-size: $v-font-size--small, $font-weight: null);
    }

    .#{$primary-stylename}-large {
      @include valo-button-style($unit-size: $v-unit-size--large, $bevel: null, $shadow: null, $background-color: null, $font-size: $v-font-size--large, $font-weight: null);
    }

    .#{$primary-stylename}-huge {
      @include valo-button-style($unit-size: $v-unit-size--huge, $bevel: null, $shadow: null, $background-color: null, $font-size: $v-font-size--huge, $font-weight: null);
    }

    .#{$primary-stylename}-icon-align-right {
      @include valo-button-icon-align-right-style;
    }

    .#{$primary-stylename}-icon-align-top {
      @include valo-button-icon-align-top-style;
    }

    .#{$primary-stylename}-icon-only {
      width: $v-unit-size;
      padding: 0;

      &.#{$primary-stylename}-tiny {
        width: $v-unit-size--tiny;
      }

      &.#{$primary-stylename}-small {
        width: $v-unit-size--small;
      }

      &.#{$primary-stylename}-large {
        width: $v-unit-size--large;
      }

      &.#{$primary-stylename}-huge {
        width: $v-unit-size--huge;
      }

      .#{$primary-stylename}-caption {
        display: none;
      }
    }
  }
}





@mixin valo-button-static-style ($states: (normal, hover, focus, active, disabled), $vertical-centering: true) {
  @if contains($states, normal) {
    position: relative;
    text-align: center;
    white-space: nowrap;
    outline: none;
    @include valo-tappable;
    @if $vertical-centering {
      @include valo-button-vertical-centering;
    }
  }

  @if contains($states, hover) or contains($states, focus) or contains($states, active) {
    // Generated element for :hover, :focus and :active styles
    &:after {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      border-radius: inherit;
      @if $v-animations-enabled {
        @include transition(box-shadow 180ms, border 180ms);
      }
    }
  }

  @if contains($states, focus) {
    &:focus:after {
      @if $v-animations-enabled {
        @include transition(none);
      }
    }
  }

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

      &:after {
        display: none;
      }
    }
  }
}





@mixin valo-button-style (
  $unit-size        : $v-unit-size,
  $padding          : null, // Computed by default

  $font-color       : null, // Computed by default
  $font-weight      : $v-font-weight + 100,
  $font-size        : null, // Inherited by default
  $cursor           : null,

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

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

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

  @if contains($states, focus) or contains($states, active) {
    $border-width: first-number($border);
    &:after {
      border: inherit;
      top: -$border-width;
      right: -$border-width;
      bottom: -$border-width;
      left: -$border-width;
    }
  }

  @if contains($states, normal) {
    @if $unit-size {
      height: $unit-size;
      @if type-of($padding) == number or type-of($padding) == list {
        padding: $padding;
      } @else {
        padding: 0 round($unit-size/2.4) + round($border-radius/3);
      }
    }

    $_font-color: $font-color or valo-font-color($background-color, 0.9);
    color: $_font-color;
    font-weight: $font-weight;
    font-size: $font-size;
    cursor: $cursor;

    border-radius: $border-radius;

    @if type-of($background-color) == color {
      @include valo-border-with-gradient($border: $border, $color: darkest-color($background-color, $v-background-color), $gradient: $gradient);
      @include valo-gradient($background-color, $gradient);
      @include box-shadow(valo-bevel-and-shadow($bevel: $bevel, $shadow: $shadow, $background-color: $background-color, $gradient: $gradient));
    }

    @if $bevel and type-of($_font-color) == color and type-of($background-color) == color {
      text-shadow: valo-text-shadow($_font-color, $background-color, $bevel);
    }

    @if $bevel == none and $shadow == none {
      @include box-shadow(none);
    }
  }

  @if $background-color {
    @if contains($states, hover) {
      &:hover:after {
        @include valo-button-hover-style($background-color);
      }
    }

    @if contains($states, focus) {
      &:focus:after {
        @include valo-button-focus-style($background-color);
      }
    }

    @if contains($states, active) {
      &:active:after {
        @include valo-button-active-style($background-color);
      }
    }
  }
}




@mixin valo-button-hover-style ($background-color: $v-background-color) {
  $bg: darken($background-color, 25%);
  @if is-dark-color($background-color) {
    $bg: lighten($background-color, 15%);
  }
  background-color: rgba($bg, .1);
}



@mixin valo-button-focus-style ($background-color: $v-background-color, $border-fallback: inherit, $include-box-shadow: true) {
  $focus-color: $v-focus-color;

  @if color-luminance($focus-color) + 50 < color-luminance($background-color) {
    border-color: $focus-color;
  } @else if $border-fallback != none {
    border: $border-fallback or valo-border($color: $background-color);
  }

  @include valo-focus-style($include-box-shadow: $include-box-shadow);
}



@mixin valo-button-active-style ($background-color: $v-background-color) {
  $bg: scale-color($background-color, $lightness: -50%, $saturation: saturation($background-color));
  background-color: rgba($bg, .2);
}





@mixin valo-button-vertical-centering {
  // Vertical centering of icon and caption, independent of the height of the button
  @include valo-vertical-align-guide($to-align: div, $pseudo-element: before);

  // WebKit handles line-heights and vertical-alignments somewhat differently, so we need to adjust
  .v-sa &:before {
    height: 110%;
  }

  // Firefox needs a bit of adjusting as well
  .v-ff &:before {
    height: 107%;
  }

  // ...and so does IE. Who knew?
  .v-ie &:before {
    margin-top: 4px;
  }
}




@mixin valo-button-borderless-style ($font-color: inherit) {
  border: none;
  @include box-shadow(none);
  background: transparent;
  color: $font-color;

  &:hover {
    &:after {
      background: transparent;
    }

    @if type-of($font-color) == color {
      color: lighten($font-color, 10%);
    }
  }

  &:active {
    @include opacity(.7);

    &:after {
      background: transparent;
    }
  }
}


@mixin valo-button-quiet-style ($primary-stylename: v-button) {
  visibility: hidden;

  &:focus,
  &:hover {
    visibility: visible;
  }

  .#{$primary-stylename}-wrap {
    visibility: visible;
  }

  .#{$primary-stylename}-caption {
    // For IE8
    display: inline-block;
  }
}


@mixin valo-button-icon-align-right-style ($primary-stylename: v-button) {
  .#{$primary-stylename}-wrap {
    display: inline-block;
  }

  .v-icon {
    float: right;
    $padding-width: ceil($v-unit-size/2.4);
    margin-left: $padding-width + ceil($padding-width/-5);

    + span:not(:empty) {
      margin-left: 0;
    }
  }
}


@mixin valo-button-icon-align-top-style ($primary-stylename: v-button) {
  height: auto;
  padding-top: ceil($v-unit-size/9);
  padding-bottom: ceil($v-unit-size/9);

  .#{$primary-stylename}-wrap {
    display: inline-block;
  }

  .v-icon {
    display: block;

    + span:not(:empty) {
      margin-top: ceil($v-unit-size/6);
      margin-left: 0;
    }
  }
}