_custom-forms.scss 6.73 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-flex;
15
  min-height: (1rem * $line-height-base);
16
  padding-left: $custom-control-gutter;
17
  margin-right: $custom-control-spacer-x;
Mark Otto's avatar
Mark Otto committed
18
}
19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
109

110
111
112
113
114
// 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
115
.custom-controls-stacked {
116
117
118
  display: flex;
  flex-direction: column;

Mark Otto's avatar
Mark Otto committed
119
  .custom-control {
120
    margin-bottom: $custom-control-spacer-y;
121

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

Mark Otto's avatar
Mark Otto committed
128

129
130
// Select
//
131
132
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
Mark Otto's avatar
Mark Otto committed
133
//
134

135
.custom-select {
136
  display: inline-block;
137
  max-width: 100%;
Mark Otto's avatar
Mark Otto committed
138
  $select-border-width: ($border-width * 2);
139
  height: calc(#{$input-height} + #{$select-border-width});
140
  padding: $custom-select-padding-y ($custom-select-padding-x + $custom-select-indicator-padding) $custom-select-padding-y $custom-select-padding-x;
141
  line-height: $custom-select-line-height;
142
  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;
145
146
147
  background-size: $custom-select-bg-size;
  border: $custom-select-border-width solid $custom-select-border-color;
  @include border-radius($custom-select-border-radius);
148
  appearance: none;
149
150

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

    &::-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;
    }
164
165
  }

166
167
168
169
170
171
  &:disabled {
    color: $custom-select-disabled-color;
    cursor: $cursor-disabled;
    background-color: $custom-select-disabled-bg;
  }

172
173
174
  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
175
176
  }
}
177

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

Mark Otto's avatar
Mark Otto committed
189

190
191
192
// File
//
// Custom file input.
193

194
.custom-file {
195
196
  position: relative;
  display: inline-block;
197
  max-width: 100%;
198
  height: $custom-file-height;
Catalin Zalog's avatar
Catalin Zalog committed
199
  margin-bottom: 0;
200
}
201
202

.custom-file-input {
203
  min-width: $custom-file-width;
204
  max-width: 100%;
205
  height: $custom-file-height;
206
207
  margin: 0;
  opacity: 0;
208
209

  &:focus ~ .custom-file-control {
210
    @include box-shadow($custom-file-focus-box-shadow);
211
  }
212
}
213
214

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

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

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

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