_custom-forms.scss 12.4 KB
Newer Older
1
2
// Embedded icons from Open Iconic.
// Released under MIT and copyright 2014 Waybury.
3
// https://useiconic.com/open
4

Mark Otto's avatar
Mark Otto committed
5

6
// Checkboxes and radios
Mark Otto's avatar
Mark Otto committed
7
8
9
//
// Base class takes care of all the key behavioral aspects.

Mark Otto's avatar
Mark Otto committed
10
.custom-control {
11
  position: relative;
Mark Otto's avatar
Mark Otto committed
12
  display: block;
13
  min-height: ($font-size-base * $line-height-base);
14
  padding-left: $custom-control-gutter;
Mark Otto's avatar
Mark Otto committed
15
16
17
18
}

.custom-control-inline {
  display: inline-flex;
19
  margin-right: $custom-control-spacer-x;
Mark Otto's avatar
Mark Otto committed
20
}
21

Mark Otto's avatar
Mark Otto committed
22
23
24
25
.custom-control-input {
  position: absolute;
  z-index: -1; // Put the input behind the label so it doesn't overlay text
  opacity: 0;
26

Mark Otto's avatar
Mark Otto committed
27
  &:checked ~ .custom-control-label::before {
28
    color: $custom-control-indicator-checked-color;
Mark Otto's avatar
Mark Otto committed
29
    @include gradient-bg($custom-control-indicator-checked-bg);
30
    @include box-shadow($custom-control-indicator-checked-box-shadow);
Mark Otto's avatar
Mark Otto committed
31
  }
32

Mark Otto's avatar
Mark Otto committed
33
  &:focus ~ .custom-control-label::before {
Mark Otto's avatar
Mark Otto committed
34
    // the mixin is not used here to make sure there is feedback
35
    box-shadow: $custom-control-indicator-focus-box-shadow;
36
37
  }

Mark Otto's avatar
Mark Otto committed
38
  &:active ~ .custom-control-label::before {
39
    color: $custom-control-indicator-active-color;
40
    background-color: $custom-control-indicator-active-bg;
41
    @include box-shadow($custom-control-indicator-active-box-shadow);
Mark Otto's avatar
Mark Otto committed
42
43
44
  }

  &:disabled {
Mark Otto's avatar
Mark Otto committed
45
46
    ~ .custom-control-label {
      color: $custom-control-label-disabled-color;
Mark Otto's avatar
Mark Otto committed
47

Mark Otto's avatar
Mark Otto committed
48
49
50
      &::before {
        background-color: $custom-control-indicator-disabled-bg;
      }
Mark Otto's avatar
Mark Otto committed
51
    }
52
  }
53
54
}

Mark Otto's avatar
Mark Otto committed
55
// Custom control indicators
Mark Otto's avatar
Mark Otto committed
56
//
57
// Build the custom controls out of pseudo-elements.
Mark Otto's avatar
Mark Otto committed
58

Mark Otto's avatar
Mark Otto committed
59
.custom-control-label {
60
  position: relative;
Mark Otto's avatar
Mark Otto committed
61
  margin-bottom: 0;
62

Mark Otto's avatar
Mark Otto committed
63
  // Background-color and (when enabled) gradient
64
  &::before {
Mark Otto's avatar
Mark Otto committed
65
    position: absolute;
66
    top: (($font-size-base * $line-height-base - $custom-control-indicator-size) / 2);
67
    left: -$custom-control-gutter;
Mark Otto's avatar
Mark Otto committed
68
69
70
71
72
73
74
75
76
77
78
79
80
    display: block;
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    pointer-events: none;
    content: "";
    user-select: none;
    background-color: $custom-control-indicator-bg;
    @include box-shadow($custom-control-indicator-box-shadow);
  }

  // Foreground (icon)
  &::after {
    position: absolute;
81
    top: (($font-size-base * $line-height-base - $custom-control-indicator-size) / 2);
82
    left: -$custom-control-gutter;
83
84
85
86
87
88
89
90
    display: block;
    width: $custom-control-indicator-size;
    height: $custom-control-indicator-size;
    content: "";
    background-repeat: no-repeat;
    background-position: center center;
    background-size: $custom-control-indicator-bg-size;
  }
91
92
}

Mark Otto's avatar
Mark Otto committed
93

Mark Otto's avatar
Mark Otto committed
94
95
96
// Checkboxes
//
// Tweak just a few things for checkboxes.
97

Mark Otto's avatar
Mark Otto committed
98
.custom-checkbox {
Mark Otto's avatar
Mark Otto committed
99
  .custom-control-label::before {
100
    @include border-radius($custom-checkbox-indicator-border-radius);
101
  }
102

Mark Otto's avatar
Mark Otto committed
103
  .custom-control-input:checked ~ .custom-control-label {
104
    &::before {
Mark Otto's avatar
Mark Otto committed
105
106
107
      @include gradient-bg($custom-control-indicator-checked-bg);
    }
    &::after {
108
109
      background-image: $custom-checkbox-indicator-icon-checked;
    }
110
  }
Mark Otto's avatar
Mark Otto committed
111

Mark Otto's avatar
Mark Otto committed
112
  .custom-control-input:indeterminate ~ .custom-control-label {
113
    &::before {
Mark Otto's avatar
Mark Otto committed
114
115
116
117
      @include gradient-bg($custom-checkbox-indicator-indeterminate-bg);
      @include box-shadow($custom-checkbox-indicator-indeterminate-box-shadow);
    }
    &::after {
118
119
      background-image: $custom-checkbox-indicator-icon-indeterminate;
    }
Mark Otto's avatar
Mark Otto committed
120
  }
121
122
123
124
125
126
127
128
129

  .custom-control-input:disabled {
    &:checked ~ .custom-control-label::before {
      background-color: $custom-control-indicator-checked-disabled-bg;
    }
    &:indeterminate ~ .custom-control-label::before {
      background-color: $custom-control-indicator-checked-disabled-bg;
    }
  }
130
131
}

Mark Otto's avatar
Mark Otto committed
132
133
134
// Radios
//
// Tweak just a few things for radios.
135

Mark Otto's avatar
Mark Otto committed
136
.custom-radio {
Mark Otto's avatar
Mark Otto committed
137
  .custom-control-label::before {
138
    border-radius: $custom-radio-indicator-border-radius;
139
  }
140

Mark Otto's avatar
Mark Otto committed
141
  .custom-control-input:checked ~ .custom-control-label {
142
    &::before {
Mark Otto's avatar
Mark Otto committed
143
      @include gradient-bg($custom-control-indicator-checked-bg);
144
    }
Mark Otto's avatar
Mark Otto committed
145
146
    &::after {
      background-image: $custom-radio-indicator-icon-checked;
147
148
    }
  }
149
150
151
152
153
154

  .custom-control-input:disabled {
    &:checked ~ .custom-control-label::before {
      background-color: $custom-control-indicator-checked-disabled-bg;
    }
  }
155
156
}

Mark Otto's avatar
Mark Otto committed
157

158
159
// Select
//
160
// Replaces the browser default select with a custom one, mostly pulled from
XhmikosR's avatar
XhmikosR committed
161
// https://primer.github.io/.
Mark Otto's avatar
Mark Otto committed
162
//
163

164
.custom-select {
165
  display: inline-block;
166
  width: 100%;
167
  height: $custom-select-height;
168
  padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding) $custom-select-padding-y $custom-select-padding-x;
169
  line-height: $custom-select-line-height;
170
  color: $custom-select-color;
Mark Otto's avatar
order    
Mark Otto committed
171
  vertical-align: middle;
172
173
  background: $custom-select-background;
  background-color: $custom-select-bg;
174
  border: $custom-select-border-width solid $custom-select-border-color;
175
176
177
178
179
  @if $enable-rounded {
    border-radius: $custom-select-border-radius;
  } @else {
    border-radius: 0;
  }
180
  @include box-shadow($custom-select-box-shadow);
181
  appearance: none;
182
183

  &:focus {
184
    border-color: $custom-select-focus-border-color;
185
    outline: 0;
186
187
188
189
190
    @if $enable-shadows {
      box-shadow: $custom-select-box-shadow, $custom-select-focus-box-shadow;
    } @else {
      box-shadow: $custom-select-focus-box-shadow;
    }
191
192
193

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
194
      // suppress the default white text on blue background highlight given to
195
196
197
198
199
200
      // the selected option text when the (still closed) <select> receives focus
      // in IE and (under certain conditions) Edge.
      // See https://github.com/twbs/bootstrap/issues/19398.
      color: $input-color;
      background-color: $input-bg;
    }
201
202
  }

Mark Otto's avatar
Mark Otto committed
203
204
  &[multiple],
  &[size]:not([size="1"]) {
205
    height: auto;
Mark Otto's avatar
Mark Otto committed
206
    padding-right: $custom-select-padding-x;
207
208
209
    background-image: none;
  }

210
211
212
213
214
  &:disabled {
    color: $custom-select-disabled-color;
    background-color: $custom-select-disabled-bg;
  }

215
216
217
  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
218
219
  }
}
220

221
.custom-select-sm {
222
  height: $custom-select-height-sm;
223
224
225
  padding-top: $custom-select-padding-y-sm;
  padding-bottom: $custom-select-padding-y-sm;
  padding-left: $custom-select-padding-x-sm;
226
  font-size: $custom-select-font-size-sm;
227
228
}

Mark Otto's avatar
Mark Otto committed
229
230
.custom-select-lg {
  height: $custom-select-height-lg;
231
232
233
  padding-top: $custom-select-padding-y-lg;
  padding-bottom: $custom-select-padding-y-lg;
  padding-left: $custom-select-padding-x-lg;
Mark Otto's avatar
Mark Otto committed
234
235
236
  font-size: $custom-select-font-size-lg;
}

Mark Otto's avatar
Mark Otto committed
237

238
239
240
// File
//
// Custom file input.
241

242
.custom-file {
243
244
  position: relative;
  display: inline-block;
245
  width: 100%;
246
  height: $custom-file-height;
Catalin Zalog's avatar
Catalin Zalog committed
247
  margin-bottom: 0;
248
}
249
250

.custom-file-input {
Mark Otto's avatar
Mark Otto committed
251
252
253
  position: relative;
  z-index: 2;
  width: 100%;
254
  height: $custom-file-height;
255
256
  margin: 0;
  opacity: 0;
257

258
  &:focus ~ .custom-file-label {
Mark Otto's avatar
Mark Otto committed
259
    border-color: $custom-file-focus-border-color;
260
    box-shadow: $custom-file-focus-box-shadow;
261
  }
Mark Otto's avatar
Mark Otto committed
262

263
264
265
266
  &:disabled ~ .custom-file-label {
    background-color: $custom-file-disabled-bg;
  }

Mark Otto's avatar
Mark Otto committed
267
268
269
270
271
  @each $lang, $value in $custom-file-text {
    &:lang(#{$lang}) ~ .custom-file-label::after {
      content: $value;
    }
  }
272
}
273

Mark Otto's avatar
Mark Otto committed
274
.custom-file-label {
275
276
277
278
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
Mark Otto's avatar
Mark Otto committed
279
  z-index: 1;
280
  height: $custom-file-height;
281
  padding: $custom-file-padding-y $custom-file-padding-x;
282
283
284
285
  line-height: $custom-file-line-height;
  color: $custom-file-color;
  background-color: $custom-file-bg;
  border: $custom-file-border-width solid $custom-file-border-color;
Mark Otto's avatar
Mark Otto committed
286
  @include border-radius($custom-file-border-radius);
287
  @include box-shadow($custom-file-box-shadow);
288

Mark Otto's avatar
Mark Otto committed
289
  &::after {
290
    position: absolute;
Mark Otto's avatar
Mark Otto committed
291
292
293
294
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
295
    display: block;
296
    height: $custom-file-height-inner;
297
    padding: $custom-file-padding-y $custom-file-padding-x;
298
299
    line-height: $custom-file-line-height;
    color: $custom-file-button-color;
Mark Otto's avatar
Mark Otto committed
300
    content: "Browse";
Mark Otto's avatar
Mark Otto committed
301
    @include gradient-bg($custom-file-button-bg);
302
    border-left: inherit;
303
    @include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
304
  }
305
}
Mark Otto's avatar
Mark Otto committed
306
307
308

// Range
//
309
// Style range inputs the same across browsers. Vendor-specific rules for pseudo
Mark Otto's avatar
Mark Otto committed
310
311
312
313
314
// elements cannot be mixed. As such, there are no shared styles for focus or
// active states on prefixed selectors.

.custom-range {
  width: 100%;
ysds's avatar
ysds committed
315
316
  height: calc(#{$custom-range-thumb-height} + #{$custom-range-thumb-focus-box-shadow-width * 2});
  padding: 0; // Need to reset padding
Mark Otto's avatar
Mark Otto committed
317
318
319
320
321
  background-color: transparent;
  appearance: none;

  &:focus {
    outline: none;
ysds's avatar
ysds committed
322
323
324
325
326
327

    // Pseudo-elements must be split across multiple rulesets to have an affect.
    // No box-shadow() mixin for focus accessibility.
    &::-webkit-slider-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
    &::-moz-range-thumb     { box-shadow: $custom-range-thumb-focus-box-shadow; }
    &::-ms-thumb            { box-shadow: $custom-range-thumb-focus-box-shadow; }
Mark Otto's avatar
Mark Otto committed
328
329
330
331
332
333
334
335
336
  }

  &::-moz-focus-outer {
    border: 0;
  }

  &::-webkit-slider-thumb {
    width: $custom-range-thumb-width;
    height: $custom-range-thumb-height;
ysds's avatar
ysds committed
337
    margin-top: (($custom-range-track-height - $custom-range-thumb-height) / 2); // Webkit specific
Mark Otto's avatar
Mark Otto committed
338
339
340
341
    @include gradient-bg($custom-range-thumb-bg);
    border: $custom-range-thumb-border;
    @include border-radius($custom-range-thumb-border-radius);
    @include box-shadow($custom-range-thumb-box-shadow);
Martijn Cuppens's avatar
Martijn Cuppens committed
342
    @include transition($custom-forms-transition);
Mark Otto's avatar
Mark Otto committed
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
    appearance: none;

    &:active {
      @include gradient-bg($custom-range-thumb-active-bg);
    }
  }

  &::-webkit-slider-runnable-track {
    width: $custom-range-track-width;
    height: $custom-range-track-height;
    color: transparent; // Why?
    cursor: $custom-range-track-cursor;
    background-color: $custom-range-track-bg;
    border-color: transparent;
    @include border-radius($custom-range-track-border-radius);
    @include box-shadow($custom-range-track-box-shadow);
  }

  &::-moz-range-thumb {
    width: $custom-range-thumb-width;
    height: $custom-range-thumb-height;
    @include gradient-bg($custom-range-thumb-bg);
    border: $custom-range-thumb-border;
    @include border-radius($custom-range-thumb-border-radius);
    @include box-shadow($custom-range-thumb-box-shadow);
Martijn Cuppens's avatar
Martijn Cuppens committed
368
    @include transition($custom-forms-transition);
Mark Otto's avatar
Mark Otto committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
    appearance: none;

    &:active {
      @include gradient-bg($custom-range-thumb-active-bg);
    }
  }

  &::-moz-range-track {
    width: $custom-range-track-width;
    height: $custom-range-track-height;
    color: transparent;
    cursor: $custom-range-track-cursor;
    background-color: $custom-range-track-bg;
    border-color: transparent; // Firefox specific?
    @include border-radius($custom-range-track-border-radius);
    @include box-shadow($custom-range-track-box-shadow);
  }

  &::-ms-thumb {
    width: $custom-range-thumb-width;
    height: $custom-range-thumb-height;
ysds's avatar
ysds committed
390
391
392
    margin-top: 0; // Edge specific
    margin-right: $custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
    margin-left: $custom-range-thumb-focus-box-shadow-width;  // Workaround that overflowed box-shadow is hidden.
Mark Otto's avatar
Mark Otto committed
393
394
395
396
    @include gradient-bg($custom-range-thumb-bg);
    border: $custom-range-thumb-border;
    @include border-radius($custom-range-thumb-border-radius);
    @include box-shadow($custom-range-thumb-box-shadow);
Martijn Cuppens's avatar
Martijn Cuppens committed
397
    @include transition($custom-forms-transition);
Mark Otto's avatar
Mark Otto committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
    appearance: none;

    &:active {
      @include gradient-bg($custom-range-thumb-active-bg);
    }
  }

  &::-ms-track {
    width: $custom-range-track-width;
    height: $custom-range-track-height;
    color: transparent;
    cursor: $custom-range-track-cursor;
    background-color: transparent;
    border-color: transparent;
    border-width: ($custom-range-thumb-height * .5);
    @include box-shadow($custom-range-track-box-shadow);
  }

  &::-ms-fill-lower {
    background-color: $custom-range-track-bg;
    @include border-radius($custom-range-track-border-radius);
  }

  &::-ms-fill-upper {
    margin-right: 15px; // arbitrary?
    background-color: $custom-range-track-bg;
    @include border-radius($custom-range-track-border-radius);
  }
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

  &:disabled {
    &::-webkit-slider-thumb {
      background-color: $custom-range-thumb-disabled-bg;
    }

    &::-webkit-slider-runnable-track {
      cursor: default;
    }

    &::-moz-range-thumb {
      background-color: $custom-range-thumb-disabled-bg;
    }

    &::-moz-range-track {
      cursor: default;
    }

    &::-ms-thumb {
      background-color: $custom-range-thumb-disabled-bg;
    }
  }
Mark Otto's avatar
Mark Otto committed
448
}
Martijn Cuppens's avatar
Martijn Cuppens committed
449
450
451
452
453
454

.custom-control-label::before,
.custom-file-label,
.custom-select {
  @include transition($custom-forms-transition);
}