_custom-forms.scss 6.07 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
14
  position: relative;
  display: inline;
15
  padding-left: $custom-control-gutter;
16

Mark Otto's avatar
Mark Otto committed
17
  + .custom-control {
18
    margin-left: $custom-control-spacer-x;
Mark Otto's avatar
Mark Otto committed
19
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-indicator {
28
29
30
    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
31
  }
32

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

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

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

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
111

112
113
114
115
116
// 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
117
118
.custom-controls-stacked {
  .custom-control {
119
120
    display: inline;

121
    &::after {
122
      display: block;
123
      margin-bottom: $custom-control-spacer-y;
124
125
126
      content: "";
    }

Mark Otto's avatar
Mark Otto committed
127
    + .custom-control {
128
129
130
      margin-left: 0;
    }
  }
131
132
}

Mark Otto's avatar
Mark Otto committed
133

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

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

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

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
166
167
  }
}
168

169
.custom-select-sm {
170
171
172
173
174
175
176
177
  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;
  // }
178
179
}

Mark Otto's avatar
Mark Otto committed
180

181
182
183
// File
//
// Custom file input.
184

185
.custom-file {
186
187
  position: relative;
  display: inline-block;
188
  max-width: 100%;
189
  height: $custom-file-height;
190
  cursor: pointer;
191
}
192
193

.custom-file-input {
194
  min-width: $custom-file-width;
195
  max-width: 100%;
196
  margin: 0;
XhmikosR's avatar
XhmikosR committed
197
  filter: alpha(opacity = 0);
198
  opacity: 0;
199
200

  &:focus ~ .custom-file-control {
201
    @include box-shadow($custom-file-focus-box-shadow);
202
  }
203
}
204
205

.custom-file-control {
206
207
208
209
210
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
211
212
213
214
  height: $custom-file-height;
  padding: $custom-file-padding-x $custom-file-padding-y;
  line-height: $custom-file-line-height;
  color: $custom-file-color;
215
  user-select: none;
216
217
  background-color: $custom-file-bg;
  border: $custom-file-border-width solid $custom-file-border-color;
Mark Otto's avatar
Mark Otto committed
218
  @include border-radius($custom-file-border-radius);
219
  @include box-shadow($custom-file-box-shadow);
220

221
  &::after {
222
    content: $custom-file-placeholder;
223
224
225
226
  }

  &::before {
    position: absolute;
227
228
229
    top: -$custom-file-border-width;
    right: -$custom-file-border-width;
    bottom: -$custom-file-border-width;
230
231
    z-index: 6;
    display: block;
232
233
234
235
236
237
238
239
    height: $custom-file-height;
    padding: $custom-file-padding-x $custom-file-padding-y;
    line-height: $custom-file-line-height;
    color: $custom-file-button-color;
    content: $custom-file-button-label;
    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);
240
  }
241
}