_custom-forms.scss 7.28 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
15
16
17
  position: relative;
  display: inline;
  padding-left: 1.5rem;
  color: #555;

Mark Otto's avatar
Mark Otto committed
18
19
20
21
  + .custom-control {
    margin-left: 1rem;
  }
}
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
29
30
31
32
  &:checked ~ .custom-control-indicator {
    color: #fff;
    background-color: #0074d9;
    @include box-shadow(none);
  }
33

Mark Otto's avatar
Mark Otto committed
34
35
36
  &:focus ~ .custom-control-indicator {
    // the mixin is not used here to make sure there is feedback
    box-shadow: 0 0 0 .075rem #fff, 0 0 0 .2rem #0074d9;
37
38
  }

Mark Otto's avatar
Mark Otto committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  &:active ~ .custom-control-indicator {
    color: #fff;
    background-color: #84c6ff;
    @include box-shadow(none);
  }

  &:disabled {
    ~ .custom-control-indicator {
      cursor: not-allowed;
      background-color: $custom-form-bg-color-disabled;
    }

    ~ .custom-control-description {
      color: $custom-form-description-color-disabled;
      cursor: not-allowed;
    }
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;
Mark Otto's avatar
Mark Otto committed
64
  top: .0625rem;
65
66
67
68
69
70
71
72
73
  left: 0;
  display: block;
  width: 1rem;
  height: 1rem;
  font-size: 65%;
  line-height: 1rem;
  color: #eee;
  text-align: center;
  user-select: none;
74
  background-color: $custom-form-bg-color;
75
76
77
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 50% 50%;
Mark Otto's avatar
Mark Otto committed
78
  @include box-shadow(inset 0 .25rem .25rem rgba(0,0,0,.1));
79
80
}

Mark Otto's avatar
Mark Otto committed
81
82
83
// Checkboxes
//
// Tweak just a few things for checkboxes.
84

Mark Otto's avatar
Mark Otto committed
85
86
.custom-checkbox {
  .custom-control-indicator {
87
88
    border-radius: .25rem;
  }
89

Mark Otto's avatar
Mark Otto committed
90
  .custom-control-input:checked ~ .custom-control-indicator {
91
92
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgOCA4IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA4IDgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHBhdGggZmlsbD0iI0ZGRkZGRiIgZD0iTTYuNCwxTDUuNywxLjdMMi45LDQuNUwyLjEsMy43TDEuNCwzTDAsNC40bDAuNywwLjdsMS41LDEuNWwwLjcsMC43bDAuNy0wLjdsMy41LTMuNWwwLjctMC43TDYuNCwxTDYuNCwxeiINCgkvPg0KPC9zdmc+DQo=);
  }
Mark Otto's avatar
Mark Otto committed
93

Mark Otto's avatar
Mark Otto committed
94
  .custom-control-input:indeterminate ~ .custom-control-indicator {
Mark Otto's avatar
Mark Otto committed
95
96
    background-color: #0074d9;
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iOHB4IiBoZWlnaHQ9IjhweCIgdmlld0JveD0iMCAwIDggOCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgOCA4IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGw9IiNGRkZGRkYiIGQ9Ik0wLDN2Mmg4VjNIMHoiLz4NCjwvc3ZnPg0K);
97
    @include box-shadow(none);
Mark Otto's avatar
Mark Otto committed
98
  }
99
100
}

Mark Otto's avatar
Mark Otto committed
101
102
103
// Radios
//
// Tweak just a few things for radios.
104

Mark Otto's avatar
Mark Otto committed
105
106
.custom-radio {
  .custom-control-indicator {
107
108
    border-radius: 50%;
  }
109

Mark Otto's avatar
Mark Otto committed
110
  .custom-control-input:checked ~ .custom-control-indicator {
111
112
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgOCA4IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA4IDgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHBhdGggZmlsbD0iI0ZGRkZGRiIgZD0iTTQsMUMyLjMsMSwxLDIuMywxLDRzMS4zLDMsMywzczMtMS4zLDMtM1M1LjcsMSw0LDF6Ii8+DQo8L3N2Zz4NCg==);
  }
113
114
}

Mark Otto's avatar
Mark Otto committed
115

116
117
118
119
120
// 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
121
122
.custom-controls-stacked {
  .custom-control {
123
124
    display: inline;

125
    &::after {
126
127
128
129
130
      display: block;
      margin-bottom: .25rem;
      content: "";
    }

Mark Otto's avatar
Mark Otto committed
131
    + .custom-control {
132
133
134
      margin-left: 0;
    }
  }
135
136
}

Mark Otto's avatar
Mark Otto committed
137

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

145
.custom-select {
146
  display: inline-block;
147
148
  max-width: 100%;
  padding: .375rem 1.75rem .375rem .75rem;
Mark Otto's avatar
Mark Otto committed
149
  padding-right: .75rem \9;
150
  color: $input-color;
Mark Otto's avatar
order    
Mark Otto committed
151
  vertical-align: middle;
152
  background: #fff url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAUCAMAAACzvE1FAAAADFBMVEUzMzMzMzMzMzMzMzMKAG/3AAAAA3RSTlMAf4C/aSLHAAAAPElEQVR42q3NMQ4AIAgEQTn//2cLdRKppSGzBYwzVXvznNWs8C58CiussPJj8h6NwgorrKRdTvuV9v16Afn0AYFOB7aYAAAAAElFTkSuQmCC) no-repeat right .75rem center;
Mark Otto's avatar
Mark Otto committed
153
  background-image: none \9;
154
  background-size: 8px 10px;
155
  border: $input-btn-border-width solid $input-border-color;
156
  @include border-radius($border-radius);
Mark Otto's avatar
Mark Otto committed
157
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
158
  -moz-appearance: none;
Mark Otto's avatar
Mark Otto committed
159
  -webkit-appearance: none;
160
161
162

  &:focus {
    border-color: #51a7e8;
163
    outline: none;
164
    @include box-shadow(inset 0 1px 2px rgba(0, 0, 0, 0.075), 0 0 5px rgba(81, 167, 232, 0.5));
165
166
167
168
169
  }

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
170
171
  }
}
172

173
.custom-select-sm {
174
175
176
  padding-top: 3px;
  padding-bottom: 3px;
  font-size: 12px;
177

178
179
180
  &:not([multiple]) {
    height: 26px;
    min-height: 26px;
181
  }
182
183
}

Mark Otto's avatar
Mark Otto committed
184

185
186
187
// File
//
// Custom file input.
188

189
.custom-file {
190
191
  position: relative;
  display: inline-block;
192
  max-width: 100%;
193
194
  height: 2.5rem;
  cursor: pointer;
195
}
196
197

.custom-file-input {
198
  min-width: 14rem;
199
  max-width: 100%;
200
  margin: 0;
XhmikosR's avatar
XhmikosR committed
201
  filter: alpha(opacity = 0);
202
  opacity: 0;
203
204
205
206

  &:focus ~ .custom-file-control {
    @include box-shadow(0 0 0 .075rem #fff, 0 0 0 .2rem #0074d9);
  }
207
}
208
209

.custom-file-control {
210
211
212
213
214
215
216
217
218
219
220
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
  height: 2.5rem;
  padding: .5rem 1rem;
  line-height: 1.5;
  color: #555;
  user-select: none;
  background-color: #fff;
221
  border: $input-btn-border-width solid #ddd;
222
  border-radius: .25rem;
223
  @include box-shadow(inset 0 .2rem .4rem rgba(0,0,0,.05));
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  &::after {
    content: "Choose file...";
  }

  &::before {
    position: absolute;
    top: -.075rem;
    right: -.075rem;
    bottom: -.075rem;
    z-index: 6;
    display: block;
    height: 2.5rem;
    padding: .5rem 1rem;
    line-height: 1.5;
    color: #555;
    content: "Browse";
    background-color: #eee;
    border: $input-btn-border-width solid #ddd;
    border-radius: 0 .25rem .25rem 0;
  }
245
}