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

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

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
  padding-left: $custom-control-gutter;
16
  cursor: pointer;
17

Mark Otto's avatar
Mark Otto committed
18
  + .custom-control {
19
    margin-left: $custom-control-spacer-x;
Mark Otto's avatar
Mark Otto committed
20
21
  }
}
22

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

Mark Otto's avatar
Mark Otto committed
28
  &:checked ~ .custom-control-indicator {
29
30
31
    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
32
  }
33

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

Mark Otto's avatar
Mark Otto committed
39
  &:active ~ .custom-control-indicator {
40
41
42
    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
43
44
45
46
  }

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

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
112

113
114
115
116
117
// 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
118
119
.custom-controls-stacked {
  .custom-control {
120
121
    float: left;
    clear: left;
122

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

Mark Otto's avatar
Mark Otto committed
129

130
131
// Select
//
132
133
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
Mark Otto's avatar
Mark Otto committed
134
135
//
// Includes IE9-specific hacks (noted by ` \9`).
136

137
.custom-select {
138
  display: inline-block;
139
  max-width: 100%;
140
141
142
  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
143
  vertical-align: middle;
144
  background: $custom-select-bg $custom-select-indicator no-repeat right $custom-select-padding-x center;
Mark Otto's avatar
Mark Otto committed
145
  background-image: none \9;
146
147
148
  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
149
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
150
  -moz-appearance: none;
Mark Otto's avatar
Mark Otto committed
151
  -webkit-appearance: none;
152
153

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

    &::-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;
    }
167
168
  }

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

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

181
.custom-select-sm {
182
183
184
185
186
187
188
189
  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;
  // }
190
191
}

Mark Otto's avatar
Mark Otto committed
192

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

197
.custom-file {
198
199
  position: relative;
  display: inline-block;
200
  max-width: 100%;
201
  height: $custom-file-height;
202
  cursor: pointer;
203
}
204
205

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

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

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

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

  &::before {
    position: absolute;
241
242
243
    top: -$custom-file-border-width;
    right: -$custom-file-border-width;
    bottom: -$custom-file-border-width;
244
245
    z-index: 6;
    display: block;
246
247
248
249
250
251
252
    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);
253
  }
254
255
256
257
258
259

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