_custom-forms.scss 6.05 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
  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: url(#{$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
91
92
    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
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: url(#{$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
    display: inline;

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

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

Mark Otto's avatar
Mark Otto committed
132

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
179

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

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

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

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

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

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

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