_custom-forms.scss 6.79 KB
Newer Older
jatuporn Tonggasem's avatar
jatuporn Tonggasem committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
// scss-lint:disable PropertyCount

// Embedded icons from Open Iconic.
// Released under MIT and copyright 2014 Waybury.
// https://useiconic.com/open


// Checkboxes and radios
//
// Base class takes care of all the key behavioral aspects.

.custom-control {
  position: relative;
  display: inline-block;
  padding-left: $custom-control-gutter;
  cursor: pointer;

  + .custom-control {
    margin-left: $custom-control-spacer-x;
  }
}

.custom-control-input {
  position: absolute;
  z-index: -1; // Put the input behind the label so it doesn't overlay text
  opacity: 0;

  &:checked ~ .custom-control-indicator {
    color: $custom-control-checked-indicator-color;
    background-color: $custom-control-checked-indicator-bg;
    @include box-shadow($custom-control-checked-indicator-box-shadow);
  }

  &:focus ~ .custom-control-indicator {
    // the mixin is not used here to make sure there is feedback
    box-shadow: $custom-control-focus-indicator-box-shadow;
  }

  &:active ~ .custom-control-indicator {
    color: $custom-control-active-indicator-color;
    background-color: $custom-control-active-indicator-bg;
    @include box-shadow($custom-control-active-indicator-box-shadow);
  }

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

    ~ .custom-control-description {
      color: $custom-control-disabled-description-color;
      cursor: $custom-control-disabled-cursor;
    }
  }
}

// Custom indicator
//
// Generates a shadow element to create our makeshift checkbox/radio background.

.custom-control-indicator {
  position: absolute;
  top: .25rem;
  left: 0;
  display: block;
  width: $custom-control-indicator-size;
  height: $custom-control-indicator-size;
  pointer-events: none;
  user-select: none;
  background-color: $custom-control-indicator-bg;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: $custom-control-indicator-bg-size;
  @include box-shadow($custom-control-indicator-box-shadow);
}

// Checkboxes
//
// Tweak just a few things for checkboxes.

.custom-checkbox {
  .custom-control-indicator {
    @include border-radius($custom-checkbox-radius);
  }

  .custom-control-input:checked ~ .custom-control-indicator {
    background-image: $custom-checkbox-checked-icon;
  }

  .custom-control-input:indeterminate ~ .custom-control-indicator {
    background-color: $custom-checkbox-indeterminate-bg;
    background-image: $custom-checkbox-indeterminate-icon;
    @include box-shadow($custom-checkbox-indeterminate-box-shadow);
  }
}

// Radios
//
// Tweak just a few things for radios.

.custom-radio {
  .custom-control-indicator {
    border-radius: $custom-radio-radius;
  }

  .custom-control-input:checked ~ .custom-control-indicator {
    background-image: $custom-radio-checked-icon;
  }
}


// Layout options
//
// By default radios and checkboxes are `inline-block` with no additional spacing
// set. Use these optional classes to tweak the layout.

.custom-controls-stacked {
  .custom-control {
    float: left;
    clear: left;

    + .custom-control {
      margin-left: 0;
    }
  }
}


// Select
//
// Replaces the browser default select with a custom one, mostly pulled from
// http://primercss.io.
//
// Includes IE9-specific hacks (noted by ` \9`).

.custom-select {
  display: inline-block;
  max-width: 100%;
  $select-border-width: ($border-width * 2);
  height: calc(#{$input-height} - #{$select-border-width});
  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;
  vertical-align: middle;
  background: $custom-select-bg $custom-select-indicator no-repeat right $custom-select-padding-x center;
  background-image: none \9;
  background-size: $custom-select-bg-size;
  border: $custom-select-border-width solid $custom-select-border-color;
  @include border-radius($custom-select-border-radius);
  // Use vendor prefixes as `appearance` isn't part of the CSS spec.
  -moz-appearance: none;
  -webkit-appearance: none;

  &:focus {
    border-color: $custom-select-focus-border-color;
    outline: none;
    @include box-shadow($custom-select-focus-box-shadow);

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

  &:disabled {
    color: $custom-select-disabled-color;
    cursor: $cursor-disabled;
    background-color: $custom-select-disabled-bg;
  }

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

.custom-select-sm {
  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;
  // }
}


// File
//
// Custom file input.

.custom-file {
  position: relative;
  display: inline-block;
  max-width: 100%;
  height: $custom-file-height;
  cursor: pointer;
}

.custom-file-input {
  min-width: $custom-file-width;
  max-width: 100%;
  margin: 0;
  filter: alpha(opacity = 0);
  opacity: 0;

  &:focus ~ .custom-file-control {
    @include box-shadow($custom-file-focus-box-shadow);
  }
}

.custom-file-control {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
  height: $custom-file-height;
  padding: $custom-file-padding-x $custom-file-padding-y;
  line-height: $custom-file-line-height;
  color: $custom-file-color;
  user-select: none;
  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);

  @each $lang, $text in map-get($custom-file-text, placeholder) {
    &:lang(#{$lang})::after {
      content: $text;
    }
  }

  &::before {
    position: absolute;
    top: -$custom-file-border-width;
    right: -$custom-file-border-width;
    bottom: -$custom-file-border-width;
    z-index: 6;
    display: block;
    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);
  }

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