_custom-forms.scss 6.94 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
// scss-lint:disable PropertyCount

3
4
// Embedded icons from Open Iconic.
// Released under MIT and copyright 2014 Waybury.
5
// https://useiconic.com/open
6

Mark Otto's avatar
Mark Otto committed
7

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

Mark Otto's avatar
Mark Otto committed
12
.custom-control {
13
  position: relative;
14
  display: inline-block;
15
  min-height: (1rem * $line-height-base);
16
  padding-left: $custom-control-gutter;
17
  margin-right: $custom-control-spacer-x;
18
  cursor: pointer;
Mark Otto's avatar
Mark Otto committed
19
}
20

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

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

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

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

  &:disabled {
    ~ .custom-control-indicator {
45
46
      cursor: $custom-control-disabled-cursor;
      background-color: $custom-control-disabled-indicator-bg;
Mark Otto's avatar
Mark Otto committed
47
48
49
    }

    ~ .custom-control-description {
50
51
      color: $custom-control-disabled-description-color;
      cursor: $custom-control-disabled-cursor;
Mark Otto's avatar
Mark Otto committed
52
    }
53
  }
54
55
}

Mark Otto's avatar
Mark Otto committed
56
57
58
59
// Custom indicator
//
// Generates a shadow element to create our makeshift checkbox/radio background.

Mark Otto's avatar
Mark Otto committed
60
.custom-control-indicator {
61
  position: absolute;
62
  top: (($line-height-base - $custom-control-indicator-size) / 2);
63
64
  left: 0;
  display: block;
65
66
  width: $custom-control-indicator-size;
  height: $custom-control-indicator-size;
67
  pointer-events: none;
68
  user-select: none;
69
  background-color: $custom-control-indicator-bg;
70
71
  background-repeat: no-repeat;
  background-position: center center;
72
73
  background-size: $custom-control-indicator-bg-size;
  @include box-shadow($custom-control-indicator-box-shadow);
74
75
}

Mark Otto's avatar
Mark Otto committed
76
77
78
// Checkboxes
//
// Tweak just a few things for checkboxes.
79

Mark Otto's avatar
Mark Otto committed
80
81
.custom-checkbox {
  .custom-control-indicator {
82
    @include border-radius($custom-checkbox-radius);
83
  }
84

Mark Otto's avatar
Mark Otto committed
85
  .custom-control-input:checked ~ .custom-control-indicator {
86
    background-image: $custom-checkbox-checked-icon;
87
  }
Mark Otto's avatar
Mark Otto committed
88

Mark Otto's avatar
Mark Otto committed
89
  .custom-control-input:indeterminate ~ .custom-control-indicator {
90
    background-color: $custom-checkbox-indeterminate-bg;
91
    background-image: $custom-checkbox-indeterminate-icon;
92
    @include box-shadow($custom-checkbox-indeterminate-box-shadow);
Mark Otto's avatar
Mark Otto committed
93
  }
94
95
}

Mark Otto's avatar
Mark Otto committed
96
97
98
// Radios
//
// Tweak just a few things for radios.
99

Mark Otto's avatar
Mark Otto committed
100
101
.custom-radio {
  .custom-control-indicator {
102
    border-radius: $custom-radio-radius;
103
  }
104

Mark Otto's avatar
Mark Otto committed
105
  .custom-control-input:checked ~ .custom-control-indicator {
106
    background-image: $custom-radio-checked-icon;
107
  }
108
109
}

Mark Otto's avatar
Mark Otto committed
110

111
112
113
114
115
// Layout options
//
// By default radios and checkboxes are `inline-block` with no additional spacing
// set. Use these optional classes to tweak the layout.

Mark Otto's avatar
Mark Otto committed
116
117
.custom-controls-stacked {
  .custom-control {
118
119
    float: left;
    clear: left;
120

Mark Otto's avatar
Mark Otto committed
121
    + .custom-control {
122
123
124
      margin-left: 0;
    }
  }
125
126
}

Mark Otto's avatar
Mark Otto committed
127

128
129
// Select
//
130
131
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
Mark Otto's avatar
Mark Otto committed
132
//
133
134
// Includes hacks for IE9 (noted by ` \9`), which may apply to other versions of
// IE, but not with any adverse affects.
135

136
.custom-select {
137
  display: inline-block;
138
  max-width: 100%;
Mark Otto's avatar
Mark Otto committed
139
140
  $select-border-width: ($border-width * 2);
  height: calc(#{$input-height} - #{$select-border-width});
141
142
143
  padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding) $custom-select-padding-y $custom-select-padding-x;
  padding-right: $custom-select-padding-x \9;
  color: $custom-select-color;
Mark Otto's avatar
order    
Mark Otto committed
144
  vertical-align: middle;
145
  background: $custom-select-bg $custom-select-indicator no-repeat right $custom-select-padding-x center;
Mark Otto's avatar
Mark Otto committed
146
  background-image: none \9;
147
148
149
  background-size: $custom-select-bg-size;
  border: $custom-select-border-width solid $custom-select-border-color;
  @include border-radius($custom-select-border-radius);
Mark Otto's avatar
Mark Otto committed
150
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
151
  -moz-appearance: none;
Mark Otto's avatar
Mark Otto committed
152
  -webkit-appearance: none;
153
154

  &:focus {
155
    border-color: $custom-select-focus-border-color;
156
    outline: none;
157
    @include box-shadow($custom-select-focus-box-shadow);
158
159
160
161
162
163
164
165
166
167

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
      // supress the default white text on blue background highlight given to
      // 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;
    }
168
169
  }

170
171
172
173
174
175
  &:disabled {
    color: $custom-select-disabled-color;
    cursor: $cursor-disabled;
    background-color: $custom-select-disabled-bg;
  }

176
177
178
  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
179
180
  }
}
181

182
.custom-select-sm {
183
184
185
186
187
188
189
190
  padding-top: $custom-select-padding-y;
  padding-bottom: $custom-select-padding-y;
  font-size: $custom-select-sm-font-size;

  // &:not([multiple]) {
  //   height: 26px;
  //   min-height: 26px;
  // }
191
192
}

Mark Otto's avatar
Mark Otto committed
193

194
195
196
// File
//
// Custom file input.
197

198
.custom-file {
199
200
  position: relative;
  display: inline-block;
201
  max-width: 100%;
202
  height: $custom-file-height;
Catalin Zalog's avatar
Catalin Zalog committed
203
  margin-bottom: 0;
204
  cursor: pointer;
205
}
206
207

.custom-file-input {
208
  min-width: $custom-file-width;
209
  max-width: 100%;
210
  margin: 0;
XhmikosR's avatar
XhmikosR committed
211
  filter: alpha(opacity = 0);
212
  opacity: 0;
213
214

  &:focus ~ .custom-file-control {
215
    @include box-shadow($custom-file-focus-box-shadow);
216
  }
217
}
218
219

.custom-file-control {
220
221
222
223
224
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
225
226
227
228
  height: $custom-file-height;
  padding: $custom-file-padding-x $custom-file-padding-y;
  line-height: $custom-file-line-height;
  color: $custom-file-color;
229
  user-select: none;
230
231
  background-color: $custom-file-bg;
  border: $custom-file-border-width solid $custom-file-border-color;
Mark Otto's avatar
Mark Otto committed
232
  @include border-radius($custom-file-border-radius);
233
  @include box-shadow($custom-file-box-shadow);
234

235
236
237
238
  @each $lang, $text in map-get($custom-file-text, placeholder) {
    &:lang(#{$lang})::after {
      content: $text;
    }
239
240
241
242
  }

  &::before {
    position: absolute;
243
244
245
    top: -$custom-file-border-width;
    right: -$custom-file-border-width;
    bottom: -$custom-file-border-width;
246
247
    z-index: 6;
    display: block;
248
249
250
251
252
253
254
    height: $custom-file-height;
    padding: $custom-file-padding-x $custom-file-padding-y;
    line-height: $custom-file-line-height;
    color: $custom-file-button-color;
    background-color: $custom-file-button-bg;
    border: $custom-file-border-width solid $custom-file-border-color;
    @include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
255
  }
256
257
258
259
260
261

  @each $lang, $text in map-get($custom-file-text, button-label) {
    &:lang(#{$lang})::before {
      content: $text;
    }
  }
262
}